I started learning about objects and classes this week and it's really confusing. I'm trying to make a class/object to read data from an input file and use the values to calculate the profit loss/gain(in percent and numbers). So far when I try to run the program I get an error saying " 'main' : looks like a function definition, but there is no parameter list; skipping apparent body"
Current input from txt file:
IBM 100 93.2 98.6
MER 200 67.2 43.89
QQQ 300 78.9 70.0
C 200 35.78 50.02
CSCO 400 45.67 57.23
What I have so far(Sorry if it's messy, it's my first time working with class/objects):
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
class Stock
{
private:
string stockName;
double numShares;
double buyPrice;
double currPrice;
public:
void setstockName(string);
void setnumShares(double);
void setbuyPrice(double);
void setcurrPrice(double);
double computePercentProfitLoss(double);
double computeDollarProfitLoss(double);
};
int main{}
{
Stock stockdata;
string stockname;
double numshar, buypric, currpric;
ifstream inFile;
ofstream outFile;
inFile.open("C:\\text1.txt");
outFile.open("C:\\text2.txt");
if(!inFile.good())
{
cout << "Unable to open file";
}
while (inFile.good())
{
inFile >> stocknam >> numshar >> buypric >> currpric;
stockdata.setstockName(stocknam);
stockdata.setnumShares(numchar);
stockdata.setbuyPrice(buypric);
stockdata.setcurrPrice(currpric);
}
outfile << setw(7) << "Stock" << setw(7) << "# Shares" << setw(7) << "Buy Price" << setw(7) << "Current Price << setw(7) << "$P/L" << setw(7) << "%P/L"<<endl;
outFile << setw(7) << stockName << setw(7) << numShares << setw(7) << buyPrice << setw(7) << currPrice << setw(7) << computePercentProfitLoss(stockdata.setnumShares(), stockdata.setbuyPrice(), stockdata.setcurrPrice())<< setw(7)<< computePercentProfitLoss(stockdata.setnumShares(), stockdata.setbuyPrice(), stockdata.setcurrPrice())<< endl;
inFile.close();
outFile.close();
return 0;
}
double computePercentProfitLoss(double nshare, double bprice, double cprice);
{
double percentloss;
percentloss= ((cprice - bprice) * nshare) / bprice;
if(percentloss)
{
cout<<"(percentloss)"<<endl;
}
return percentloss;
}
double computeDollarProfitLoss(double nshare2, double bprice2, double cprice2)
{
double profitloss;
profitloss = ((cprice2 - bprice2) * nshare2);
if(profitloss <0)
{
cout<<"(profitloss)"<<endl;
}
return profitloss;
}