Question

Write a C++ program to determine the cost of cell phone bill.

Write a C++ program to determine the cost of cell phone bill.
media%2F6b2%2F6b2fcebe-f4d7-46f3-a3c8-10
media%2F868%2F86858327-60a3-49c3-b762-75
0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.

The file CustomersA.txt you have given is a screenshot and i was not able to copy the contents. So i have picked the first three lines as a sample and tested the program. You create the original CustomersA.txt file and test the program.

Code:

#include <iostream>

#include <fstream>

using namespace std;

// function declaration

double calculateCost(int, int, int, int);

int main()

{

// file and variable declaration

ifstream infile("CustomersA.txt");

int lines, mins, texts, gb;

double cost;

// reading each line from file

if (infile.is_open()){

while(infile >> lines >> mins >> texts >> gb){

// passing the attributes to calculateCost to determine the total cost customer has to pay

cost = calculateCost(lines, mins, texts, gb);

cout << "Customer has to pay: " << cost << endl;

}

}

else

cout << "Some issue while file opening, plese check..." << endl;

cout << endl;

return 0;

}

double calculateCost(int lines, int mins, int texts, int gb)

{

double total_cost;

total_cost = 6 * lines; // line cost

total_cost += 0.02 * mins; // calls

total_cost += 0.25 * texts; // message cost

total_cost += 10 * gb; // Data cost

return total_cost;

}

Codee output screenshot:

sh-4.4$ cat CustomersA.txt 1 1362 1134 1 3 815 495 4 1 1137 606 3 sh-4.4$ g++ prog.cpp sh-4.4$ ./a.out Customer has to pay: 3

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to determine the cost of cell phone bill.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT