c++ - What is the best way of project's organization? -



c++ - What is the best way of project's organization? -

i need develop simple portable c++ programme billing_unit. reads parameters (telefone number, etc.) , returns cost of phone call , rest of free minutes.

i decided info billing_unit standart input, , output result standart output.

i developed 2 test units: test_unit_source , test_unit_destination.

i decided organize consecutive performing of programme units:

test_unit_source: reads info database , puts standart output; billing_unit: reads standart output previous unit, calculates phone call costs , rest of free minutes, outputs result.

test_unit_destination: reads phone call costs , rest of free minutes, stores database.

test_unit_source | billing_unit | test_unit_destination

simplified test_unit_source:

#include <stdio.h> #include <iostream> #include <fstream> #include <string> #define success_result 0 #define error_result 1 using namespace std; int main() { signed char buf; string name_file; ifstream inp_file; inp_file.open("temp.txt",std::ios::binary); if (!inp_file) homecoming error_result; { buf=inp_file.get(); cout<<buf; } while (!inp_file.eof()); homecoming success_result; }

simplified billing_unit - it must portable:

#include <iostream> #define success_result 0 #define error_result 1 int main() { signed char var; unsigned long res;//cents signed char next_call; while (!eof_users) { std::cin >> input_data; ... //calculations ... std::cout << result; } std::cout << eof_users; homecoming success_result; }

simplified test_unit_destination:

#include <stdio.h> #include <iostream> #include <fstream> #include <string> #define success_result 0 #define error_result 1 using namespace std; int main() { signed char buf; ofstream out_file; out_file.open("out.txt",std::ios::binary); if (!out_file) homecoming error_result; while (!eof_users) { cin >> buf; out_file << buf; } homecoming success_result; }

actually test_unit_source , test_unit_destination can united in 1 programme unit. depends on decision.

is organization of project? best organization of project? may it's improve set input parameters billing_unit through command line, don't know how homecoming result in case.

your design fits model of unix-like languages: writing programme filter reads stdin , writes stdout you're giving users flexibility pre- or post-process data.

for example, you've written it, can run

billing_unit < input_file > output_file

but suppose input info in wrong format. can run

reformat_data < input_file | billing_unit > output_file

and can alter output format with

billing_unit < input_file | sort_by_customer > output file

these simple examples, hope show how easy work programme yours.

if plan run programme straight shell this, sure error messages written stderr instead of stdout. separate them output data, won't processed input next command.

c++ c pipe project-organization

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -