Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct kniga
  4. {
  5.     string zaglavie;
  6.     string avtor;
  7.     string izdatelstvo;
  8.     int godina;
  9.  
  10.    
  11. };
  12. void readKniga(fstream &f,int n)
  13. {
  14.     kniga s;
  15.     f.open("knigi.txt",ios::app | ios::out);
  16.  
  17.     for(int i = 1;i<=n;i++)
  18.     {
  19.         cout<<"Zaglavie: ";
  20.           cin>>s.zaglavie;
  21.         cout<<"Avtor: ";
  22.           cin>>s.avtor;
  23.         cout<<"Izdatelstvo: ";    
  24.          cin>>s.izdatelstvo;
  25.         cout<<"Godina na izdavane: ";    
  26.          cin>>s.godina;
  27.        
  28.        f<<s.zaglavie<<"\n"<<s.avtor<<"\n"<<s.izdatelstvo<<"\n"<<s.godina<<"\n"<<endl;
  29.         cout<<endl;
  30.     }
  31.  
  32.     f.clear();
  33.     f.close();
  34.  
  35.  
  36. }
  37. void printBooksByYear(fstream &f,int godina)
  38. {
  39.     kniga s;
  40.     f.open("knigi.txt");
  41.  
  42.     while(!f.eof())
  43.     {
  44.         f>>s.zaglavie>>ws;
  45.         f>>s.avtor>>ws;
  46.         f>>s.izdatelstvo>>ws;
  47.         f>>s.godina>>ws;
  48.        
  49.      if(s.godina==godina)
  50.         {
  51.         cout<<s.zaglavie<<endl;
  52.         }
  53.     }
  54.  
  55.     f.clear();
  56.     f.close();
  57. }
  58. void printAuthorsByPubl(fstream &f,string izdatelstvo)
  59. {
  60.     kniga s;
  61.     f.open("knigi.txt");
  62.  
  63.     while(!f.eof())
  64.     {
  65.         f>>s.zaglavie>>ws;
  66.         f>>s.avtor>>ws;
  67.         f>>s.izdatelstvo>>ws;
  68.         f>>s.godina>>ws;
  69.        
  70.      if(s.izdatelstvo==izdatelstvo)
  71.         {
  72.         cout<<s.avtor<<endl;
  73.         }
  74.     }
  75.  
  76.     f.clear();
  77.     f.close();
  78. }      
  79. int main()
  80. {
  81. int n;
  82. fstream f;
  83. char ch;
  84. int godina;
  85. string izdatelstvo;
  86.     do
  87.     {
  88.         system("cls");
  89.         cout<<"MAIN MENU"<<endl;
  90.         cout<<"1. Vavejdane"<<endl;
  91.         cout<<"2. Tursi knigi po godina"<<endl;
  92.         cout<<"3. Tursi avtori po izdatelstvo"<<endl;
  93.         cout<<"4. Izhod"<<endl;
  94.          cout<<"Vavedi chislo: ";
  95.         cin>>ch;
  96.         system("cls");
  97.         switch (ch)
  98.         {
  99.         case '1':
  100.             cout<<"n =";
  101.             cin>>n;
  102.             readKniga(f,n);
  103.  
  104.             break;
  105.  
  106.         case'2':
  107.             cout<<"Vavedi godina: ";
  108.             cin>>godina;
  109.             cout<<"Knigi:"<<endl;
  110.             printBooksByYear(f,godina);
  111.            
  112.             break;
  113.         case'3':
  114.             cout<<"Vavedi izdatelstvo: ";
  115.             cin>>izdatelstvo;
  116.            cout<<"Avtori: "<<endl; printAuthorsByPubl(f,izdatelstvo);
  117.             break;
  118.         }
  119.         system("pause");
  120.     }
  121.     while (ch!='4');
  122.  
  123.  
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement