Write a program that stores the bundle options illustrated in this week’s lesson
ID: 3820907 • Letter: W
Question
Write a program that stores the bundle options illustrated in this week’s lesson:
struct customerBundles
{
string name;
double internet;
double voice;
double television;
};
The program should keep an array of 10 of these structures, each element is for a different customer’s bundle options. When the program runs, it should ask the user to enter the data for each customer. It should pass the struct to a function to display in a table a list of each customer’s name, cost of each option and their total monthly bill (total of the three options). If you would like to keep things simple on the input of the values, have a set price for each option (const TV = 29.99, const VOICE = 29.99, and INTERNET = 29.99) and just ask the user which options the customer has along with their name. Validate your input.
Explanation / Answer
Here is the code for you:
#include <iostream>
using namespace std;
const double TV = 29.99;
const double VOICE = 29.99;
const double INTERNET = 29.99;
struct customerBundles
{
string name;
double internet;
double voice;
double television;
};
void displayCustomerBills(customerBundles customers[])
{
double total = 0;
for(int i = 0; i < 10; i++)
{
total = 0;
cout << "Customer # " << i+1 << ":" << endl;
if(customers[i].internet != 0)
{
cout << " internet: " << INTERNET << endl;
total += INTERNET;
}
if(customers[i].voice != 0)
{
cout << " Voice: " << VOICE << endl;
total += VOICE;
}
if(customers[i].television != 0)
{
cout << " TV: " << TV << endl;
total += TV;
}
cout << " Total Bill: " << total << endl;
}
}
int main()
{
//The program should keep an array of 10 of these structures, each element is for a
//different customer’s bundle options.
customerBundles customers[10];
char choice;
//When the program runs, it should ask the user to enter the data for each customer.
for(int i = 0; i < 3; i++)
{
customers[i].internet = customers[i].voice = customers[i].television = 0;
cout << "Enter the name for customer #" << i+1 << ": ";
cin >> customers[i].name;
cout << "internet package costs " << INTERNET << ". Do you want to add it (Y/N): ";
cin >> choice;
if(choice == 'Y')
customers[i].internet = INTERNET;
cout << "Voice package costs " << VOICE << ". Do you want to add it (Y/N): ";
cin >> choice;
if(choice == 'Y')
customers[i].voice = VOICE;
cout << "Television package costs " << TV << ". Do you want to add it (Y/N): ";
cin >> choice;
if(choice == 'Y')
customers[i].television = TV;
}
//It should pass the struct to a function to display in a table a list of each customer’s
//name, cost of each option and their total monthly bill (total of the three options).
displayCustomerBills(customers);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.