I CAN NOT OPEN THE FILE. CAN YOU FIX IT? #include #include #include #include #include using namespace std; class Stock { public: int num_shares; string stock_symbol; double stock_price; void setNumberOfshares(int num) { num_shares = num; } void setSymbol(string symb) { stock_symbol = symb; } void setPrice(double pric) { stock_price = pric; } }; void read(istream& reader) { while (reader.eof() == false) { string oneLine; getline(reader, oneLine); cout << "Line: " << oneLine << endl; } } void Menu() { cout << "\"buy\"\tbuy a stock by asking for the stock symbol, quantityand share price" << endl; cout << "\"display\"\tdisplay all purchases" << endl; cout << "\"summary\"\tdisplay only the summary of purchase totaland number of purchases" << endl; cout << "\"find \"\tdisplay all purchase only for that symbol" << endl; cout << "\"amount >= \"\tdisplay all purchases >= the given amount" << endl; cout << "\"help\"\tdisplay this help message" << endl; cout << "\"exit\"\texit the program after the confirmation" << endl; } int main(int argc, char* argv[]) { if (argc == 2) { string dataFileName = argv[1]; cout << "Stock data file name: " << dataFileName << endl; ifstream fin(dataFileName); if (fin.is_open() == false) { cout << "File is not found. Please check the location and the file." << endl; } else { int quantity = 0; string symbol = "" ; double price = 0.0 ; fin >> quantity ; fin >> symbol ; fin >> price ; cout << "Quantity: " << quantity << " Symbol: " << symbol << " Price: " << price << endl ; string oneLine ; getline(fin, oneLine) ; getline(fin, oneLine) ; cout << "2nd line: " << oneLine << endl ; read(fin); read(cin); } fin.close(); } return 0; }
I CAN NOT OPEN THE FILE. CAN YOU FIX IT?
#include<iostream>
#include<fstream>
#include<iomanip>
#include<vector>
#include<string>
using namespace std;
class Stock
{
public:
int num_shares;
string stock_symbol;
double stock_price;
void setNumberOfshares(int num)
{
num_shares = num;
}
void setSymbol(string symb)
{
stock_symbol = symb;
}
void setPrice(double pric)
{
stock_price = pric;
}
};
void read(istream& reader)
{
while (reader.eof() == false)
{ string oneLine;
getline(reader, oneLine);
cout << "Line: " << oneLine << endl; }
}
void Menu()
{
cout << "\"buy\"\tbuy a stock by asking for the stock symbol, quantityand share price" << endl;
cout << "\"display\"\tdisplay all purchases" << endl;
cout << "\"summary\"\tdisplay only the summary of purchase totaland number of purchases" << endl;
cout << "\"find <stock - symbol>\"\tdisplay all purchase only for that symbol" << endl;
cout << "\"amount >= <purchase - amount>\"\tdisplay all purchases >= the given amount" << endl;
cout << "\"help\"\tdisplay this help message" << endl;
cout << "\"exit\"\texit the
}
int main(int argc, char* argv[])
{
if (argc == 2) {
string dataFileName = argv[1];
cout << "Stock data file name: " << dataFileName << endl;
ifstream fin(dataFileName);
if (fin.is_open() == false)
{
cout << "File is not found. Please check the location and the file." << endl;
}
else {
int quantity = 0;
string symbol = "" ;
double price = 0.0 ;
fin >> quantity ;
fin >> symbol ;
fin >> price ;
cout << "Quantity: " << quantity << " Symbol: " << symbol << " Price: " << price << endl ;
string oneLine ;
getline(fin, oneLine) ;
getline(fin, oneLine) ;
cout << "2nd line: " << oneLine << endl ;
read(fin);
read(cin); }
fin.close();
}
return 0;
}
Step by step
Solved in 2 steps with 2 images