Thread: Help!!

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    230

    Help!!

    I have made this code and it works fine. but i want to use an array to store multiple inputs and i havent gotten that to work. I would appreciate it if somone could help me with the array part.

    Code:
    #include <iostream>
    #include <conio.h>
    #include <string>
    using namespace std;
    
    
    ///////////////////////////////////////////////////////////////////////
    class Publication
    {
    	private:
    	float price;
    	string title;
    	
    	public:
    	
    	Publication () : price(0)
    	{}
    	
        void getdata()
    	{
    		cout << "Enter title "; 
            cin>>title;
    		cout << "Enter price "; 
            cin>>price;
    	}
    	
    	void putdata()
    	{
    		cout <<"price: "<<price<<endl;
    		cout <<"title: "<<title<<endl;
    	}
    };
    //////////////////////////////////////////////////////////////////////
    class Book : public Publication
    {
    	private:
    	int pagecount;
    	int bkcount;
    	public:
    	Book () : pagecount (0) {}
     
    	void getdata()
    	{
    	Publication::getdata();
    	cout <<"Enter page amount in book"<<endl; cin>>pagecount;
    	}
    	void putdata()
    	{
    	Publication::putdata();
    	cout <<"Page amount: "<<pagecount<<endl;
    	}
    };
    /////////////////////////////////////////////////////////////////////////
    class Tape : public Publication
    {
    	private:
    	float minutes;
    	
        public:
    	Tape() : minutes(0){}
    	
    	void getdata()
    	{
    	Publication::getdata();
    	cout <<"Enter playing time of tape"<<endl; cin>>minutes;
    	}
    	void putdata()
    	{
    	Publication::putdata();
    	cout <<"Playing time:  "<<minutes<<endl;
    	}
    	
    };
    /////////////////////////////////////////////////////////////////////////////
    
    int main()
    
    {
    	Book bk;
    	Tape tp;
    	int ch;
    	char again;
    	
    	do	{
    		cout<< " 1) Enter Book info "<<endl;
    		cout<< " 2) Enter Tape info "<<endl;
    		 cin>>ch;
    		 	
    		 switch (ch)
    		 	{
    		 	case 1:
    		 	bk.getdata();
    		 	cout<<"Enter again (y/n)"<<endl; 
    		 	cin>>again;
    		 	break;
    		 	case 2:
    		 	tp.getdata();
    		                cout<<"Enter again (y/n)"<<endl;
                                                    cin>>again;
    		 	break;
    		 	default: cout<< "Invalid input"<<endl; cout<<"Try again (y/n)"<<endl;
                                                    cin>>again;
                                                    break;	
                                    }	 
    	 	              }	
    	while(again != 'n');
    	bk.putdata();
    	tp.putdata();
    	
                    getch();
    	return 0;
    }
    Last edited by gamer4life687; 09-28-2002 at 04:36 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Be more specific and post your question. Where exactly do you need help with respect to class member variables? Post the exactly variable.

    If you want to post a lot of code, include a lot of comments.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    my fault on the comments


    the code runs fine but only excepts one input from user for both book and tape

    i need help on how to create an array of max 100 to hold input for books and tape from the user

    hope this clears up my question

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    i wanted to try that but i didnt know how


    thxxxxxx alot ill try it in a few

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    IT WORKED THX now i just do the same for tape thanks a lot!!!!

Popular pages Recent additions subscribe to a feed