forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex8_06.cpp
47 lines (42 loc) · 1.11 KB
/
ex8_06.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// ex8_06.cpp
// Exercise 8.6
//
// Created by pezy on 11/27/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Rewrite the bookstore program from ¡ì7.1.1 (p.256) to read its transactions from a file.
// Pass the name of the file as an argument to main (¡ì6.2.5, p.218).
// @See ex7_26.h (use the Sales_data)
// @Run give a parameter: "../data/book.txt"
// @Output 0-201-78345-X 5 110
// 0-201-78346-X 9 839.2
#include <fstream>
#include <iostream>
#include "../ch07/ex7_26.h"
using std::ifstream; using std::cout; using std::endl; using std::cerr;
int main(int argc, char **argv)
{
ifstream input(argv[1]);
Sales_data total;
if (read(input, total))
{
Sales_data trans;
while (read(input, trans))
{
if (total.isbn() == trans.isbn())
total.combine(trans);
else
{
print(cout, total) << endl;
total = trans;
}
}
print(cout, total) << endl;
}
else
{
cerr << "No data?!" << endl;
}
return 0;
}