Thread: Help!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

Popular pages Recent additions subscribe to a feed