Advertisement
LegoDrifter

Naslovna stranica

Apr 6th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Category{
  6. private:
  7.     char categoryName[20];
  8. public:
  9.     Category(){
  10.     strcpy(this->categoryName,"unnamed");
  11.     }
  12.     Category(const char*name){
  13.     strcpy(this->categoryName,name);
  14.  
  15.     }
  16.     void print(){
  17.     cout<<"Category :"<<this->categoryName<<endl;
  18.     }
  19.     ~Category(){}
  20. };
  21. class NewsArticle {
  22. private:
  23.     Category object;
  24.     char articleTitle[30];
  25.  
  26. public:
  27.     NewsArticle(){
  28.     strcpy(this->articleTitle,"untitled");
  29.     }
  30.     NewsArticle(Category x){
  31.     this->object=x;
  32.     strcpy(this->articleTitle,"untitled");
  33.     }
  34.     NewsArticle(Category x,const char*title){
  35.     this->object=x;
  36.     strcpy(this->articleTitle,title);
  37.  
  38.  
  39.     }
  40.     void print(){
  41.     cout<<"Article title: "<<this->articleTitle<<endl;
  42.     object.print();
  43.     }
  44.     ~NewsArticle(){}
  45.  
  46. };
  47. class FrontPage {
  48. private:
  49.     NewsArticle Article;
  50.     float price;
  51.     int edition;
  52. public:
  53.     FrontPage(){
  54.     this->price=0.0;
  55.     this->edition=0;
  56.     }
  57.     FrontPage(NewsArticle p,float x){
  58.     this->Article=p;
  59.     this->price=x;
  60.     this->edition=0;
  61.     }
  62.     FrontPage(NewsArticle p,float x,int id){
  63.     this->Article=p;
  64.     this->price=x;
  65.     this->edition=id;
  66.  
  67.     }
  68.     void print(){
  69.     cout<<"Price: "<<this->price<<", Edition number: "<<this->edition<<endl;
  70.     Article.print();
  71.     }
  72.  
  73.  
  74. };
  75.  
  76.  
  77.  
  78.  
  79. int main() {
  80.     char categoryName[20];
  81.     char articleTitle[30];
  82.     float price;
  83.     int editionNumber;
  84.  
  85.     int testCase;
  86.     cin >> testCase;
  87.  
  88.  
  89.     if (testCase == 1) {
  90.         int iter;
  91.         cin >> iter;
  92.         while (iter > 0) {
  93.             cin >> categoryName;
  94.             cin >> articleTitle;
  95.             cin >> price;
  96.             cin >> editionNumber;
  97.             Category category(categoryName);
  98.             NewsArticle article(category, articleTitle);
  99.             FrontPage frontPage(article, price, editionNumber);
  100.             frontPage.print();
  101.             iter--;
  102.         }
  103.     }
  104.     else if (testCase == 2) {
  105.         cin >> categoryName;
  106.         cin >> price;
  107.         cin >> editionNumber;
  108.         Category category(categoryName);
  109.         NewsArticle article(category);
  110.         FrontPage frontPage(article, price, editionNumber);
  111.         frontPage.print();
  112.     }// test case 3
  113.     else if (testCase == 3) {
  114.         cin >> categoryName;
  115.         cin >> articleTitle;
  116.         cin >> price;
  117.         Category category(categoryName);
  118.         NewsArticle article(category, articleTitle);
  119.         FrontPage frontPage(article, price);
  120.         frontPage.print();
  121.     }
  122.     else {
  123.         FrontPage frontPage = FrontPage();
  124.         frontPage.print();
  125.     }
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement