Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Category { // која ја претставува категоријата во која спаѓа веста
- private:
- // наслов од максимум 30 знаци (char title[30])
- char name[20]; //Класата Category треба да содржи име од максимум 20 знаци (char name[20])
- public:
- Category () {
- strcpy(this->name, "unnamed"); // со предодредена вредност unnamed.
- }
- void print() { //За категоријата се печати само името: Category: [name].
- cout<<"Category: "<<name;
- } // За сите класи треба да напишете соодветен метод за печатење print().
- Category(char * name){
- strcpy(this->name, name);
- }
- };
- class NewsArticle { // Класата NewsArticle треба да содржи:
- private:
- Category c; // објект од класата Category
- char title[30];
- public:
- NewsArticle(Category c) { // За класата NewsArticle напишете предодреден конструктор
- strcpy(this->title, "untitled"); // со предодредена вредност untitled
- }
- NewsArticle(){}
- NewsArticle(Category c, char * title) { // и конструктор со параметри.
- this->c=c;
- strcpy(this->title, title);
- }
- NewsArticle(const NewsArticle &n) {
- this->c=n.c;
- strcpy(this->title, n.title);
- }
- void print() { // За веста се печати насловот, па категоријата во нов ред:
- cout<<"Article title: "<<title<<endl; //Title: [title]
- c.print(); //category.print()
- }
- };
- class FrontPage {// напишете класа FrontPage која ќе содржи:
- private:
- NewsArticle n; //објект од класата NewsArticle која ја претставува насловната вест на страницата
- float price; // цена (float price) со предодредена вредност 0
- int editionNumber; // број на издание на списанието (int editionNumber) со предодредена вредност 0
- public:
- FrontPage(NewsArticle n) {
- this->n=n;
- this->price=0;
- this->editionNumber=0;
- }
- FrontPage(){} // За класата FrontPage напишете предодреден (default) конструктор
- FrontPage(NewsArticle n, float price, int editionNumber) { // и конструктор со параметри.
- this->n=n;
- this->price=price;
- this->editionNumber=editionNumber;
- }
- FrontPage(NewsArticle n, float price) {
- this->n=n;
- this->price=price;
- this->editionNumber=0;
- }
- void print() { // За насловната страница се печати цената и изданието во прв ред, па веста во втор:
- cout<<"Price: "<<price<<" "<<"Edition number: "<<editionNumber<<endl;
- n.print(); //Price: [price], Edition number: [editionNumber]
- //article.print()
- }
- }; //Внимајте на редоследот на параметрите во конструкторите.
- // Не го менувајте main методот.
- 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 if (testCase == 3) {
- cin >> categoryName;
- cin >> articleTitle;
- cin >> price;
- Category category(categoryName);
- NewsArticle article(category, articleTitle);
- FrontPage frontPage(article, price);
- frontPage.print();
- }
- else {
- FrontPage frontPage = FrontPage();
- frontPage.print();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement