Guest User

Untitled

a guest
Oct 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <iomanip>
  5. using namespace std;
  6. class stock
  7. {
  8. public:
  9. char symbol[10];
  10. double openingprice;
  11. double closingprice;
  12. double todayhigh;
  13. double todaylow;
  14. double prevclose;
  15. double volume;
  16. double pgain;
  17. friend ostream& operator<<(ostream& os, const stock stockout);
  18. friend istream& operator>>(ostream& os, stock &stockin);
  19. friend stock operator+(stock instock);
  20. friend stock operator/(stock ,stock );
  21. friend bool operator<(stock s1,stock s2);
  22. void print();
  23. };
  24.  
  25.  
  26. void stock::print(*mystocks)
  27. {
  28. /*cout << "\nstock company by symbol\n\n " << endl;
  29. cout << "********************************************************************" << endl;
  30. cout << "******************* First Investors's Heaven ***********************" << endl;
  31. cout << "******************* Financial Report ***********************" << endl;
  32. cout << "stock today previous precent" << endl;
  33. cout << "symbol open close high low close gain volume" << endl;
  34. cout << "------ ---- ----- ---- --- ----- ---- ------" << endl;
  35. for(int l=0;l<10;l++)
  36. {
  37. mystocks[l].pgain = ((mystocks[l].closingprice/mystocks[l].prevclose)-1)*100;
  38. cout << left << setprecision(0)<< setw(9) << mystocks[l].symbol << setw(9) << mystocks[l].openingprice << setw(9) << mystocks[l].closingprice << setw(9)
  39. << mystocks[l].todayhigh << setw(9) << mystocks[l].todaylow << setw(9) << mystocks[l].prevclose << fixed << setprecision(2) <<
  40. mystocks[l].pgain << right << "%" << setprecision(0) << setw(9) << mystocks[l].volume << endl;
  41. }
  42. cout << "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_" << endl;*/
  43.  
  44. }
  45.  
  46.  
  47. stock operator+(stock instock1,stock instock2)
  48. {
  49. stock temp;
  50. temp.closingprice=instock1.closingprice+instock2.closingprice;
  51. return temp;
  52. }
  53.  
  54.  
  55. stock operator/(stock instock1,stock outstock2)
  56. {
  57. stock temp;
  58. temp.pgain = instock1.closingprice / instock1.prevclose;
  59. return temp;
  60. }
  61.  
  62.  
  63. ostream& operator<<(ostream& os, const stock stockout)
  64. {
  65. os<<stockout.symbol<<" ";
  66. os<<stockout.openingprice<<" ";
  67. os<<stockout.closingprice<<" ";
  68. os<<stockout.todayhigh<<" ";
  69. os<<stockout.todaylow<<" ";
  70. os<<stockout.prevclose<<" ";
  71. os<<stockout.volume<<endl;
  72. return os;
  73. }
  74.  
  75.  
  76. istream& operator>>(istream& is, stock &stockin)
  77. {
  78. is>>stockin.symbol;
  79. is>>stockin.openingprice;
  80. is>>stockin.closingprice;
  81. is>>stockin.todayhigh;
  82. is>>stockin.todaylow;
  83. is>>stockin.prevclose;
  84. is>>stockin.volume;
  85. return is;
  86. }
  87.  
  88.  
  89. bool operator<(stock s1, stock s2)
  90. {
  91. if(strcmp(s1.symbol,s2.symbol)>0)
  92. return true;
  93. return false;
  94. }
  95.  
  96.  
  97. int main()
  98. {
  99. vector<stock> mystocks;
  100. stock temp;
  101. ifstream fstocks("stocks.txt", ifstream::in);
  102.  
  103.  
  104. for(int i=0;i<10;i++)
  105. {
  106. fstocks >> temp;
  107. mystocks.push_back(temp);
  108. }
  109.  
  110. stock stemp;
  111.  
  112. for(int i=0;i<10;i++)
  113. {
  114. for(int j=0;j<9;j++)
  115. {
  116. if(mystocks[j]<mystocks[j+1])
  117. {
  118. stemp=mystocks[j];
  119. mystocks[j]=mystocks[j+1];
  120. mystocks[j+1]=stemp;
  121. }
  122. }
  123. }
  124.  
  125. stemp.print(&mystocks);
  126.  
  127. stock atemp;
  128.  
  129. for(int i=0;i<10;i++)
  130. {
  131. for(int j=0;j<9;j++)
  132. {
  133. if(mystocks[j].pgain<mystocks[j+1].pgain)
  134. {
  135. atemp=mystocks[j];
  136. mystocks[j]=mystocks[j+1];
  137. mystocks[j+1]=atemp;
  138. }
  139. }
  140. }
  141. //atemp.print(&mystocks);
  142.  
  143. system("pause");
  144. }
Add Comment
Please, Sign In to add comment