Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<iomanip>
- #include<string>
- #include<iostream>
- using namespace std;
- void claculateMonthlyCharges(string ID, int numOfText, bool &, double & );
- int main() {
- bool goodData=0;
- string ID;
- int numOfText;
- double monthlyCharges = 0;
- ifstream inFile;
- ofstream outFile;
- inFile.open("Temp.txt");
- outFile.open("output.txt");
- if (!inFile) {cout << "can not open the file\n";
- system("pause");
- return 0;}
- outFile << "customer" << "\t" << "Messages" << "\t" << "Monthly Charges\n";
- while(!inFile.eof()) {
- inFile >> ID >> numOfText;
- claculateMonthlyCharges(ID, numOfText, goodData, monthlyCharges);
- if (goodData == false) {
- outFile << ID << "\t\t" << numOfText << "\t\t" << "Bad data\n";}
- else {outFile << fixed << showpoint << setprecision(2);
- outFile << ID << "\t\t" << numOfText << "\t\t" << monthlyCharges << endl;}}
- inFile.close();
- outFile.close();
- system("pause");
- return 0;}
- void claculateMonthlyCharges(string ID, int numOfText,bool & goodData,double & monthlyCharges){
- if (numOfText<0 || numOfText>300 ) {goodData = false;}
- else {goodData = true;
- double overSixtyCharges;
- if (numOfText <= 60) {
- overSixtyCharges = 0;}
- else {overSixtyCharges = (numOfText - 60)*0.05;}
- int basic = 5;
- double tax = (basic + overSixtyCharges)*0.12;
- monthlyCharges = basic + overSixtyCharges + tax;}}
- /*
- customer Messages Monthly Charges
- AAA 45 5.60
- BBB 200 13.44
- CCC -10 Bad data
- DDD 0 5.60
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement