Advertisement
AntoniiaG

Untitled

May 1st, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 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_name;
  76.     int next_edition;
  77.     int isbn_number;
  78.     int circulation;
  79.  
  80. public:
  81.     Books() {
  82.         cout << "Enter book's name: " << endl;
  83.         cin >> book_name;
  84.         cout<< endl;
  85.        
  86.         cout << "Enter autor name: " << endl;
  87.         cin >> autor_name;
  88.         cout << endl;
  89.  
  90.         cout << "Enter next edition: " << endl;
  91.         cin >> next_edition;
  92.         cout << endl;
  93.  
  94.        
  95.  
  96.         cout << "Entet date DD/MM/YY: " << endl;
  97.         int Month, Day, Year;
  98.         cin >> Day >> Month >> Year;
  99.         cout << endl;
  100.         Date newDate(Day, Month, Year);
  101.         newDate.showDate2();
  102.         cin.get();
  103.         cout << endl;
  104.  
  105.         cout << "Enter circulation: " << endl;
  106.         cin >> circulation;
  107.         cout << endl;
  108.     }
  109.  
  110.     void setBookName(string book)
  111.     {
  112.         book_name = book;
  113.     }
  114.     string getBookName()
  115.     {
  116.         return book_name;
  117.     }
  118.  
  119.     void setAutorName(string autor)
  120.     {
  121.         autor_name = autor;
  122.     }
  123.     string getAutor()
  124.     {
  125.         return autor_name;
  126.     }
  127.  
  128.     void setNextEdition(int edition)
  129.     {
  130.         next_edition = edition;
  131.     }
  132.     int getNextEdition()
  133.     {
  134.         return next_edition;
  135.     }
  136.  
  137.     void setIsbnNumber(int isbn_num)
  138.     {
  139.         isbn_number = isbn_num;
  140.     }
  141.     int getIsbnNumber()
  142.     {
  143.         return isbn_number;
  144.     }
  145.  
  146.     void setCirculation(int circul) {
  147.         circulation = circul;
  148.     }
  149.     int getCirculation()
  150.     {
  151.         return circulation;
  152.     }
  153. };
  154.  
  155. class Bookseller:public Books
  156. {
  157. private:
  158.     string name_bookseller;
  159.     string address_bookseller;
  160.     int phone_bookseller;
  161.  
  162. public:
  163.     Bookseller()
  164.     {
  165.         cout << "Enter bookseller name: ";
  166.         cin >> name_bookseller;
  167.         cout << endl;
  168.  
  169.         cout << "Enter bookseller address: ";
  170.         cin >> address_bookseller;
  171.         cout << endl;
  172.    
  173.         cout << "Enter bookseller phone: ";
  174.         cin >> phone_bookseller;
  175.         cout << endl;
  176.     }
  177.     void setBooksellerName(string name) {
  178.         name_bookseller = name;
  179.     }
  180.     string getBooksellerName() {
  181.         return name_bookseller;
  182.     }
  183.  
  184.     void setBooksellerAddress(string address) {
  185.         address_bookseller = address;
  186.     }
  187.     string getBooksellerAddress() {
  188.         return address_bookseller;
  189.     }
  190.  
  191.     void setBooksellerPhone(int phoneNumber) {
  192.         phone_bookseller = phoneNumber;
  193.     }
  194.     int getBooksellerPhone() {
  195.         return phone_bookseller;
  196.     }
  197. };
  198.  
  199. int main()
  200. {
  201.     string end;
  202.     Books b;
  203.     Bookseller bs;
  204.     ofstream BookInfo;
  205.     // Write to the file
  206.     BookInfo.open("BookInfo.txt");
  207.     while (end != "end")
  208.     {
  209.         b.setBookName("" "");
  210.         b.setAutorName("" "");
  211.         b.setNextEdition(0);
  212.         b.setIsbnNumber(0);
  213.         b.setCirculation(0);
  214.         bs.setBooksellerName("");
  215.         bs.setBooksellerAddress("");
  216.         bs.setBooksellerPhone(0);
  217.  
  218.         string agree;
  219.         cin >> agree;
  220.         if (agree == "yes") {
  221.             cout << "This book has certificate";
  222.  
  223.             cout << "Entet date DD/MM/YY: ";
  224.             int Month, Day, Year;
  225.             cin >> Day >> Month >> Year;
  226.             cout << endl;
  227.             Date newDate(Day, Month, Year);
  228.             newDate.showDate2();
  229.             cin.get();
  230.             cout << endl;
  231.         }
  232.         else
  233.         {
  234.             cout << "This book hasn't certificate";
  235.         }
  236.     }
  237.        
  238.     // Close the file
  239.     BookInfo.close();
  240. }
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement