Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include<string>
- #include<sstream>
- using namespace std;
- class Date
- {
- private:
- int day;
- int month;
- int year;
- public:
- //These are consturctors
- Date();
- Date(int, int, int);
- //Destructor
- ~Date() {}
- //void do not return values
- void setDay(int);
- void setMonth(int);
- void setYear(int);
- void showDate1();
- void showDate2();
- };
- Date::Date()
- {
- //Initialize variables.
- day = 0, month = 0, year = 0;
- }
- Date::Date(int Day, int Month, int Year)
- {
- day = Day;
- month = Month;
- year = Year;
- }
- void Date::setDay(int d)
- {
- if (d < 1 && d > 31)
- cout << "The day is invalid" << endl;
- else
- day = d;
- }
- void Date::setMonth(int m)
- {
- if (m < 1 && m > 12)
- cout << "The month is invalid" << endl;
- else
- month = m;
- }
- void Date::setYear(int y)
- {
- if (y < 1950 && y > 2022)
- cout << "The year is invalid" << endl;
- else
- year = y;
- }
- void Date::showDate1()
- {
- cout << day << " /" << month << " /" << year << endl;
- }
- void Date::showDate2()
- {
- string monthName[] = { "January", "February", "March",
- "April", "May", "June", "July",
- "August", "September", "October",
- "November", "December" };
- cout << day << " " << monthName[month - 1] << " " << year << endl;
- }
- class Books :public Date
- {
- private:
- string book_name;
- string authorFirstName;
- string authorLastName;
- int next_edition;
- int isbn_number;
- int circulation;
- public:
- Books();
- Books(string bookName, string FName, string LName, int nextEditon, int isbnNumber, int bookCirculation);
- ~Books() { }
- void setBook(string);
- string getBook();
- void setFirstName(string);
- void setLastName(string);
- string getAuthorName();
- void setNextEdition(int);
- int getNextEdition();
- void setIsbnNumber(int);
- int getIsbnNumber();
- void setCirculation(int);
- int getCirculation();
- friend ostream& operator <<(ostream& os, const Books& com) {
- os << "Name: " << com.book_name;
- return os;
- }
- };
- Books::Books() {
- book_name = """""", authorFirstName = "", authorLastName = "";
- next_edition = 0, isbn_number = 0, circulation = 0;
- }
- Books ::Books(string bookName, string FirstName, string LastName, int nextEditon, int isbnNumber, int bookCirculation)
- {
- book_name = bookName;
- authorFirstName = FirstName;
- authorLastName = LastName;
- next_edition = nextEditon;
- isbn_number = isbnNumber;
- circulation = bookCirculation;
- }
- void Books::setBook(string bookName)
- {
- book_name = bookName;
- cout << endl;
- }
- string Books :: getBook()
- {
- return book_name;
- }
- void Books::setFirstName(string FirstName)
- {
- authorFirstName = FirstName;
- cout << endl;
- }
- void Books :: setLastName(string LastName) {
- authorLastName = LastName;
- }
- string Books::getAuthorName()
- {
- return authorFirstName + " " + authorLastName;
- }
- void Books::setNextEdition(int nextEdition)
- {
- next_edition = nextEdition;
- cout << endl;
- }
- int Books :: getNextEdition()
- {
- return next_edition;
- }
- void Books::setIsbnNumber(int isbnNumber)
- {
- isbn_number = isbnNumber;
- cout << endl;
- }
- int Books :: getIsbnNumber()
- {
- return isbn_number;
- }
- void Books::setCirculation(int bookCirculation)
- {
- circulation = bookCirculation;
- cout << endl;
- }
- int Books :: getCirculation()
- {
- return circulation;
- }
- class Bookseller:public Books
- {
- private:
- string name_bookseller;
- string address_bookseller;
- int phone_bookseller;
- public:
- Bookseller();
- Bookseller(string nameBS, string address, int phone);
- ~Bookseller () { }
- void setBookseller(string);
- string getBookseller();
- void setAddress(string);
- string getAddress();
- void setPhone(int);
- int getPhone();
- };
- Bookseller::Bookseller() {
- name_bookseller = "";
- address_bookseller= "";
- phone_bookseller = 0;
- }
- Bookseller::Bookseller(string nameBS, string address, int phone)
- {
- name_bookseller = nameBS;
- address_bookseller = address;
- phone_bookseller = phone;
- }
- void Bookseller::setBookseller(string nameBS)
- {
- name_bookseller = nameBS;
- cout << endl;
- }
- string Bookseller :: getBookseller() {
- return name_bookseller;
- }
- void Bookseller::setAddress(string address)
- {
- address_bookseller = address;
- cout << endl;
- }
- string Bookseller :: getAddress() {
- return address_bookseller;
- }
- void Bookseller::setPhone(int phone)
- {
- phone_bookseller = phone;
- cout << endl;
- }
- int Bookseller :: getPhone() {
- return phone_bookseller;
- }
- class Certificate : public Date
- {
- private:
- string agree;
- public:
- Certificate()
- {
- agree = " ";
- }
- Certificate(string agreeBook) {
- agree = agreeBook;
- }
- ~Certificate() { }
- void setAgree(string agreeBook)
- {
- agree = agreeBook;
- cout << endl;
- }
- string getAgree() {
- return agree;
- }
- };
- int main()
- {
- string agreeBook, bookName, FirstName, LastName, nameBS, address;
- int nextEdition = 0, isbnNumber = 0, bookCirculation = 0, phone = 0;
- Books b;
- Date d;
- Bookseller bs;
- Certificate c;
- fstream BookInfo;
- // Write to the file
- BookInfo.open("BookInfo2.txt", ios::out);
- int choice = 0;
- string monthName[] = { "January", "February", "March",
- "April", "May", "June", "July",
- "August", "September", "October",
- "November", "December" };
- do
- {
- //1. Книги
- //2. Издателство
- //3. Купи книга
- cout << "Menu" << endl;
- cout << "-----------------------------------" << endl;
- 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";
- cin >> choice;
- if (choice < 0 && choice > 3) {
- cout << "Incorect number, please try again" << endl;
- cin >> choice;
- }
- cout << "\n";
- switch (choice)
- {
- case 0:
- cout << "Exiting... Have a nice day!";
- break;
- case 1:
- cout << "\n";
- cout << "Enter Books Information:" << endl;
- cout << "-----------------------------------" << endl;
- cout << "";
- cout << "Enter book's name: \n" << endl;
- cin >> bookName;
- b.setBook(bookName);
- cout << b;
- cout << "\n";
- BookInfo << "Book" << endl << "Name:" << bookName << endl;
- cout << "Enter author name: " << endl;
- cin >> FirstName;
- cin >> LastName;
- b.setFirstName(FirstName);
- b.setLastName(LastName);
- cout << b;
- cout << "\n";
- BookInfo <<"Autor: " << FirstName << " " << LastName << endl;
- cout << "Enter next edition: " << endl;
- cin >> nextEdition;
- b.setNextEdition(nextEdition);
- cout << b;
- cout << "\n";
- BookInfo << "Next Edition: " << nextEdition << endl;
- cout << "Enter ISBN number: " << endl;
- cin >> isbnNumber;
- b.setIsbnNumber(isbnNumber);
- cout << b;
- cout << "\n";
- BookInfo << "ISBN number: " << isbnNumber << endl;
- cout << "Entet print date DD/MM/YY: ";
- int day, month, year;
- cin >> day >> month >> year;
- cout << endl;
- cout << day << " " << monthName[month - 1] << " " << year << endl;
- cin.get();
- cout << endl;
- cout << "\n";
- BookInfo << "Date: " << day << " " << monthName[month - 1] << " " << year << endl;
- cout << "Enter circulation: " << endl;
- cin >> bookCirculation;
- b.setCirculation(bookCirculation);
- cout << b;
- cout << "\n";
- BookInfo << "Circulation: " << bookCirculation << endl;
- cout << "Enter yes if this book is agree for certificate." << endl;
- cout << "\n";
- cin >> agreeBook;
- c.setAgree(agreeBook);
- if (agreeBook._Equal("yes")) {
- BookInfo << "Certificate: " << agreeBook << endl;
- BookInfo << "This book has certificate from MON!" << endl;
- cout << "\n";
- }
- else {
- BookInfo << "Certificate: " << agreeBook << endl;
- BookInfo << "This book has not certificate from MON!" << endl;
- cout << "\n";
- }
- break;
- case 2:
- cout << "Enter Bookseller Information:" << endl;
- cout << "-----------------------------------" << endl;
- cout << "Enter bookseller name: " << endl;
- getline(cin, nameBS);
- getline(cin, nameBS);
- cout << "\n";
- bs.setBookseller("" "");
- cout << bs;
- cout << "\n";
- BookInfo << "Bookseller"<< endl << "Bookseller: " << nameBS << endl;
- cout << "Enter address: " << endl;
- getline(cin, address);
- //getline(cin, nameBS);
- bs.setAddress("" "" "");
- cout << bs;
- cout << "\n";
- BookInfo << "Bookseller address: " << address << endl;
- cout << "Enter phone: " << endl;
- cin >> phone;
- bs.setPhone(phone);
- cout << bs;
- cout << "\n";
- BookInfo << "Bookseller phone: " << phone << endl;
- break;
- case 3:
- cout << "Buy a book:" << endl;
- cout << "-----------------------------------" << endl;
- break;
- default:
- cout << "Invalid choice!";
- cout << "\n";
- break;
- }
- } while (choice != 0);
- // Close the file
- BookInfo.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement