Question
Delete vectors, replace with arrays // Animal.h #ifndef ANIMAL_H #define ANIMAL_H class Animal { public: Animal(); Animal(string name,double weight,string color,int noOfLegs); // Function declarations string
Delete vectors, replace with arrays
// Animal.h
#ifndef ANIMAL_H #define ANIMAL_H
class Animal { public: Animal(); Animal(string name,double weight,string color,int noOfLegs);
// Function declarations string getName(); void setName(string name); double getWeight(); void setWeight(double weight); string getColor(); void setColor(string color); int getNoOfLegs(); void setNoOfLegs(int noOfLegs);
private: // Declaring variables string name; double weight; string color; int noOfLegs;
}; #endif
_______________________
// Animal.cpp
#include using namespace std; #include "Animal.h"
Animal::Animal() { } Animal::Animal(string name,double weight,string color,int noOfLegs) { this->name=name; this->weight=weight; this->color=color; this->noOfLegs=noOfLegs; } string Animal::getName() { return name; } void Animal::setName(string name) { this->name = name; } double Animal::getWeight() { return weight; } void Animal::setWeight(double weight) { this->weight = weight; } string Animal::getColor() { return color; } void Animal::setColor(string color) { this->color = color; } int Animal::getNoOfLegs() { return noOfLegs; } void Animal::setNoOfLegs(int noOfLegs) { this->noOfLegs = noOfLegs; }
______________________
// main.cpp
#include #include using namespace std; #include "Animal.h"
int main() { int choice; string name; double weight; string color; int noOfLegs; // Declaring vector vector vec(0); while(true) { cout<<" ::Menu::"< cout<<"1.Add a New Animal"< cout<<"2.View All Animals entered"< cout<<"3.Exit"< cout<<"Enter Choice :"; cin>>choice;
switch(choice) { case 1:{ cout<<"Enter Animal Name :"; cin>>name; cout<<"Enter Weight :"; cin>>weight; cout<<"Enter Color :"; cin>>color; cout<<"Enter no of legs :"; cin>>noOfLegs; Animal a(name,weight,color,noOfLegs); vec.push_back(a); continue; } case 2:{ for(int i=0;i { cout<<"Animal#"< cout<<"Name :"< cout<<"Weight :"< cout<<"Color :"< cout<<"No of Legs :"< cout<<"-----------------------"< } continue; } case 3:{ break; continue; } default:{ cout<<"** Invalid Choice **"< break; } } break; }
return 0; }
-----------------------------------------
instructions:
- C++
- Separate the programs into three files (header class, source class, main class)
- We will create a class of Animal.
First design the class diagram for an Animal
Create a class named Animal
Create a Main Menu:
Add a New Animal
View All Animals entered
Exit
Tips
An Animal should have at least four member variables (examples: name, weight, color, amount of legs, etc.)
All class functions should be well defined in the scope of this lab.
Evaluation:
- Ask the user of your application for all the animal details.
- Print in the console all the information previously entered by the user.
- Create a class called animal.
- Incorporate the class to main menu with the use of global variables.
- Organized code with comments.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started