Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. class Song
  8. {
  9. char name[31];
  10. char style;
  11. char singer[16];
  12. short year;
  13. char album[21];
  14. int count;
  15. public:
  16. void inp(istream &is)
  17. {
  18. if(is==cin) cout<<"Title: ";
  19. is.getline(name,31);
  20. if(is==cin) cout<<"Style (1-jazz,2-pop,3-rock,4-folk,5-classic): ";
  21. is>>style;
  22. is.ignore();
  23. if(is==cin) cout<<"Singer: ";
  24. is.getline(singer,16);
  25. if(is==cin) cout<<"Year: ";
  26. is>>year;
  27. is.ignore();
  28. if(is==cin) cout<<"Album: ";
  29. is.getline(album,21);
  30. if(is==cin) cout<<"Count: ";
  31. is>>count;
  32. is.ignore();
  33. }
  34. void out()
  35. {
  36. cout<<name<<"; "<<style<<"; "<<singer<<"; "<<year<<"; "<<album<<"; "<<count<<endl;
  37. }
  38. const char *getName() const
  39. {
  40. return name;
  41. }
  42. };
  43.  
  44. Song s[5000];
  45. int n;
  46.  
  47. void inp(istream &is)
  48. {
  49. if(is==cin) cout<<"Song count: ";
  50. is>>n;
  51. is.ignore();
  52. for(int i=0;i<n;i++)
  53. {
  54. if(is==cin) cout<<"Song #"<<i+1<<endl;
  55. s[i].inp(is);
  56. }
  57. }
  58.  
  59. void out()
  60. {
  61. for(int i=0;i<n;i++)
  62. {
  63. s[i].out();
  64. }
  65. }
  66.  
  67. void Bub()
  68. {
  69. bool f;
  70. int d=n-1;
  71. do
  72. {
  73. f=false;
  74. for(int i=0;i<d;i++)
  75. {
  76. if(strcmp(s[i].getName(),s[i+1].getName())>0)
  77. {
  78. Song t=s[i];
  79. s[i]=s[i+1];
  80. s[i+1]=t;
  81. f=true;
  82. }
  83. d--;
  84. }
  85. }
  86. while(f);
  87. }
  88.  
  89.  
  90. int main()
  91. {
  92. ifstream f("data.txt");
  93. if(!f)
  94. {
  95. cout<<"File not found!";
  96. return 0;
  97. }
  98. inp(f);
  99. out();
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement