Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

=+Are they specific or general in nature?

Answered: 1 week ago

Question

=+ What is the nature of the contracts or agreements with unions?

Answered: 1 week ago

Question

=+What is the procedure for labor relations in the workplace?

Answered: 1 week ago