Advertisement
lastephanieee

Lab work

Mar 27th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. class Article{
  8. private:
  9.     char title[100];
  10.     char author[50];
  11.     char *content;
  12.     bool publish;
  13. public:
  14.     Article(char *title="", char *author="", char *content="", bool publish=0){
  15.     strcpy(this->title, title);
  16.     strcpy(this->author, author);
  17.     this->content=new char[strlen(content)+1];
  18.     strcpy(this->content, content);
  19.     this->publish=publish;
  20.     }
  21.     void show(){
  22.         cout<<title<<endl;
  23.         cout<<author<<endl;
  24.         cout<<content<endl;
  25.     }
  26.     ~Article(){
  27.         delete [] content;
  28.     }
  29. };
  30.  
  31. class Newspaper{
  32. private:
  33.     char name[100];
  34.     Article **p;
  35.     int articles;
  36.     Article first;
  37. public:
  38.     Newspaper(char *name="", Article **p=Article(), int articles=0, Article first=Article()){
  39.         strcpy(this->name, name);
  40.     }
  41.    
  42. };
  43.  
  44. int main() {
  45.     char title[100], author[50], content[100];
  46.     int n;
  47.     cin >> n;
  48.     char name[100];
  49.     cin.getline(name, 100);
  50.     cin.getline(name, 100);
  51.  
  52.     Article first("VAZNO","OOP","Vezba:OOP",true);
  53.     Newspaper v(name,first);
  54.     Article **s = new Article*[n];
  55.     for(int i = 0; i < n; ++i) {
  56.         cin.getline(title, 100);
  57.         cin.getline(author, 50);
  58.         cin.getline(content, 100);
  59.         v.addArticle(Article(title, author, content, true)); //se koristi copy konstruktor
  60.     }
  61.     v.showFirst();
  62.     v.showLongest();
  63.     cout << v.totalofauthor(author) << endl;
  64.     for(int i = 0; i < n; ++i) {
  65.         delete s[i];
  66.     }
  67.     delete [] s;
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement