#include <iostream>
#include <sstream>
#include <fstream>

using namespace std;

class Sale{///stores data from the input file, use as an array
    string ID;
    float price, amount; // price is per 1.00*amount
public:
    string getID(){return ID;}
    void setID(string s){ID = s;}
    void setPrice(float p){price = p;}
    void setAmount(float a){amount = a;}
    float salePrice(){return price*amount;}
};

class Item{///stores every individual product, use as a stack
    string ID;
    float profit = 0.0;
public:
    string getID(){return ID;}
    float getProfit(){return profit;}
    void setID(string s){ID = s;}
    void updateProfit(float p){profit += p;}
    Item *pNext;
};

int checkFile(ifstream&, string);
///read data from file to stringstream
int readData(ifstream&, stringstream&);
///parse the data in the stringstream and fill the Sale class array
Sale *parseData(stringstream&, int);
///parse the Sale data and create a stack on Item class items
///find the best selling product from the Item stack
///print out the best selling product

int main(void){
    string fileName = "in.txt";
    ifstream myFile (fileName.c_str());
    if(!checkFile(myFile, fileName))
		return 1;
    stringstream ss;
    int amount = readData(myFile, ss);
    Sale *saleArr = parseData(ss, amount);
    ///only function call inside the main
    return 0;
}

int checkFile(ifstream &myFile, string fileName){
	if(!myFile.is_open()){
		cout << "Failed to open file " << fileName << endl;
		return 0;
	}
	return 1;
}

int readData(ifstream &myFile, stringstream &ss){
	string buf;
	int i = 0;
	while(getline(myFile, buf)){
		ss << buf;
		ss << '\n';
		i++;
	}
	myFile.close();
	return i;
}

Sale *parseData(stringstream &ss, int amount){
	Sale saleArr[amount];
	float temp1;
	string temp2;
	for(int i=0;i<amount;i++){
		
	}
	return saleArr;
}
