Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- class Song
- {
- char name[31];
- char style;
- char singer[16];
- short year;
- char album[21];
- int count;
- public:
- void inp(istream &is)
- {
- if(is==cin) cout<<"Title: ";
- is.getline(name,31);
- if(is==cin) cout<<"Style (1-jazz,2-pop,3-rock,4-folk,5-classic): ";
- is>>style;
- is.ignore();
- if(is==cin) cout<<"Singer: ";
- is.getline(singer,16);
- if(is==cin) cout<<"Year: ";
- is>>year;
- is.ignore();
- if(is==cin) cout<<"Album: ";
- is.getline(album,21);
- if(is==cin) cout<<"Count: ";
- is>>count;
- is.ignore();
- }
- void out()
- {
- cout<<name<<"; "<<style<<"; "<<singer<<"; "<<year<<"; "<<album<<"; "<<count<<endl;
- }
- const char *getName() const
- {
- return name;
- }
- };
- Song s[5000];
- int n;
- void inp(istream &is)
- {
- if(is==cin) cout<<"Song count: ";
- is>>n;
- is.ignore();
- for(int i=0;i<n;i++)
- {
- if(is==cin) cout<<"Song #"<<i+1<<endl;
- s[i].inp(is);
- }
- }
- void out()
- {
- for(int i=0;i<n;i++)
- {
- s[i].out();
- }
- }
- void Bub()
- {
- bool f;
- int d=n-1;
- do
- {
- f=false;
- for(int i=0;i<d;i++)
- {
- if(strcmp(s[i].getName(),s[i+1].getName())>0)
- {
- Song t=s[i];
- s[i]=s[i+1];
- s[i+1]=t;
- f=true;
- }
- d--;
- }
- }
- while(f);
- }
- int main()
- {
- ifstream f("data.txt");
- if(!f)
- {
- cout<<"File not found!";
- return 0;
- }
- inp(f);
- out();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement