Advertisement
DacCum

ООП лаб 10(1)

Nov 10th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class book {
  7.     string title;
  8.     string author;
  9.     double price;
  10. public:
  11.     friend istream& operator>> (istream& in, book& b);
  12.     friend ostream& operator<< (ostream& out, book& b);
  13. };
  14.  
  15. istream& operator>> (istream& in, book& b) {
  16.     cout << "Enter title: ";
  17.     getline(in, b.title);
  18.     cout << "Enter authoe: ";
  19.     getline(in, b.author);
  20.     cout << "Enter price: ";
  21.     in >> b.price;
  22.     in.ignore(37578, '\n');
  23.     return in;
  24. }
  25.  
  26. ostream& operator<< (ostream& out, book& b) {
  27.     out << "Title: " << b.title << endl;
  28.     out << "Author: " << b.author << endl;
  29.     out << "Price: " << b.price << endl;
  30.     return out;
  31. }
  32.  
  33. int main() {
  34.     book b;
  35.     cout << "Enter info about book: " << endl;
  36.     cin >> b;
  37.  
  38.     cout << endl << b << endl;
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement