Advertisement
AntoniiaG

Untitled

May 23rd, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.66 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 authorFirstName;
  79.     string authorLastName;
  80.     int next_edition;
  81.     int isbn_number;
  82.     int circulation;
  83.  
  84. public:
  85.     Books();
  86.     Books(string bookName, string FName, string LName, int nextEditon, int isbnNumber, int bookCirculation);
  87.     ~Books() { }
  88.     void setBook(string);
  89.     string getBook();
  90.     void setFirstName(string);
  91.     void setLastName(string);
  92.     string getAuthorName();
  93.     void setNextEdition(int);
  94.     int getNextEdition();
  95.     void setIsbnNumber(int);
  96.     int getIsbnNumber();
  97.     void setCirculation(int);
  98.     int getCirculation();
  99.     friend ostream& operator <<(ostream& os, const Books& com) {
  100.         os << "Name: " << com.book_name;
  101.         return os;
  102.     }
  103. };
  104. Books::Books() {
  105.     book_name = """""", authorFirstName = "", authorLastName = "";
  106.     next_edition = 0, isbn_number = 0, circulation = 0;
  107. }
  108. Books ::Books(string bookName, string FirstName, string LastName, int nextEditon, int isbnNumber, int bookCirculation)
  109. {
  110.     book_name = bookName;
  111.     authorFirstName = FirstName;
  112.     authorLastName = LastName;
  113.     next_edition = nextEditon;
  114.     isbn_number = isbnNumber;
  115.     circulation = bookCirculation;
  116. }
  117. void Books::setBook(string bookName)
  118. {
  119.     book_name = bookName;
  120.    
  121.     cout << endl;
  122. }
  123. string Books :: getBook()
  124. {
  125.     return book_name;
  126. }
  127.  
  128. void Books::setFirstName(string FirstName)
  129. {
  130.     authorFirstName = FirstName;
  131.     cout << endl;
  132. }
  133. void Books :: setLastName(string LastName) {
  134.     authorLastName = LastName;
  135. }
  136. string Books::getAuthorName()
  137. {
  138.     return authorFirstName + " " + authorLastName;
  139. }
  140.  
  141. void Books::setNextEdition(int nextEdition)
  142. {
  143.     next_edition = nextEdition;
  144.     cout << endl;
  145. }
  146. int Books :: getNextEdition()
  147. {
  148.     return next_edition;
  149. }
  150.  
  151. void Books::setIsbnNumber(int isbnNumber)
  152. {
  153.     isbn_number = isbnNumber;
  154.     cout << endl;
  155. }
  156. int Books :: getIsbnNumber()
  157. {
  158.     return isbn_number;
  159. }
  160. void Books::setCirculation(int bookCirculation)
  161. {
  162.     circulation = bookCirculation;
  163.     cout << endl;
  164. }
  165. int Books :: getCirculation()
  166. {
  167.     return circulation;
  168. }
  169.  
  170. class Bookseller:public Books
  171. {
  172. private:
  173.     string name_bookseller;
  174.     string address_bookseller;
  175.     int phone_bookseller;
  176.  
  177. public:
  178.  
  179.     Bookseller();
  180.     Bookseller(string nameBS, string address, int phone);
  181.     ~Bookseller () { }
  182.     void setBookseller(string);
  183.     string getBookseller();
  184.     void setAddress(string);
  185.     string getAddress();
  186.     void setPhone(int);
  187.     int getPhone();
  188. };
  189.  
  190. Bookseller::Bookseller() {
  191.     name_bookseller = "";
  192.     address_bookseller= "";
  193.     phone_bookseller = 0;
  194. }
  195. Bookseller::Bookseller(string nameBS, string address, int phone)
  196. {
  197.     name_bookseller = nameBS;
  198.     address_bookseller = address;
  199.     phone_bookseller = phone;
  200. }
  201.  
  202. void Bookseller::setBookseller(string nameBS)
  203. {
  204.     name_bookseller = nameBS;
  205.     cout << endl;
  206. }
  207. string Bookseller :: getBookseller() {
  208.     return name_bookseller;
  209. }
  210.  
  211. void Bookseller::setAddress(string address)
  212. {
  213.     address_bookseller = address;
  214.     cout << endl;
  215. }
  216. string Bookseller :: getAddress() {
  217.     return address_bookseller;
  218. }
  219. void Bookseller::setPhone(int phone)
  220. {
  221.     phone_bookseller = phone;
  222.     cout << endl;
  223. }
  224. int Bookseller :: getPhone() {
  225.     return phone_bookseller;
  226. }
  227.  
  228.  
  229. class Certificate : public Date
  230. {
  231.  
  232. private:
  233.     string agree;
  234.  
  235. public:
  236.     Certificate()
  237.     {
  238.         agree = " ";
  239.     }
  240.     Certificate(string agreeBook) {
  241.         agree = agreeBook;
  242.     }
  243.  
  244.     ~Certificate() { }
  245.     void setAgree(string agreeBook)
  246.     {
  247.         agree = agreeBook;
  248.         cout << endl;
  249.     }
  250.     string getAgree() {
  251.         return agree;
  252.     }
  253.  
  254. };
  255. int main()
  256. {
  257.     string agreeBook, bookName, FirstName, LastName, nameBS, address;
  258.     int nextEdition = 0, isbnNumber = 0, bookCirculation = 0, phone = 0;
  259.     Books b;
  260.     Date d;
  261.     Bookseller bs;
  262.     Certificate c;
  263.  
  264.     fstream BookInfo;
  265.     // Write to the file
  266.     BookInfo.open("BookInfo2.txt", ios::out);
  267.    
  268.     int choice = 0;
  269.     string monthName[] = { "January", "February", "March",
  270.             "April", "May", "June", "July",
  271.             "August", "September", "October",
  272.             "November", "December" };
  273.  
  274.     do
  275.     {
  276.         //1. Книги
  277.         //2. Издателство
  278.         //3. Купи книга
  279.         cout << "Menu" << endl;
  280.         cout << "-----------------------------------" << endl;
  281.         cout << "Enter a number from 1 to 3 to choose your command:\n 1 - Books\n 2 - Bookseller\n 3 - Buy a book\n 0 - Exit\n";
  282.        
  283.         cin >> choice;
  284.         if (choice < 0 && choice > 3) {
  285.             cout << "Incorect number, please try again" << endl;
  286.             cin >> choice;
  287.         }
  288.         cout << "\n";
  289.    
  290.  
  291.         switch (choice)
  292.         {
  293.         case 0:
  294.             cout << "Exiting... Have a nice day!";
  295.             break;
  296.  
  297.         case 1:
  298.             cout << "\n";
  299.             cout << "Enter Books Information:" << endl;
  300.             cout << "-----------------------------------" << endl;
  301.             cout << "";
  302.  
  303.             cout << "Enter book's name: \n" << endl;
  304.             cin >> bookName;
  305.             b.setBook(bookName);
  306.             cout << b;
  307.             cout << "\n";
  308.             BookInfo << "Book" << endl << "Name:" << bookName << endl;
  309.  
  310.             cout << "Enter author name: " << endl;
  311.             cin >> FirstName;
  312.             cin >> LastName;
  313.             b.setFirstName(FirstName);
  314.             b.setLastName(LastName);
  315.             cout << b;
  316.             cout << "\n";
  317.             BookInfo <<"Autor: " << FirstName << " " << LastName << endl;
  318.  
  319.             cout << "Enter next edition: " << endl;
  320.             cin >> nextEdition;
  321.             b.setNextEdition(nextEdition);
  322.             cout << b;
  323.             cout << "\n";
  324.             BookInfo << "Next Edition: " << nextEdition << endl;
  325.  
  326.  
  327.             cout << "Enter ISBN number: " << endl;
  328.             cin >> isbnNumber;
  329.             b.setIsbnNumber(isbnNumber);
  330.             cout << b;
  331.             cout << "\n";
  332.             BookInfo << "ISBN number: " << isbnNumber << endl;
  333.  
  334.             cout << "Entet print date DD/MM/YY: ";
  335.             int day, month, year;
  336.             cin >> day >> month >> year;
  337.             cout << endl;
  338.             cout << day << "  " << monthName[month - 1] << "  " << year << endl;
  339.             cin.get();
  340.             cout << endl;
  341.             cout << "\n";
  342.             BookInfo << "Date: " << day << "  " << monthName[month - 1] << "  " << year << endl;
  343.  
  344.             cout << "Enter circulation: " << endl;
  345.             cin >> bookCirculation;
  346.             b.setCirculation(bookCirculation);
  347.             cout << b;
  348.             cout << "\n";
  349.             BookInfo << "Circulation: " << bookCirculation << endl;
  350.  
  351.             cout << "Enter yes if this book is agree for certificate." << endl;
  352.             cout << "\n";
  353.             cin >> agreeBook;
  354.             c.setAgree(agreeBook);
  355.             if (agreeBook._Equal("yes")) {
  356.                 BookInfo << "Certificate: " << agreeBook << endl;
  357.                 BookInfo << "This book has certificate from MON!" << endl;
  358.                 cout << "\n";
  359.             }
  360.             else {
  361.                 BookInfo << "Certificate: " << agreeBook << endl;
  362.                 BookInfo << "This book has not certificate from MON!" << endl;
  363.                 cout << "\n";
  364.             }
  365.             break;
  366.  
  367.         case 2:
  368.             cout << "Enter Bookseller Information:" << endl;
  369.             cout << "-----------------------------------" << endl;
  370.             cout << "Enter bookseller name: " << endl;
  371.             getline(cin, nameBS);
  372.             getline(cin, nameBS);
  373.             cout << "\n";
  374.             bs.setBookseller("" "");
  375.             cout << bs;
  376.             cout << "\n";
  377.             BookInfo << "Bookseller"<< endl << "Bookseller: " << nameBS << endl;
  378.  
  379.             cout << "Enter address: " << endl;
  380.             getline(cin, address);
  381.             //getline(cin, nameBS);
  382.             bs.setAddress("" "" "");
  383.             cout << bs;
  384.             cout << "\n";
  385.             BookInfo << "Bookseller address: " << address << endl;
  386.  
  387.             cout << "Enter phone: " << endl;
  388.             cin >> phone;
  389.             bs.setPhone(phone);
  390.             cout << bs;
  391.             cout << "\n";
  392.             BookInfo << "Bookseller phone: " << phone << endl;
  393.             break;
  394.  
  395.         case 3:
  396.             cout << "Buy a book:" << endl;
  397.             cout << "-----------------------------------" << endl;
  398.             break;
  399.         default:
  400.             cout << "Invalid choice!";
  401.             cout << "\n";
  402.             break;
  403.         }
  404.     } while (choice != 0);
  405.  
  406.     // Close the file
  407.     BookInfo.close();
  408. }
  409.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement