私は簡単な移植可能なC++プログラムBilling_Unitを開発する必要があります。 いくつかのパラメータ(電信電話番号など)を読み込み、通話料金と残りの分を返します。プロジェクトの組織の最良の方法は何ですか?
私はstandart入力からBilling_Unitのデータを取得し、結果をstandart出力に出力することにしました。
私はTest_Unit_SourceとTest_Unit_Destinationという2つのテストユニットを開発しました。
は、私は私のプログラム単位の連続したパフォーマンスを整理することにしました:
- Test_Unit_Sourceを:データベースからデータを読み込み、 スタンダール出力にそれを置きます。
- Billing_Unit:前のユニット からスタンドアット出力を読み込み、残りのコールのコストを計算して、残りの分を 分計算し、結果を出力します。
Test_Unit_Destination: コストと残りの空き分を読み取り、データベースに保存します。
Test_Unit_Source | Billing_Unit | Test_Unit_Destination
簡体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) return ERROR_RESULT;
do {
buf=inp_file.get();
cout<<buf;
} while (!inp_file.eof());
return SUCCESS_RESULT;
}
簡体Billing_Unit - それはポータブルにする必要があります
#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;
return SUCCESS_RESULT;
}
簡体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) return ERROR_RESULT;
while (!EOF_USERS) {
cin >> buf;
out_file << buf;
}
return SUCCESS_RESULT;
}
実際には、Test_Unit_SourceとTest_Unit_Destinationを1つのプログラム単位にまとめることができます。それは私の決定にかかっています。
私のプロジェクトの良い組織ですか? このプロジェクトの最高の組織は何ですか?コマンドラインからBilling_Unitの入力パラメータを設定する方が良いかもしれませんが、この場合は結果を返す方法がわかりません。
コマンドライン引数については、 'int main(int argc、char * argv [])'を試してください。入力を求める前に、存在しないかどうかを確認することができます。 – chris
機能テスト(ユニットテストではない)のように見えます –
chris、はい、あなたはかなり正しいです。コマンドラインから入力データを取得する方法はわかっていますが、結果を返す方法はわかりません。コンパイラはint型だけを返すように求めています。 –