forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// ex8_07.cpp | ||
// Exercise 8.7 | ||
// | ||
// Created by pezy on 11/28/14. | ||
// Copyright (c) 2014 pezy. All rights reserved. | ||
// | ||
// @Brief Revise the bookstore program from the previous section to write its output to a file. | ||
// Pass the name of that file as a second argument to main. | ||
// @See ex8_06.cpp | ||
// @Run give a parameter: "../data/book.txt ../data/out.txt" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include "../ch07/ex7_26.h" | ||
using std::ifstream; using std::ofstream; using std::endl; using std::cerr; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
ifstream input(argv[1]); | ||
ofstream output(argv[2]); | ||
|
||
Sales_data total; | ||
if (read(input, total)) | ||
{ | ||
Sales_data trans; | ||
while (read(input, trans)) | ||
{ | ||
if (total.isbn() == trans.isbn()) | ||
total.combine(trans); | ||
else | ||
{ | ||
print(output, total) << endl; | ||
total = trans; | ||
} | ||
} | ||
print(output, total) << endl; | ||
} | ||
else | ||
{ | ||
cerr << "No data?!" << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// ex8_08.cpp | ||
// Exercise 8.8 | ||
// | ||
// Created by pezy on 11/28/14. | ||
// Copyright (c) 2014 pezy. All rights reserved. | ||
// | ||
// @Brief Revise the program from the previous exercise to append its output to its given file. | ||
// Run the program on the same output file at least twice to ensure that the data are preserved | ||
// @See ex8_07.cpp | ||
// @Run give a parameter: "../data/book.txt ../data/out.txt" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include "../ch07/ex7_26.h" | ||
using std::ifstream; using std::ofstream; using std::endl; using std::cerr; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
ifstream input(argv[1]); | ||
ofstream output(argv[2], ofstream::app); | ||
|
||
Sales_data total; | ||
if (read(input, total)) | ||
{ | ||
Sales_data trans; | ||
while (read(input, trans)) | ||
{ | ||
if (total.isbn() == trans.isbn()) | ||
total.combine(trans); | ||
else | ||
{ | ||
print(output, total) << endl; | ||
total = trans; | ||
} | ||
} | ||
print(output, total) << endl; | ||
} | ||
else | ||
{ | ||
cerr << "No data?!" << endl; | ||
} | ||
|
||
return 0; | ||
} |