Sei sulla pagina 1di 6

STRATHMORE UNIVERSITY

BACHELOR OF INFORMATICS

ADVANCED C++


PROJECT 3- PUBLICATION


DELIVERED TO: VINCENT OMWENGA




























// pubb.cpp : Defines the entry point for the console application.

include<iostream>
#include<string>
using namespace std;
//creation of class publication which stores the title and price of the
publication
class publication{
// declaration of class members and functions
private:
string title;
float price;
public:
publication(){}
void getTitle();
string putTitle();
void getPrice();
float putPrice();
};
void publication::getTitle(){
cout<<"enter the title of the publication: ";
cin>>title;
}
string publication::putTitle(){
return title;
}
void publication::getPrice(){
cout<<"enter price of the publication: ";
cin>>price;
}
float publication::putPrice(){
return price;
}
// class sales which returns the sales of the publication for the last three
months
class sales{
public:
//array to store the sales for the last three months
float record[1][3];
float sales1;
float sales2;
float sales3;
public:
sales(){}
void getSales();
float putSales();
};
//function to get the sales from the user
void sales::getSales(){
int i;
for(i=1;i<2;i++){
cout<<"Enter the sales of the publication for last month
but 2: "<<endl;
cin>>sales1;
cout<<"Enter the sales of the publication for lastmonth but
1: "<<endl;
cin>>sales2;
cout<<"Enter the sales of the publication for last month:
"<<endl;
cin>>sales3;
}
record[i][0]=sales1;
record[i][1]=sales2;
record[i][2]=sales3;
}
//function to return the sales
float sales::putSales(){
/*cout<<"sales1\tsales2\tsales3\n";
cout<<"------\t------\t------\n";
cout<<sales1<<"\t"<<sales2<<"\t"<<sales3<<endl;*/
return record[1][3];
}
//class book which inherits from sales and publication and adds page
count of the publication
class book:public publication,public sales{
private:
int page;
public:
book(){}
void getPages();
int putPages();
};
//function to get the number of pages
void book::getPages(){
cout<<"Enter the number of pages in the book: "<<endl;
cin>>page;
}
//function to return the number of pages
int book::putPages(){
//cout<<"The book has "<<page<<" pages.";
return page;
}
//class tape which inherits from sales and publication and adds playing
time of the publication
class tape:public publication,public sales{
private:
float ptime;
public:
//class tape constructor
tape(){}
void getPtime();
float putPtime();
};
//function to get the paying time of the tape
void tape::getPtime(){
cout<<"Enter the playing time of the tape: "<<endl;
cin>>ptime;
}
//function to return the paying time of the tape
float tape::putPtime(){

return ptime;
}

int main(){
// creation of objects of type book and tape
book a;
tape b;
cout<<"Welcome to publication storage."<<endl;
cout<<"please enter the publication type you would like to store details
about.";
cout<<" enter '1' for a book or '2' for a tape."<<endl;
int n;
cin>>n;
if(n==1){
a.getTitle();
a.getPrice();
a.getSales();
a.getPages();
cout<<" The following are the entered details for the book: "<<endl;
cout<<"Title: "<<a.putTitle()<<endl;
cout<<"Price: "<<a.putPrice()<<endl;
cout<<"sales for the last 3 months:"<<endl;
cout<<"sales1\tsales2\tsales3\n";
cout<<"------\t------\t------\n";
cout<<a.sales1<<"\t"<<a.sales2<<"\t"<<a.sales3<<endl;
cout<<"Pages: "<<a.putPages()<<endl;
}
else if(n==2){
b.getTitle();
b.getPrice();
b.getSales();
b.getPtime();
cout<<" The following are the entered details for the tape: "<<endl;
cout<<"Title: "<<b.putTitle()<<endl;
cout<<"Price: "<<b.putPrice()<<endl;
cout<<"sales for the last 3 months:"<<endl;
cout<<"sales1\tsales2\tsales3\n";
cout<<"------\t------\t------\n";
cout<<b.sales1<<"\t"<<b.sales2<<"\t"<<b.sales3<<endl;
cout<<"Playing time: "<<b.putPtime()<<endl;
}
else{
cout<<"invalid response."<<endl;
}
cout<<"Thankyou."<<endl;
system("pause");
return 0;
}









Class diagrams









1. Output when user enters 1






2. Output when user enters 2

Potrebbero piacerti anche