c++ - What type of array should I be using? -
c++ - What type of array should I be using? -
i have project class , i'm not sure type of array should using program. have create stock market programme user buys, sells , views stock listings , checks business relationship balance. there 2 text files contain next data:
class="lang-none prettyprint-override">leon1111 5000.00 wise2222 10000.00 woo3333 3000.00 white4444 7000.00 head5555 4000.00
and
class="lang-none prettyprint-override">apple aapl 450.00 boeing ba 75.50 intel intc 22.30 rambus rmbs 5.55 sirius siri 3.15 skyworks swks 25.35 xilinx xlnx 36.80
this code i've written far:
class="lang-cpp prettyprint-override">#include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #include <string> using namespace std; int main() { ofstream outstream; int option; { cout << "1) check stock listings " << endl; cout << "2) purchase stock " << endl; cout << "3) sell stock" << endl; cout << "4) check business relationship balance " << endl; cout << "5) quit " << endl << endl; cout << "please select alternative : "; cin >> option; cout << endl; if (option == 1) { fstream companiesfile; companiesfile.open("companies.txt"); if (companiesfile.is_open()) { string s; while (getline(companiesfile, s, '\n')) { cout << s << endl; } } companiesfile.close(); } else if (option == 2) { } else if (option == 3) { } else if (option == 4) { fstream accountfile; accountfile.open("account.txt"); if (accountfile.is_open()) { string t; while (getline(accountfile, t)) { cout << t << endl; } } accountfile.close(); } else if (option == 5) { cout << "program terminated. have nice day!" << endl << endl; } else { cout << "invalid alternative entered" << endl; } } while (option != 5); homecoming 0; }
class ccompany { std::string myname; std::string mysymbol; double myprice; public: ccompany( const std::string& name, const std::string& symbol, double cost ) : myname( name ), mysymbol( symbol ), myprice( cost ) {} }; std::vector< ccompany > vcompany; class caccount { std::string myname double mybalance; public: caccount( const std:string& name, double balance ) : myname( name ), mybalance( balance ) {} }; std:vector< caccount > vaccount; ... std::string name; std::string symbol; double price; while ( companiesfile.good() ) { companiesfile >> name; companiesfile >> symbol; companiesfile >> price; vcompany.push_back( ccompany( name, symbol, cost )); }
c++ arrays
Comments
Post a Comment