Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include<fstream>
  2. #include<iomanip>
  3. #include<string>
  4. #include<iostream>
  5. using namespace std;
  6. void claculateMonthlyCharges(string ID, int numOfText, bool &, double & );
  7. int main() {
  8. bool goodData=0;
  9. string ID;
  10. int numOfText;
  11. double monthlyCharges = 0;
  12. ifstream inFile;
  13. ofstream outFile;
  14. inFile.open("Temp.txt");
  15. outFile.open("output.txt");
  16. if (!inFile) {cout << "can not open the file\n";
  17. system("pause");
  18. return 0;}
  19. outFile << "customer" << "\t" << "Messages" << "\t" << "Monthly Charges\n";
  20. while(!inFile.eof()) {
  21. inFile >> ID >> numOfText;
  22. claculateMonthlyCharges(ID, numOfText, goodData, monthlyCharges);
  23. if (goodData == false) {
  24. outFile << ID << "\t\t" << numOfText << "\t\t" << "Bad data\n";}
  25. else {outFile << fixed << showpoint << setprecision(2);
  26. outFile << ID << "\t\t" << numOfText << "\t\t" << monthlyCharges << endl;}}
  27. inFile.close();
  28. outFile.close();
  29. system("pause");
  30. return 0;}
  31. void claculateMonthlyCharges(string ID, int numOfText,bool & goodData,double & monthlyCharges){
  32. if (numOfText<0 || numOfText>300 ) {goodData = false;}
  33. else {goodData = true;
  34. double overSixtyCharges;
  35. if (numOfText <= 60) {
  36. overSixtyCharges = 0;}
  37. else {overSixtyCharges = (numOfText - 60)*0.05;}
  38. int basic = 5;
  39. double tax = (basic + overSixtyCharges)*0.12;
  40. monthlyCharges = basic + overSixtyCharges + tax;}}
  41. /*
  42. customer    Messages    Monthly Charges
  43. AAA     45      5.60
  44. BBB     200     13.44
  45. CCC     -10     Bad data
  46. DDD     0       5.60
  47. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement