-
Help with program
i need some help with the following program.. i think i have the basics but do not understand the more "complicated things"
#include <iostream>
#include <string>
using namespace std;
class pets
{
protected:
string type;
double price;
public:
void get_type(void);
void show_type(void);
void get_price(void);
void show_price(void);
};
void pets::get_type(void)
{
cout <<"Enter the type of pet. "; cin >> type;
}
void pets::show_type(void)
{
cout <<"The type of pet is "<< type << endl;
}
void pets::get_price(void)
{
cout <<"Enter the price of your pet. ";cin >>price;
}
void pets::show_price(void)
{
cout << "The price of your pet is " << price<<endl;
}
void main(void)
{
pets my_pet;
my_pet.get_type();
my_pet.show_type();
my_pet.get_price();
my_pet.show_price();
}
now i think that is right... i now need a class called dog and a class called cat... and need them to do the PARENT class's functions... though im not sure how to go about that... if anyone can provide some help that would be appreciated
-
a) Use code tags. (See sticky at top of forum).
b) 'void main' bad. 'int main' good.
c) There are tutorials on this website (and don't forget Google) that will teach you about inherited classes. Books are good too. Look for: inheritance, virtual functions.
Give it a shot. If you have problems, show us what you are trying.
Cheers
-
Use code tags to post code not big bold letters as even though they are GREAT they don't help with readablity.
-
Use Inheritance :)
I've probably got the syntax wrong here, but declare the dog class something like:
Class dog : public pets
-
Thats a start, but you'll need more. Namely, virtual functions.