Thread: How to use Member function INPUT

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Question How to use Member function INPUT

    I have a question on how can I use the member function INPUT to ask the user to input all the elements of the array and then to display all of the elements using DISPLAY?




    #include <iostream>



    class CAT

    {

    public:

    CAT() { itsAge = 1; itsWeight=5; } // default constructor

    ~CAT() {} // destructor

    int GetAge() const { return itsAge; }

    int GetWeight() const { return itsWeight; }

    void SetAge(int age) { itsAge = age; }



    private:

    int itsAge;

    int itsWeight;

    };



    int main()

    {

    CAT Litter[5];

    int i;

    for (i = 0; i < 5; i++)

    Litter[i].SetAge(2*i +1);



    for (i = 0; i < 5; i++)

    std::cout << "Cat #" << i+1<< ": "

    << Litter[i].GetAge() << std::endl;

    return 0;

    }

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    #include <iostream>



    class CAT

    {

    public:

    CAT() { itsAge = 1; itsWeight=5; } // default constructor

    ~CAT() {} // destructor

    int GetAge() const { return itsAge; }

    int GetWeight() const { return itsWeight; }

    void SetAge(int age) { itsAge = age; }

    void INPUT();

    void DISPLAY();



    private:

    int itsAge;

    int itsWeight;

    };

    void CAT::INPUT()
    {
    cout << "enter age" << endl;
    cin >> itsAge;
    cout << "enter weight" << endl;
    cin >> itsWeight;
    }

    void CAT:ISPLAY()
    {
    cout << itsAge << ' ' << itsWeight << endl;
    }

    int main()

    {

    CAT Litter[5];

    int i;

    for (i = 0; i < 5; i++)

    Litter[i].SetAge(2*i +1);



    for (i = 0; i < 5; i++)

    std::cout << "Cat #" << i+1<< ": "

    << Litter[i].GetAge() << std::endl;

    for(i = 0; i < 5; i++)
    {
    Litter[i].INPUT();
    Litter[i].DISPLAY();
    }

    return 0;

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM