Advertisement
AntoniiaG

BI2

May 1st, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.44 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. void Date::setMonth(int m)
  45. {
  46.     if (m < 1 && m > 12)
  47.         cout << "The month is invalid" << endl;
  48.     else
  49.         month = m;
  50. }
  51. void Date::setYear(int y)
  52. {
  53.     if (y < 1950 && y > 2022)
  54.         cout << "The year is invalid" << endl;
  55.     else
  56.         year = y;
  57. }
  58. void Date::showDate1()
  59. {
  60.     cout << day << " /" << month << " /" << year << endl;
  61. }
  62. void Date::showDate2()
  63. {
  64.     string monthName[] = { "January", "February", "March",
  65.         "April", "May", "June", "July",
  66.         "August", "September", "October",
  67.         "November", "December" };
  68.     cout << day << "  " << monthName[month - 1] << "  " << year << endl;
  69. }
  70.  
  71. class Books :public Date
  72. {
  73. private:
  74.     string book_name;
  75.     string autor;
  76.     int next_edition;
  77.     int isbn_number;
  78.     int circulation;
  79.  
  80. public:
  81.     Books();
  82.     Books(string, string, int, int, int);
  83.     ~Books() { }
  84.     void setBookName(string);
  85.     void setAutorName(string);
  86.     void setNextEdition(int);
  87.     void setIsbnNumber(int);
  88.     void setBookCirculation(int);
  89. };
  90. Books::Books() {
  91.     book_name = "", autor = "";
  92.     next_edition = 0, isbn_number = 0, circulation = 0;
  93. }
  94. Books::Books(string bookName, string autorName, int nextEditon, int isbnNumber, int bookCirculation)
  95. {
  96.     book_name = bookName;
  97.     autor = autorName;
  98.     next_edition = nextEditon;
  99.     isbn_number = isbnNumber;
  100.     circulation = bookCirculation;
  101. }
  102. void Books::setBookName(string bookName) {
  103.     cout << "Enter book's name: " << endl;
  104.     getline(cin, bookName);
  105.     cout << endl;
  106. }
  107. void Books::setAutorName(string autor)
  108. {
  109.     cout << "Enter autor name: " << endl;
  110.     getline(cin, autor);
  111.     cout << endl;
  112. }
  113.  
  114. void Books::setNextEdition(int edition)
  115. {
  116.     cout << "Enter next edition: " << endl;
  117.     cin >> edition;
  118.     cout << endl;
  119. }
  120.  
  121. void Books::setIsbnNumber(int isbn_num)
  122. {
  123.     cout << "Enter ISBN number: " << endl;
  124.     cin >> isbn_num;
  125.     cout << endl;
  126. }
  127.  
  128. void Books::setBookCirculation(int circ)
  129. {
  130.     cout << "Enter circulation: " << endl;
  131.     cin >> circ;
  132.     cout << endl;
  133. }
  134.  
  135.  
  136. class Bookseller:public Books
  137. {
  138. private:
  139.     string name_bookseller;
  140.     string address_bookseller;
  141.     int phone_bookseller;
  142.  
  143. public:
  144.  
  145.     Bookseller();
  146.     Bookseller(string name, string address, int phone);
  147.     ~Bookseller () { }
  148.     void setBookseller(string);
  149.     void setAddress(string);
  150.     void setPhone(int);
  151. };
  152.  
  153. Bookseller::Bookseller() {
  154.     name_bookseller = "";
  155.     address_bookseller= "";
  156.     phone_bookseller = 0;
  157. }
  158. Bookseller::Bookseller(string name, string address, int phone)
  159. {
  160.     name_bookseller = name;
  161.     address_bookseller = address;
  162.     phone_bookseller = phone;
  163. }
  164. void Bookseller::setBookseller(string name)
  165. {
  166.     cout << "Enter bookseller name: " << endl;
  167.     getline(cin, name);
  168.     cout << endl;
  169. }
  170. void Bookseller::setAddress(string address)
  171. {
  172.     cout << "Enter address: " << endl;
  173.     getline(cin, address);
  174.     cout << endl;
  175. }
  176. void Bookseller::setPhone(int phone)
  177. {
  178.     cout << "Enter next edition: " << endl;
  179.     cin >> phone;
  180.     cout << endl;
  181. }
  182.  
  183. int main()
  184. {
  185.     string end;
  186.     Books b;
  187.     Bookseller bs;
  188.     ofstream BookInfo;
  189.     // Write to the file
  190.     BookInfo.open("BookInfo.txt");
  191.     while(end != "end")
  192.      {
  193.         b.setBookName("" "");
  194.         b.setAutorName("" "");
  195.         b.setNextEdition(0);
  196.         b.setIsbnNumber(0);
  197.         cout << "Entet date DD/MM/YY: ";
  198.         int Month, Day, Year;
  199.         cin >> Day >> Month >> Year;
  200.         cout << endl;
  201.         Date newDate(Day, Month, Year);
  202.         newDate.showDate2();
  203.         cin.get();
  204.         cout << endl;
  205.         b.setBookCirculation(0);
  206.         bs.setBookseller("");
  207.         bs.setAddress("");
  208.         bs.setPhone(0);
  209.  
  210.         string agree;
  211.         cin >> agree;
  212.         if (agree == "yes") {
  213.             cout << "This book has certificate";
  214.  
  215.             cout << "Entet date DD/MM/YY: ";
  216.             int Month, Day, Year;
  217.             cin >> Day >> Month >> Year;
  218.             cout << endl;
  219.             Date newDate(Day, Month, Year);
  220.             newDate.showDate2();
  221.             cin.get();
  222.             cout << endl;
  223.         }
  224.         else
  225.         {
  226.             cout << "This book hasn't certificate";
  227.         }
  228.     }
  229.     // Close the file
  230.     BookInfo.close();
  231. }
  232.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement