Skillrack IL 7

Solutions for Skillrack CSE1002 Inlab 7

Total time : 20 mins

Challenges : 1

Question (Price of books and CD/DVD)

Solution

#include
using namespace std;
class learning_Material
{
protected :
char isbn[15];
char title[20];
char author[20];
int year;
float price;
public :
void get();
void print();
};

void learning_Material :: get()
{
    cin>>isbn>>title>>author>>year;
}
void learning_Material :: print()
{
	cout<<isbn<<"\n"<<title<<"\n"<<price;
} 
class book : public learning_Material 
{ 
	public : 
		int pages; 
		void get() 
		{ 
                        learning_Material :: get();
			cin>>pages;
		}
		void calc_Price()
		{
			price=pages;
		}
};
class CD : public learning_Material
{
	public :
		int time;
		void get()
		{
                        learning_Material :: get();
			cin>>time;
		}
		void calc_Price()
		{
			price=2*time;
		}
};

int main()
{
int ch;
cin>>ch;
if(ch==0)
{
book a;
a.get();
a.calc_Price();
a.print();
}
else
{
CD e;
e.get();
e.calc_Price();
e.print();
}
}

Note

Solution has not been tested

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s