Thread: Help with program

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    2

    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

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Use code tags to post code not big bold letters as even though they are GREAT they don't help with readablity.
    Woop?

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    63
    Use Inheritance

    I've probably got the syntax wrong here, but declare the dog class something like:

    Class dog : public pets

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Thats a start, but you'll need more. Namely, virtual functions.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM