Skip to content

Instantly share code, notes, and snippets.

Created April 20, 2017 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ddf4f71edcd133f4588c41eb711840bb to your computer and use it in GitHub Desktop.
Save anonymous/ddf4f71edcd133f4588c41eb711840bb to your computer and use it in GitHub Desktop.
int main() {
Book b;
vector<Book> books;
string tempTitle, tempAuthor, tempisbn, tempPrice, tempCost, tempqtyOnHand, tempqtySold;
ofstream out("new_list.txt");
ifstream inClientFile{ "Book_List.txt" };
if (!inClientFile) {
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
while (inClientFile.peek() != EOF) {
//CreateBook to store data, call it b
inClientFile >> quoted(b.title) >> quoted(b.author) >> quoted(tempPrice) >> quoted(tempqtyOnHand) >> quoted(tempqtySold) >> quoted(tempisbn) >> tempCost;
inClientFile.ignore();
b.price = stod(tempPrice);
b.qtyOnHand = stoi(tempqtyOnHand);
b.qtySold = stoi(tempqtySold);
b.cost = stod(tempCost);
out << b.title << ", " << b.author << ", " << b.price << ", " << b.qtyOnHand << ", " << b.qtySold << ", " << b.isbn << ", " << b.cost << ", " << b.calcRevenue(b.price, b.qtySold) << ", " << b.calcProfit(b.price, b.cost, b.qtySold) << endl;
books.push_back(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment