Advertisement
AntoniiaG

BookInfo

Apr 29th, 2022 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include<string>
  4. #include<sstream>
  5. using namespace std;
  6.  
  7. //books: title, autor, next edition, ISBN number, date of publication, edition
  8.  
  9. class Date
  10. {
  11. private:
  12.     int day;
  13.     int month;
  14.     int year;
  15. public:
  16.     //These are consturctors
  17.     Date();
  18.     Date(int, int, int);
  19.     //Destructor
  20.     ~Date() {}
  21.     //void do not return values
  22.     void setDay(int);
  23.     void setMonth(int);
  24.     void setYear(int);
  25.     void showDate1();
  26.     void showDate2();
  27. };
  28. Date::Date()
  29. {
  30.     //Initialize variables.
  31.     day = 0, month = 0, year = 0;
  32. }
  33. Date::Date(int Day, int Month, int Year)
  34. {
  35.     day = Day;
  36.     month = Month;
  37.     year = Year;
  38. }
  39. void Date::setDay(int d)
  40. {
  41.     if (d < 1 && d > 31)
  42.         cout << "The day is invalid" << endl;
  43.     else
  44.         day = d;
  45. }
  46. void Date::setMonth(int m)
  47. {
  48.     if (m < 1 && m > 12)
  49.         cout << "The month is invalid" << endl;
  50.     else
  51.         month = m;
  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. void Date::showDate1()
  61. {
  62.     cout << day << " /" << month << " /" << year << endl;
  63. }
  64. void Date::showDate2()
  65. {
  66.     string monthName[] = { "January", "February", "March",
  67.         "April", "May", "June", "July",
  68.         "August", "September", "October",
  69.         "November", "December" };
  70.     cout << day << "  " << monthName[month - 1] << "  " << year << endl;
  71. }
  72.     //cout << "Entet date DD/MM/YY: ";
  73.     //int Month, Day, Year;
  74.     //cin >> Day >> Month >> Year;
  75.     //cout << endl;
  76.     //Date newDate(Day, Month, Year);
  77.     //newDate.showDate();
  78.     //cin.get();
  79.     //cout << endl;
  80.  
  81.  
  82. class Books : public Date
  83. {
  84. private:
  85.     string book_name;
  86.     string autor;
  87.     int next_edition;
  88.     int isbn_number;
  89.     int circulation;
  90.  
  91. public:
  92.     Books() {
  93.         cout << "Enter book's name: ";
  94.         cin >> book_name;
  95.         cout << endl;
  96.  
  97.         cout << "Enter autor name: ";
  98.         cin >> autor;
  99.         cout << endl;
  100.  
  101.         cout << endl;
  102.         cout << "Enter next edition: ";
  103.         cin >> next_edition;
  104.         cout << endl;
  105.  
  106.         cout << "Enter ISBN number: ";
  107.         cin >> isbn_number;
  108.         cout << endl;
  109.  
  110.         cout << "Entet date DD/MM/YY: ";
  111.         int Month, Day, Year;
  112.         cin >> Day >> Month >> Year;
  113.         cout << endl;
  114.         Date newDate(Day, Month, Year);
  115.         newDate.showDate2();
  116.         cin.get();
  117.         cout << endl;
  118.  
  119.         cout << "Enter circulation: ";
  120.         cin >> autor;
  121.         cout << endl;
  122.     }
  123.  
  124.     void setBookName(string book)
  125.     {
  126.         book_name = book;
  127.     }
  128.     string getBookName()
  129.     {
  130.         return book_name;
  131.     }
  132.  
  133.     void setAutor(string autor_name)
  134.     {
  135.         autor = autor_name;
  136.     }
  137.     string getAutor()
  138.     {
  139.         return autor;
  140.     }
  141.  
  142.     void setNextEdition(int edition)
  143.     {
  144.         next_edition = edition;
  145.     }
  146.     int getNextEdition()
  147.     {
  148.         return next_edition;
  149.     }
  150.  
  151.     void setIsbnNumber(int isbn_num)
  152.     {
  153.         isbn_number = isbn_num;
  154.     }
  155.     int getIsbnNumber()
  156.     {
  157.         return isbn_number;
  158.     }
  159.  
  160.     void setCirculation(int circul) {
  161.         circulation = circul;
  162.     }
  163.     int getCirculation()
  164.     {
  165.         return circulation;
  166.     }
  167. };
  168.  
  169. /*
  170. class Books :public Date
  171. {
  172. private:
  173.     string book_name;
  174.     string autor;
  175.     int next_edition;
  176.     int isbn_number;
  177.     int circulation;
  178.  
  179. public:
  180.     Books();
  181.     Books(string, string, int, int, int);
  182.     ~Books() { }
  183.     void setBookName(string);
  184.     void setAutorName(string);
  185.     void setNextEdition(int);
  186.     void setIsbnNumber(int);
  187.     void setBookCirculation(int);
  188. };
  189. Books::Books() {
  190.     book_name = "";
  191.     autor = "";
  192.     next_edition = 0;
  193.     isbn_number = 0;
  194.     circulation = 0;
  195. }
  196. Books::Books(string bookName, string autorName, int nextEditon, int isbnNumber, int bookCirculation)
  197. {
  198.     book_name = bookName;
  199.     autor = autorName;
  200.     next_edition = nextEditon;
  201.     isbn_number = isbnNumber;
  202.     circulation = bookCirculation;
  203. }
  204. void Books::setBookName(string bookName) {
  205.     cout << "Enter book's name: " << endl;
  206.     cin >> bookName;
  207.     cout << endl;
  208. }
  209. void Books::setAutorName(string autor)
  210. {
  211.     cout << "Enter autor name: " << endl;
  212.     cin >> autor;
  213.     cout << endl;
  214. }
  215.  
  216. void Books::setNextEdition(int edition)
  217. {
  218.     cout << "Enter next edition: " << endl;
  219.     cin >> edition;
  220.     cout << endl;
  221. }
  222.  
  223. void Books::setIsbnNumber(int isbn_num)
  224. {
  225.     cout << "Enter ISBN number: " << endl;
  226.     cin >> isbn_num;
  227.     cout << endl;
  228. }
  229.  
  230. void Books::setBookCirculation(int circ)
  231. {
  232.     cout << "Enter circulation: " << endl;
  233.     cin >> circ;
  234.     cout << endl;
  235. }
  236. */
  237.  
  238.  
  239. class Bookseller : public Books
  240. {
  241. private:
  242.     string name_bookseller;
  243.     string address_bookseller;
  244.     int phone_bookseller;
  245.  
  246. public:
  247.     void setBooksellerName(string name) {
  248.         name_bookseller = name;
  249.     }
  250.     string getBooksellerName() {
  251.         return name_bookseller;
  252.     }
  253.  
  254.     void setBooksellerAddress(string address) {
  255.         address_bookseller = address;
  256.     }
  257.     string getBooksellerAddress() {
  258.         return address_bookseller;
  259.     }
  260.  
  261.     void setBooksellerPhone(int phoneNumber) {
  262.         phone_bookseller = phoneNumber;
  263.     }
  264.     int getBooksellerPhone() {
  265.         return phone_bookseller;
  266.     }
  267. };
  268. /*
  269. class Bookseller :public Books
  270. {
  271. private:
  272.     string name_bookseller;
  273.     string address_bookseller;
  274.     int phone_bookseller;
  275.  
  276. public:
  277.  
  278.     Bookseller();
  279.     Bookseller(string name, string address, int phone);
  280.     ~Bookseller () { }
  281.     void setBookseller(string);
  282.     void setAddress(string);
  283.     void setPhone(int);
  284. };
  285.  
  286. Bookseller::Bookseller() {
  287.     name_bookseller = "";
  288.     address_bookseller= "";
  289.     phone_bookseller = 0;
  290. }
  291. Bookseller::Bookseller(string name, string address, int phone)
  292. {
  293.     name_bookseller = name;
  294.     address_bookseller = address;
  295.     phone_bookseller = phone;
  296. }
  297. void Bookseller::setBookseller(string name)
  298. {
  299.     cout << "Enter bookseller name: " << endl;
  300.     cin >> name;
  301.     cout << endl;
  302. }
  303. void Bookseller::setAddress(string address)
  304. {
  305.     cout << "Enter address: " << endl;
  306.     cin >> address;
  307.     cout << endl;
  308. }
  309. void Bookseller::setPhone(int phone)
  310. {
  311.     cout << "Enter next edition: " << endl;
  312.     cin >> phone;
  313.     cout << endl;
  314. }
  315. */
  316.  
  317. int main()
  318. {
  319.     string end;
  320.     Books b;
  321.     Bookseller bs;
  322.     ofstream BookInfo;
  323.     // Write to the file
  324.     BookInfo.open("BookInfo.txt");
  325.     if (end == "end") {
  326.         return 0;
  327.     }
  328.     else {
  329.         b.setBookName("" "");
  330.         b.setAutorName("" "");
  331.         b.setNextEdition(0);
  332.         b.setIsbnNumber(0);
  333.         /*
  334.             cout << "Entet date DD/MM/YY: ";
  335.             int Month, Day, Year;
  336.             cin >> Day >> Month >> Year;
  337.             cout << endl;
  338.             Date newDate(Day, Month, Year);
  339.             newDate.showDate2();
  340.             cin.get();
  341.             cout << endl;
  342.         */
  343.         b.setCirculation(0);
  344.         bs.setBooksellerName("");
  345.         bs.setBooksellerAddress("");
  346.         bs.setBooksellerPhone(0);
  347.  
  348.         string agree;
  349.         cin >> agree;
  350.         if (agree == "yes") {
  351.             cout << "This book has certificate";
  352.  
  353.             cout << "Entet date DD/MM/YY: ";
  354.             int Month, Day, Year;
  355.             cin >> Day >> Month >> Year;
  356.             cout << endl;
  357.             Date newDate(Day, Month, Year);
  358.             newDate.showDate2();
  359.             cin.get();
  360.             cout << endl;
  361.         }
  362.         else
  363.         {
  364.             cout << "This book hasn't certificate";
  365.         }
  366.     }
  367.     // Close the file
  368.     BookInfo.close();
  369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement