Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6.  
  7. class dep{
  8.  
  9. public:
  10.  
  11. dep();
  12. friend std::ostream& operator<< (std::ostream &out, const dep &DEP);
  13. friend std::istream& operator>> (std::istream &in, dep &DEP);
  14. void print();
  15. char* gets_fam(){return s_fam;}
  16. char* getnumb_of_dep(){return numb_of_dep;}
  17. double get_income(){return income;}
  18. double get_outcome(){return outcome;}
  19. ~dep();
  20. dep(const dep &DEP);
  21. dep& operator= (const dep &DEP);
  22.  
  23. dep(char* init1,char* init2,double init3, double init4);
  24. private:
  25.  
  26. double income;
  27. double outcome;
  28. char* numb_of_dep;
  29. char* s_fam;
  30.  
  31. };
  32. dep :: dep()
  33.  
  34. { s_fam=NULL;
  35. numb_of_dep=NULL;
  36. income=0;
  37. outcome=0;
  38.  
  39.  
  40. }
  41. dep::dep(char* init1,char* init2,double init3, double init4):
  42. numb_of_dep(new char[strlen(init2)+1]),s_fam(new char[strlen(init1)+1])
  43. {
  44. strcpy( s_fam,init1);
  45. strcpy(numb_of_dep,init2);
  46. income =init3;
  47. outcome =init4;
  48.  
  49. }
  50. ostream& operator<< (ostream &out, const dep &DEP)
  51. {
  52.  
  53. out << DEP.s_fam<<" "<<DEP.numb_of_dep<<" "<<DEP.income<<" "<<DEP.outcome<<endl;
  54.  
  55. return out;
  56. }
  57. istream& operator>> (istream &in, dep &DEP)
  58. {
  59. char buff1[100];
  60. char buff2[100];
  61.  
  62. in >> buff1 >> buff2 >> DEP.income >> DEP.outcome;
  63. delete[] DEP.s_fam;
  64. delete[] DEP.numb_of_dep;
  65. int n=strlen(buff1);
  66. int l=strlen(buff2);
  67. DEP.s_fam=new char[n+1];
  68. DEP.numb_of_dep=new char[l+1];
  69. strcpy(DEP.gets_fam(),buff1);
  70. strcpy(DEP.numb_of_dep,buff2);
  71. return in;
  72. }
  73. dep& dep::operator= (const dep &DEP)
  74. {
  75.  
  76. if (this == &DEP)
  77. return *this;
  78.  
  79.  
  80. income=DEP.income;
  81. outcome=DEP.outcome;
  82. delete[] numb_of_dep;
  83. numb_of_dep=new char[strlen(DEP.numb_of_dep)+1];
  84. strcpy(numb_of_dep,DEP.numb_of_dep);
  85. delete[] s_fam;
  86. s_fam=new char[strlen(DEP.numb_of_dep)+1];
  87. strcpy(s_fam,DEP.s_fam);
  88.  
  89.  
  90.  
  91.  
  92. return *this;
  93. }
  94. dep::dep(const dep &DEP):
  95. numb_of_dep(new char[strlen(DEP.numb_of_dep)+1]),s_fam(new char[strlen(DEP.s_fam)+1])
  96. {
  97. income=DEP.income;
  98. outcome=DEP.outcome;
  99. strcpy(numb_of_dep,DEP.numb_of_dep);
  100. strcpy(s_fam,DEP.s_fam);
  101.  
  102. }
  103. dep::~dep(){
  104. delete [] s_fam;
  105. delete [] numb_of_dep;
  106. }
  107. struct max_value{
  108.  
  109. char fam[40];
  110. double money;
  111.  
  112. };
  113. bool comp(max_value k,max_value b){
  114. if (k.money>b.money)
  115. return true;
  116. return false;
  117. }
  118. int main(){
  119. dep s;
  120. cin>>s;
  121. s=s;
  122. cout<<s;
  123.  
  124.  
  125. setlocale(LC_ALL, "rus");
  126. int n;
  127. cin>>n;
  128. dep k[30];
  129. for(int i=0;i<n;i++){
  130.  
  131.  
  132.  
  133. cin>> k[i];
  134.  
  135. }
  136.  
  137. max_value q[100];
  138.  
  139. int f=1;
  140. strcpy(q[0].fam,k[0].gets_fam());
  141. q[0].money=k[0].get_income()-k[0].get_outcome();
  142. for(int i=1;i<n;i++){
  143. bool flag=0;
  144. for(int j=0;j<f;j++ ){
  145. if(! strcmp( k[i].gets_fam(),q[j].fam)){
  146. q[j].money+=k[i].get_income()-k[i].get_outcome();
  147. flag=1;
  148. }
  149.  
  150. }
  151. if(!flag){
  152.  
  153. strcpy(q[f].fam,k[i].gets_fam());
  154. q[f].money=k[i].get_income()-k[i].get_outcome();
  155. f++;
  156. }
  157. }
  158. sort(begin(q),end(q),comp);
  159. for(int i=0;i<f;i++){
  160. cout<<q[i].fam<<" "<<q[i].money<<endl;}
  161.  
  162.  
  163.  
  164. return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement