我有一個類的項目,我不知道這個程序應該使用什麼類型的數組。我必須制定一個股票市場計劃,用戶可以購買,出售和查看股票列表,並檢查他們的賬戶餘額。有跡象表明,包含以下數據的兩個文本文件:我應該使用什麼類型的數組?
Leon1111 5000.00
Wise2222 10000.00
Woo3333 3000.00
White4444 7000.00
Head5555 4000.00
和
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
這是我到目前爲止已經編寫的代碼:你會
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ofstream outStream;
int option;
do
{
cout << "1) Check Stock Listings " << endl;
cout << "2) Buy Stock " << endl;
cout << "3) Sell Stock" << endl;
cout << "4) Check Account Balance " << endl;
cout << "5) Quit " << endl << endl;
cout << "Please select an option : ";
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 a nice day!" << endl << endl;
}
else
{
cout << "Invalid Option entered" << endl;
}
}
while (option != 5);
return 0;
}
很好,你不想讓我們爲你做,但你需要在你的問題更具體。你想要在數組中存儲什麼?它將如何使用? – 2014-11-05 14:59:14
爲什麼downvote? – Engine 2014-11-05 15:00:42
爲什麼不創建一個結構體,然後建立一個結構體數組 – 2014-11-05 15:01:43