Advertisement
AntoniiaG

BI2

May 1st, 2022 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include<string>
  4. #include<sstream>
  5. using namespace std;
  6.  
  7. class Date
  8. {
  9. private:
  10.     int day;
  11.     int month;
  12.     int year;
  13. public:
  14.     //These are consturctors
  15.     Date();
  16.     Date(int, int, int);
  17.     //Destructor
  18.     ~Date() {}
  19.     //void do not return values
  20.     void setDay(int);
  21.     void setMonth(int);
  22.     void setYear(int);
  23.     void showDate1();
  24.     void showDate2();
  25. };
  26. Date::Date()
  27. {
  28.     //Initialize variables.
  29.     day = 0, month = 0, year = 0;
  30. }
  31. Date::Date(int Day, int Month, int Year)
  32. {
  33.     day = Day;
  34.     month = Month;
  35.     year = Year;
  36. }
  37. void Date::setDay(int d)
  38. {
  39.     if (d < 1 && d > 31)
  40.         cout << "The day is invalid" << endl;
  41.     else
  42.         day = d;
  43. }
  44.  
  45. void Date::setMonth(int m)
  46. {
  47.     if (m < 1 && m > 12)
  48.         cout << "The month is invalid" << endl;
  49.     else
  50.         month = m;
  51. }
  52.  
  53. void Date::setYear(int y)
  54. {
  55.     if (y < 1950 && y > 2022)
  56.         cout << "The year is invalid" << endl;
  57.     else
  58.         year = y;
  59. }
  60.  
  61. void Date::showDate1()
  62. {
  63.     cout << day << " /" << month << " /" << year << endl;
  64. }
  65. void Date::showDate2()
  66. {
  67.     string monthName[] = { "January", "February", "March",
  68.         "April", "May", "June", "July",
  69.         "August", "September", "October",
  70.         "November", "December" };
  71.     cout << day << "  " << monthName[month - 1] << "  " << year << endl;
  72. }
  73.  
  74. class Books :public Date
  75. {
  76. private:
  77.     string book_name;
  78.     string autor;
  79.     int next_edition;
  80.     int isbn_number;
  81.     int circulation;
  82.  
  83. public:
  84.     Books();
  85.     Books(string, string, int, int, int);
  86.     ~Books() { }
  87.     void setBook(string);
  88.     string getBook();
  89.     void setAutor(string);
  90.     string getAutor();
  91.     void setNextEdition(int);
  92.     int getNextEdition();
  93.     void setIsbnNumber(int);
  94.     int getIsbnNumber();
  95.     void setCirculation(int);
  96.     int getCirculation();
  97. };
  98. Books::Books() {
  99.     book_name = "", autor = "";
  100.     next_edition = 0, isbn_number = 0, circulation = 0;
  101. }
  102. Books::Books(string bookName, string autorName, int nextEditon, int isbnNumber, int bookCirculation)
  103. {
  104.     book_name = bookName;
  105.     autor = autorName;
  106.     next_edition = nextEditon;
  107.     isbn_number = isbnNumber;
  108.     circulation = bookCirculation;
  109. }
  110. void Books::setBook(string bookName) {
  111.     cout << "Enter book's name: " << endl;
  112.     getline(cin, bookName);
  113.     cout << endl;
  114. }
  115. string Books :: getBook()
  116. {
  117.     return book_name;
  118. }
  119.  
  120. void Books::setAutor(string autor)
  121. {
  122.     cout << "Enter autor name: " << endl;
  123.     getline(cin, autor);
  124.     cout << endl;
  125. }
  126. string Books::getAutor()
  127. {
  128.     return autor;
  129. }
  130.  
  131. void Books::setNextEdition(int edition)
  132. {
  133.     cout << "Enter next edition: " << endl;
  134.     cin >> edition;
  135.     cout << endl;
  136. }
  137. int Books :: getNextEdition()
  138. {
  139.     return next_edition;
  140. }
  141.  
  142. void Books::setIsbnNumber(int isbn_num)
  143. {
  144.     cout << "Enter ISBN number: " << endl;
  145.     cin >> isbn_num;
  146.     cout << endl;
  147. }
  148. int Books :: getIsbnNumber()
  149. {
  150.     return isbn_number;
  151. }
  152. void Books::setCirculation(int circ)
  153. {
  154.     cout << "Enter circulation: " << endl;
  155.     cin >> circ;
  156.     cout << endl;
  157. }
  158. int Books :: getCirculation()
  159. {
  160.     return circulation;
  161. }
  162.  
  163. class Bookseller:public Books
  164. {
  165. private:
  166.     string name_bookseller;
  167.     string address_bookseller;
  168.     int phone_bookseller;
  169.  
  170. public:
  171.  
  172.     Bookseller();
  173.     Bookseller(string name, string address, int phone);
  174.     ~Bookseller () { }
  175.     void setBookseller(string);
  176.     string getBookseller();
  177.     void setAddress(string);
  178.     string getAddress();
  179.     void setPhone(int);
  180.     int getPhone();
  181. };
  182.  
  183. Bookseller::Bookseller() {
  184.     name_bookseller = "";
  185.     address_bookseller= "";
  186.     phone_bookseller = 0;
  187. }
  188. Bookseller::Bookseller(string name, string address, int phone)
  189. {
  190.     name_bookseller = name;
  191.     address_bookseller = address;
  192.     phone_bookseller = phone;
  193. }
  194. void Bookseller::setBookseller(string name)
  195. {
  196.     cout << "Enter bookseller name: " << endl;
  197.     cin >> name;
  198.     getline(cin, name);
  199.     cout << endl;
  200. }
  201. string Bookseller :: getBookseller() {
  202.     return name_bookseller;
  203. }
  204.  
  205. void Bookseller::setAddress(string address)
  206. {
  207.     cout << "Enter address: " << endl;
  208.     getline(cin, address);
  209.     cout << endl;
  210. }
  211. string Bookseller :: getAddress() {
  212.     return address_bookseller;
  213. }
  214. void Bookseller::setPhone(int phone)
  215. {
  216.     cout << "Enter phone: " << endl;
  217.     cin >> phone;
  218.     cout << endl;
  219. }
  220. int Bookseller :: getPhone() {
  221.     return phone_bookseller;
  222. }
  223.  
  224. int main()
  225. {
  226.     string end;
  227.     Date d;
  228.     Books b;
  229.     Bookseller bs;
  230.     ofstream BookInfo;
  231.    
  232.     // Write to the file
  233.     BookInfo.open("BookInfo.txt");
  234.    
  235.     while(end != "end")
  236.      {
  237.         b.setBook("");
  238.         b.setAutor("");
  239.         b.setNextEdition(0);
  240.         b.setIsbnNumber(0);
  241.         cout << "Entet date DD/MM/YY: ";
  242.         int Month, Day, Year;
  243.         cin >> Day >> Month >> Year;
  244.         cout << endl;
  245.         Date newDate(Day, Month, Year);
  246.         newDate.showDate2();
  247.         cin.get();
  248.         cout << endl;
  249.         b.setCirculation(0);
  250.         cout << "\n";
  251.         bs.setBookseller("");
  252.         bs.setAddress("");
  253.         bs.setPhone(0);
  254.  
  255.         string agree;
  256.         cin >> agree;
  257.         if (agree == "yes") {
  258.             cout << "This book has certificate";
  259.  
  260.             cout << "Entet date DD/MM/YY: ";
  261.             int Month, Day, Year;
  262.             cin >> Day >> Month >> Year;
  263.             cout << endl;
  264.             Date newDate(Day, Month, Year);
  265.             newDate.showDate2();
  266.             cin.get();
  267.             cout << endl;
  268.         }
  269.         else
  270.         {
  271.             cout << "This book hasn't certificate";
  272.         }
  273.  
  274.         BookInfo << b.getBook();
  275.         BookInfo << b.getAutor();
  276.         BookInfo << b.getNextEdition();
  277.         BookInfo << b.getIsbnNumber();
  278.         BookInfo << b.getCirculation();
  279.         BookInfo << bs.getBookseller();
  280.         BookInfo << bs.getAddress();
  281.         BookInfo << bs.getPhone();
  282.  
  283.     }
  284.     // Close the file
  285.     BookInfo.close();
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement