Skillrack CSE1002 Inlab 7
Total time : 20 mins
Challenges : 1
Question (Price of books and CD/DVD)
Solution
#include<iostream>
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();
};
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(){} void learning_Material :: print() { cout<<isbn<<"\n"<<title<<"\n"<<price; } class book : public learning_Material { public : int pages; void get() { cin>>isbn>>title>>author>>year>>pages; } void calc_Price() { price=pages; } }; class CD : public learning_Material { public : int time; void get() { cin>>isbn>>title>>author>>year>>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();
}
}
{
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();
}
}
0 comments:
Post a Comment