Guest User

Untitled

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. const int en=100;
  8.  
  9. //-------------
  10. class Prekes
  11. {
  12. string pav,
  13. tiek;
  14. int kiek;
  15. double kain;
  16. public:
  17. Prekes(string kpav, string ktiek, int kkiek, double kkain);
  18. Prekes() {pav=""; tiek=""; kiek = 0; kain = 0; t=0; t1=0;}
  19. ~Prekes() {}
  20. bool LygintiPrekes(Prekes Lyginamoji);
  21. string ImtiPav() {return pav;}
  22. string ImtiTiek() {return tiek;}
  23. int ImtiKiek() {return kiek;}
  24. void DidintiKiek(int didinamasis) {kiek+=didinamasis;}
  25. double ImtiKain() {return kain;}
  26. int t;
  27. int t1;
  28.  
  29. };
  30.  
  31.  
  32. //--------------
  33. void main()
  34. {
  35. ifstream fd;
  36. ofstream fr;
  37. string mpav,
  38. mtiek,
  39. tiekejas[en];
  40. int mkiek,
  41. n,
  42. tvarkytuViet=0,
  43. tiekViet=0,
  44. pasTiekPrekiu[en],
  45. tiekPrek[en][en],
  46. pasSitaTiekPrekiu=0;
  47. unsigned int pavIlg=0,
  48. tiekIlg=0;
  49.  
  50. double mkain;
  51. Prekes PradPreke [en],
  52. Preke [en];
  53.  
  54.  
  55. //--------------------
  56. fd.open("duomenys.txt");
  57. fr.open("rezultatai.txt");
  58. //--------------------
  59. setlocale(LC_ALL, "Lithuanian");
  60. fd >> n;
  61. //skaitymas
  62. for (int i=0; i < n; i++)
  63. {
  64. fd >> mpav >> mkiek
  65. >> mkain >> mtiek;
  66. if (mpav.length() > pavIlg) pavIlg = mpav.length();
  67. if (mtiek.length() > tiekIlg) tiekIlg = mtiek.length();
  68. PradPreke[i] = Prekes(mpav, mtiek, mkiek, mkain);
  69. PradPreke[i].t=0;
  70. PradPreke[i].t1=0;
  71. }
  72. //Visko rasymas
  73. fr << "Pradiniai duomenys : " << endl;
  74. for (int i=0; i<n; i++)
  75. {
  76. fr << setw(pavIlg) << left << PradPreke[i].ImtiPav() << " " << setw(8) << PradPreke[i].ImtiKiek() << " "
  77. << setw(8) << PradPreke[i].ImtiKain() << " " << setw(tiekIlg) << PradPreke[i].ImtiTiek() << endl;
  78. }
  79. //Prekiu masyvo taisymas
  80. for (int i=0; i<n; i++)
  81. {
  82. if (PradPreke[i].t)
  83. {
  84. cout << "Prašoku" << endl;
  85. continue;
  86. }
  87. Preke[tvarkytuViet] = Prekes(PradPreke[i].ImtiPav(), PradPreke[i].ImtiTiek(),
  88. PradPreke[i].ImtiKiek(), PradPreke[i].ImtiKain());
  89. PradPreke[i].t = 1;
  90. for (int j=i+1; j<n; j++)
  91. {
  92. if (PradPreke[j].t) continue;
  93. if (PradPreke[i].LygintiPrekes(PradPreke[j]))
  94. {
  95. Preke[tvarkytuViet].DidintiKiek(PradPreke[j].ImtiKiek());
  96. PradPreke[j].t=1;
  97. }
  98. }
  99. ++tvarkytuViet;
  100. }
  101. //Tvarkytu Prekiu masyvo rasymas
  102. fr << "-----------------------";
  103. cout << endl << "tvarkytuViet = " << tvarkytuViet << endl;
  104. fr << endl << "Sutvarkytas prekiu masyvas:" << endl;
  105. for (int i=0; i < tvarkytuViet+1; i++)
  106. {
  107. if (Preke[i].ImtiKiek() == 0) continue;
  108. fr << setw(pavIlg) << left << Preke[i].ImtiPav() << " " << setw(8) << Preke[i].ImtiKiek() << " "
  109. << setw(8) << Preke[i].ImtiKain() << " " << setw(tiekIlg) << Preke[i].ImtiTiek() << endl;
  110. }
  111. //Prekiu Rūšiavimas pagal tiekėją
  112. for (int i=0; i<tvarkytuViet+1; i++)
  113. {
  114. if (Preke[i].t1) continue;
  115. tiekejas[tiekViet] = Preke[i].ImtiTiek();
  116. Preke[i].t1=1;
  117. for (int j=0; j < tvarkytuViet+1; j++)
  118. {
  119. if (tiekejas[tiekViet] != Preke[j].ImtiTiek()) continue;
  120. Preke[j].t1=1;
  121. pasSitaTiekPrekiu = pasTiekPrekiu[tiekViet];
  122. tiekPrek[tiekViet][pasTiekPrekiu[tiekViet]] = j;
  123. pasTiekPrekiu[tiekViet] +=1;
  124. }
  125. tiekViet+=1;
  126. }
  127. //Tiekejų rašymas
  128. fr << "-----------------------" << endl << "Prekiu sararas pagal tiekejus:" << endl;
  129. for (int i=0; i < tiekViet+1; i++)
  130. {
  131. fr << endl << setw(tiekIlg) <<tiekejas[i] << ":" << endl;
  132. for (int j=0; j<pasTiekPrekiu[i]; j++)
  133. fr << setw(pavIlg) <<Preke[tiekPrek[i][j]].ImtiPav()
  134. << setw(8) <<Preke[tiekPrek[i][j]].ImtiKiek()
  135. << setw(8) <<Preke[tiekPrek[i][j]].ImtiKain() << endl;
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. system("pause");
  144. }
  145.  
  146.  
  147. //---------------
  148. Prekes::Prekes(string kpav, string ktiek, int kkiek, double kkain) :
  149. pav(kpav), tiek(ktiek), kiek(kkiek), kain(kkain) {}
  150.  
  151. //--------------
  152. bool Prekes::LygintiPrekes(Prekes Lyginamoji)
  153. {
  154. if ( (pav == Lyginamoji.ImtiPav()) &&
  155. (tiek == Lyginamoji.ImtiTiek()) &&
  156. (kain == Lyginamoji.ImtiKain()) )
  157. return true;
  158. else return false;
  159. }
Add Comment
Please, Sign In to add comment