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 categoryName[20];
- public:
- Category(){
- strcpy(this->categoryName,"unnamed");
- }
- Category(const char*name){
- strcpy(this->categoryName,name);
- }
- void print(){
- cout<<"Category :"<<this->categoryName<<endl;
- }
- ~Category(){}
- };
- class NewsArticle {
- private:
- Category object;
- char articleTitle[30];
- public:
- NewsArticle(){
- strcpy(this->articleTitle,"untitled");
- }
- NewsArticle(Category x){
- this->object=x;
- strcpy(this->articleTitle,"untitled");
- }
- NewsArticle(Category x,const char*title){
- this->object=x;
- strcpy(this->articleTitle,title);
- }
- void print(){
- cout<<"Article title: "<<this->articleTitle<<endl;
- object.print();
- }
- ~NewsArticle(){}
- };
- class FrontPage {
- private:
- NewsArticle Article;
- float price;
- int edition;
- public:
- FrontPage(){
- this->price=0.0;
- this->edition=0;
- }
- FrontPage(NewsArticle p,float x){
- this->Article=p;
- this->price=x;
- this->edition=0;
- }
- FrontPage(NewsArticle p,float x,int id){
- this->Article=p;
- this->price=x;
- this->edition=id;
- }
- void print(){
- cout<<"Price: "<<this->price<<", Edition number: "<<this->edition<<endl;
- Article.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 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