Problem is in C++ Write a program that computes the phone bills for a list of cu
ID: 3743640 • Letter: P
Question
Problem is in C++ Write a program that computes the phone bills for a list of customers from a file. Write a report of the bill to an output file. Your bill is based on the number of hours of phone use, along with your package. Here are the different packages: -------------------------------------------------------------------------- Basic package: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour. Gold package: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour. Platinum package: For $19.95 per month unlimited access is provided. -------------------------------------------------------------------------- Write a program that reads from a file called "customers.txt". The first line of the file will be a number stating how many customers are listed in the file. Each subsequent line will consist of a name, followed by a package type, followed by a number of phone hours used by that customer. Here is an example: 5 Schweller gold 19 Garret platinum 59 Kolter platinum 12 Schwarzeneger basic 237 Hansen gold 23 As output, write to a file “billing.txt” a list of each customer followed by their total bill for the month. For the above file, the corresponding output file should contain: Schweller $14.95 Garret $19.95 Kolter $19.95 Schwarzeneger $463.95 Hansen $17.95
Explanation / Answer
#include #include #include #include using namespace std; double calculate_bill(string plan, int hours) { if(plan == "gold") { if(hours > 20) { return 14.95 + (hours-20)*1; } else { return 14.95; } } else if(plan == "platinum") { return 19.95; } else { if(hours > 10) { return 9.95 + (hours-10)*2; } else { return 9.95; } } } int main() { ifstream in("customers.txt"); if(in.is_open()) { string name, plan; int hours; int n; ofstream out("billing.txt"); out > plan >> hours; outRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.