Could you please do that asap De u gloBal variables. Problem 3 You are to create
ID: 3724629 • Letter: C
Question
Could you please do that asap
De u gloBal variables. Problem 3 You are to create a class called Cow. You should create the definition of the class Cow in a file cowh and the functions for Cow in cow.cpp. You will also create a main program to be housed in cowmain.cpp A Cow will have attributes of .Breed . Weight . Name .Gender Spayed or neutered (yes/no) Registration ID (alphanumeric like HZ123x) Color description (this could be more than a single word) Other comments (also more than a single word) . A Cow will have the following methods .Accessors for all attributes . Mutators for all attributes A default constructor that sets all data elements to 0 or blank text as appropriate . A fully specified constructor that allows defining values for all attributes . A printinfo method that will display all the info for a cow in a logical and well formatted way including labels for each of the attribute fields cowmain.cpp should perform the following actions * Dynamically allocate an array of 6 Cows * Prompt the user for information about each of the six cows and store that information in one of the array elements .Print the information for each Cow Clean up all allocated spaceExplanation / Answer
Cow.h
#ifndef COW_H
#define COW_H
class Cow
{
public:
Cow();
Cow(string breed, double weight, string name, char gender,
string spayedOrNeutered, string registrationID, string color,
string comments);
string getBreed();
void setBreed(string breed);
double getWeight();
void setWeight(double weight);
string getName();
void setName(string name);
char getGender();
void setGender(char gender);
string getSpayedOrNeutered();
void setSpayedOrNeutered(string spayedOrNeutered);
string getRegistrationID();
void setRegistrationID(string registrationID);
string getColor();
void setColor(string color);
string getComments();
void setComments(string comments);
void printInfo();
private:
// Declaring variables
string breed;
double weight;
string name;
char gender;
string spayedOrNeutered;
string registrationID;
string color;
string comments;
};
#endif
_________________
Cow.cpp
#include <iostream>
using namespace std;
#include "Cow.h"
Cow::Cow()
{
}
Cow::Cow(string breed, double weight, string name, char gender,
string spayedOrNeutered, string registrationID, string color,
string comments) {
this->breed = breed;
this->weight = weight;
this->name = name;
this->gender = gender;
this->spayedOrNeutered = spayedOrNeutered;
this->registrationID = registrationID;
this->color = color;
this->comments = comments;
}
string Cow::getBreed() {
return breed;
}
void Cow::setBreed(string breed) {
this->breed = breed;
}
double Cow::getWeight() {
return weight;
}
void Cow::setWeight(double weight) {
this->weight = weight;
}
string Cow::getName() {
return name;
}
void Cow::setName(string name) {
this->name = name;
}
char Cow::getGender() {
return gender;
}
void Cow::setGender(char gender) {
this->gender = gender;
}
string Cow::getSpayedOrNeutered() {
return spayedOrNeutered;
}
void Cow::setSpayedOrNeutered(string spayedOrNeutered) {
this->spayedOrNeutered = spayedOrNeutered;
}
string Cow::getRegistrationID() {
return registrationID;
}
void Cow::setRegistrationID(string registrationID) {
this->registrationID = registrationID;
}
string Cow::getColor() {
return color;
}
void Cow::setColor(string color) {
this->color = color;
}
string Cow::getComments() {
return comments;
}
void Cow::setComments(string comments) {
this->comments = comments;
}
void Cow::printInfo()
{
cout<<"Breed=" << breed <<endl;
cout<<"Weight="<< weight<<endl;
cout<<"Name="<<name<<endl;
cout<<"Gender="<< gender <<endl;
cout<<"Spayed Or Neutered="<<spayedOrNeutered<<endl;
cout<<"Registration ID="<< registrationID<<endl;
cout<<"Color="<<color <<endl;
cout<<"Comments=" << comments <<endl;
}
___________________
main.cpp
#include <iostream>
using namespace std;
#include "Cow.h"
int main()
{
int size=6;
string breed;
double weight;
string name;
char gender;
char sOrN;
string spayedOrNeutered;
string registrationID;
string color;
string comments;
// Creating array dynamically
Cow* cows = new Cow[size];
for(int i=0;i<size;i++)
{
cout<<"Cow#"<<i+1<<":"<<endl;
cout<<"Enter Breed :";
cin>>breed;
cout<<"Enter Weight :";
cin>>weight;
cout<<"Enter Male or Female (m/f) ?";
cin>>gender;
cout<<"Enter Spayed Or Neutered :(t/f)";
cin>>sOrN;
if(sOrN=='t' ||sOrN=='T')
spayedOrNeutered="true";
else
spayedOrNeutered="false";
cout<<"Enter Registration Id:";
cin>>registrationID;
cin.ignore();
cout<<"Enter Color :";
getline(cin,color);
cout<<"Enter Comments :";
getline(cin,comments);
Cow c(string breed, double weight, string name, char gender,
string spayedOrNeutered, string registrationID, string color,
string comments)
cows[i]=c;
}
for(int i=0;i<size;i++)
{
cout<<"Cow#"<<i+1<<" info :"<<endl;
cows[i].printInfo();
}
// Deallocation of memory
delete[] cows;
return 0;
}
___________________
I will post the output..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.