Hi, I need help on my assignment ASAP it is due today. Thanks In C++ create an A
ID: 3834635 • Letter: H
Question
Hi, I need help on my assignment ASAP it is due today. Thanks
In C++ create an ADT class name Dog having the following members:
char gender;
int age;
string name;
Dog();
Dog(string n, int a, char g);
dispDog();
Create Collie class from Dog having the following members:
string look; // possible values: full coat; short coat
int size; // Possible values: 50 to 70 pounds
int LifeSpan; //Possible values: 10 to 14 years
Collie();
Collie(string n, int a, char g, string l, int s, int ls):Dog(n,a,g);
disp()
//In main() create a Collie dog (object) named myCollie.
Instantiate myCollie object as
Name - Max
Age - 3
Gender - Male (M)
Look - Short Coat
Size - 55 lbs
Life Span - 13
Explanation / Answer
Its quite simple. I have developed the program using C++ by creating an Collie() method and by creating an object for dog method.
You can achieve this using the Inheritance concept. I have attached the program along with the comments for each part of the code.
Program:-
// The header file comprises of in-built functions and classes
#include <iostream>
using namespace std;
// Created a class named "Dog"
class Dog {
public:
char gender;
int age;
string name;
void setDogData(string n,char g);
dispDog();
};
// Created a class named "Collie"
class Collie {
public:
string look;
char gender;
int size;
int LifeSpan;
void Collie(string n, int a, char g, string l,
int s, int ls) : Dog(n,a,g);
disp()
};
// Created a base class myCollie
class myCollie: public Dog, public Collie {
public:
int getData() {
return (Name ,Age ,Gender,Look ,Size , LifeSpan);
}
};
// This is main pont of the C++ Program
int main(void) {
myCollie myCollie;
int collieAvg;
myCollie.n();
myCollie.g();
collieAvg = myCollie.getData();
cout << "The myCollie object consist of : " << myCollie.getData() << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.