Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct kniga
- {
- string zaglavie;
- string avtor;
- string izdatelstvo;
- int godina;
- };
- void readKniga(fstream &f,int n)
- {
- kniga s;
- f.open("knigi.txt",ios::app | ios::out);
- for(int i = 1;i<=n;i++)
- {
- cout<<"Zaglavie: ";
- cin>>s.zaglavie;
- cout<<"Avtor: ";
- cin>>s.avtor;
- cout<<"Izdatelstvo: ";
- cin>>s.izdatelstvo;
- cout<<"Godina na izdavane: ";
- cin>>s.godina;
- f<<s.zaglavie<<"\n"<<s.avtor<<"\n"<<s.izdatelstvo<<"\n"<<s.godina<<"\n"<<endl;
- cout<<endl;
- }
- f.clear();
- f.close();
- }
- void printBooksByYear(fstream &f,int godina)
- {
- kniga s;
- f.open("knigi.txt");
- while(!f.eof())
- {
- f>>s.zaglavie>>ws;
- f>>s.avtor>>ws;
- f>>s.izdatelstvo>>ws;
- f>>s.godina>>ws;
- if(s.godina==godina)
- {
- cout<<s.zaglavie<<endl;
- }
- }
- f.clear();
- f.close();
- }
- void printAuthorsByPubl(fstream &f,string izdatelstvo)
- {
- kniga s;
- f.open("knigi.txt");
- while(!f.eof())
- {
- f>>s.zaglavie>>ws;
- f>>s.avtor>>ws;
- f>>s.izdatelstvo>>ws;
- f>>s.godina>>ws;
- if(s.izdatelstvo==izdatelstvo)
- {
- cout<<s.avtor<<endl;
- }
- }
- f.clear();
- f.close();
- }
- int main()
- {
- int n;
- fstream f;
- char ch;
- int godina;
- string izdatelstvo;
- do
- {
- system("cls");
- cout<<"MAIN MENU"<<endl;
- cout<<"1. Vavejdane"<<endl;
- cout<<"2. Tursi knigi po godina"<<endl;
- cout<<"3. Tursi avtori po izdatelstvo"<<endl;
- cout<<"4. Izhod"<<endl;
- cout<<"Vavedi chislo: ";
- cin>>ch;
- system("cls");
- switch (ch)
- {
- case '1':
- cout<<"n =";
- cin>>n;
- readKniga(f,n);
- break;
- case'2':
- cout<<"Vavedi godina: ";
- cin>>godina;
- cout<<"Knigi:"<<endl;
- printBooksByYear(f,godina);
- break;
- case'3':
- cout<<"Vavedi izdatelstvo: ";
- cin>>izdatelstvo;
- cout<<"Avtori: "<<endl; printAuthorsByPubl(f,izdatelstvo);
- break;
- }
- system("pause");
- }
- while (ch!='4');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement