Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
#include <fstream>
#include <istream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
class Book {
public:
string title, author, isbn;
double price, revenue, profit, cost;
int qtyOnHand, qtySold;
Book();
double calcRevenue(double price, int qtySold) { revenue = price * qtySold; return revenue; }
double calcProfit(double price, double cost, int qtySold) { profit = (price - cost) * qtySold; return profit; }
};
Book::Book(void){}
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) {
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;
//b.price = stod(tempPrice);
books.push_back(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment