Advertisement
Guest User

Untitled

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