Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Category {
- private:
- char name[20]="unnamed";
- public:
- Category(){}
- Category(char ime[]){
- strcpy(name,ime);
- }
- void print(){
- cout<<"Category:"<<" "<<name<<endl;
- }
- };
- class NewsArticle{
- private:
- Category obj;
- char title[30]="untitled";
- public:
- NewsArticle(){}
- NewsArticle(Category ob,char naslov[])
- {
- obj=ob;
- strcpy(title,naslov);
- }
- NewsArticle(Category ob){
- obj=ob;
- }
- void print(){
- cout<<"Article title:"<<" "<<title<<endl;
- obj.print();
- }
- };
- class FrontPage{
- private:
- NewsArticle obj;
- float price=0;
- int editionNumber=0;
- public:
- FrontPage(){}
- FrontPage(NewsArticle ob,float cena,int br){
- obj=ob;
- price=cena;
- editionNumber=br;
- }
- FrontPage(NewsArticle ob,float cena){
- obj=ob;
- price=cena;
- }
- void print(){
- cout<<"Price:"<<" "<<price<<","<<" "<<"Edition number:"<<" "<<editionNumber<<endl;;
- obj.print();
- }
- };
- int main() {
- char categoryName[20];
- char articleTitle[30];
- float price;
- int editionNumber;
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- int iter;
- cin >> iter;
- while (iter > 0) {
- cin >> categoryName;
- cin >> articleTitle;
- cin >> price;
- cin >> editionNumber;
- Category category(categoryName);
- NewsArticle article(category, articleTitle);
- FrontPage frontPage(article, price, editionNumber);
- frontPage.print();
- iter--;
- }
- }
- else if (testCase == 2) {
- cin >> categoryName;
- cin >> price;
- cin >> editionNumber;
- Category category(categoryName);
- NewsArticle article(category);
- FrontPage frontPage(article, price, editionNumber);
- frontPage.print();
- }// test case 3
- else {
- cin >> categoryName;
- cin >> articleTitle;
- cin >> price;
- Category category(categoryName);
- NewsArticle article(category, articleTitle);
- FrontPage frontPage(article, price);
- frontPage.print();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement