Advertisement
Guest User

__1__

a guest
Dec 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<fstream>
  5.  
  6. using namespace std;
  7.  
  8. const size_t MAX_LEN = 256;
  9.  
  10. struct book {
  11.  
  12.     char author[MAX_LEN];
  13.     char name[MAX_LEN];
  14.     int edition;
  15.     int price;
  16.  
  17. };
  18.  
  19. void read(book &b, istream &is){
  20.     is >> b.author >> b.name >> b.edition >> b.price;
  21. }
  22. void write(const book &b, ostream &os){
  23.     os << b.author << " "
  24.        << b.name << " "
  25.        << b.edition << " "
  26.        << b.price << "\n";
  27. }
  28.  
  29. int main(){
  30.  
  31.     ifstream in("input.txt");
  32.  
  33.     int n;
  34.     in >> n;
  35.  
  36.     book *lib = new book[n];
  37.     for (int i = 0; i < n; ++i){
  38.         read(lib[i], in);
  39.     }
  40.  
  41.     cout << "Library (input.txt): \n";
  42.     for (int i = 0; i < n; ++i){
  43.         write(lib[i], cout);
  44.     }
  45.  
  46.     delete[] lib;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement