Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <iomanip>
- using namespace std;
- class stock
- {
- public:
- char symbol[10];
- double openingprice;
- double closingprice;
- double todayhigh;
- double todaylow;
- double prevclose;
- double volume;
- double pgain;
- friend ostream& operator<<(ostream& os, const stock stockout);
- friend istream& operator>>(ostream& os, stock &stockin);
- friend stock operator+(stock instock);
- friend stock operator/(stock ,stock );
- friend bool operator<(stock s1,stock s2);
- void print();
- };
- void stock::print(*mystocks)
- {
- /*cout << "\nstock company by symbol\n\n " << endl;
- cout << "********************************************************************" << endl;
- cout << "******************* First Investors's Heaven ***********************" << endl;
- cout << "******************* Financial Report ***********************" << endl;
- cout << "stock today previous precent" << endl;
- cout << "symbol open close high low close gain volume" << endl;
- cout << "------ ---- ----- ---- --- ----- ---- ------" << endl;
- for(int l=0;l<10;l++)
- {
- mystocks[l].pgain = ((mystocks[l].closingprice/mystocks[l].prevclose)-1)*100;
- cout << left << setprecision(0)<< setw(9) << mystocks[l].symbol << setw(9) << mystocks[l].openingprice << setw(9) << mystocks[l].closingprice << setw(9)
- << mystocks[l].todayhigh << setw(9) << mystocks[l].todaylow << setw(9) << mystocks[l].prevclose << fixed << setprecision(2) <<
- mystocks[l].pgain << right << "%" << setprecision(0) << setw(9) << mystocks[l].volume << endl;
- }
- cout << "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_" << endl;*/
- }
- stock operator+(stock instock1,stock instock2)
- {
- stock temp;
- temp.closingprice=instock1.closingprice+instock2.closingprice;
- return temp;
- }
- stock operator/(stock instock1,stock outstock2)
- {
- stock temp;
- temp.pgain = instock1.closingprice / instock1.prevclose;
- return temp;
- }
- ostream& operator<<(ostream& os, const stock stockout)
- {
- os<<stockout.symbol<<" ";
- os<<stockout.openingprice<<" ";
- os<<stockout.closingprice<<" ";
- os<<stockout.todayhigh<<" ";
- os<<stockout.todaylow<<" ";
- os<<stockout.prevclose<<" ";
- os<<stockout.volume<<endl;
- return os;
- }
- istream& operator>>(istream& is, stock &stockin)
- {
- is>>stockin.symbol;
- is>>stockin.openingprice;
- is>>stockin.closingprice;
- is>>stockin.todayhigh;
- is>>stockin.todaylow;
- is>>stockin.prevclose;
- is>>stockin.volume;
- return is;
- }
- bool operator<(stock s1, stock s2)
- {
- if(strcmp(s1.symbol,s2.symbol)>0)
- return true;
- return false;
- }
- int main()
- {
- vector<stock> mystocks;
- stock temp;
- ifstream fstocks("stocks.txt", ifstream::in);
- for(int i=0;i<10;i++)
- {
- fstocks >> temp;
- mystocks.push_back(temp);
- }
- stock stemp;
- for(int i=0;i<10;i++)
- {
- for(int j=0;j<9;j++)
- {
- if(mystocks[j]<mystocks[j+1])
- {
- stemp=mystocks[j];
- mystocks[j]=mystocks[j+1];
- mystocks[j+1]=stemp;
- }
- }
- }
- stemp.print(&mystocks);
- stock atemp;
- for(int i=0;i<10;i++)
- {
- for(int j=0;j<9;j++)
- {
- if(mystocks[j].pgain<mystocks[j+1].pgain)
- {
- atemp=mystocks[j];
- mystocks[j]=mystocks[j+1];
- mystocks[j+1]=atemp;
- }
- }
- }
- //atemp.print(&mystocks);
- system("pause");
- }
Add Comment
Please, Sign In to add comment