In: Computer Science
Write a program to compute internet charges according to a rate schedule.
The rate schedule is as follows:
$0.08 per GB for usage between 0 and 40 GB, inclusive
$0.07 per GB for usage between 41 GB and 70 GB, inclusive
$0.05 per GB for usage between 71 GB and 110 GB, inclusive
$0.04 per GB for usage greater than 110 GB
Learning Objectives
In this assignment, you will:
Requirements
Your code must use these four functions, using these names (in addition to main):
Requirements for the getData Function
| 
 Purpose:  | 
 This function prompts the user for an account number (integer) and a GB value (integer). It passes these values back to main via two output parameters.  | 
| 
 Output Parameters:  | 
  | 
| 
 Algorithm:  | 
 Prompt and read. There must be only one prompt, and the user must enter the data on one line with a space between each value.  | 
| 
 Return value:  | 
 None  | 
Requirements for the computeCharges Function
| 
 Purpose:  | 
 This function computes the charges for one transaction. It uses one input parameter (GB value as an integer) and a return value (amount of the charge, which may include decimals).  | 
| 
 Input Parameter:  | 
  | 
| 
 Algorithm:  | 
 Use a selection structure to determine the charge per GB, using the above rate schedule. Calculate the charges using multiplication.  | 
| 
 Return value:  | 
 Transaction charges (may include decimals)  | 
Requirements for the printAccountInfo Function
| 
 Purpose:  | 
 This function displays the information for one account transaction to the screen.  | 
| 
 Input Parameters:  | 
  | 
| 
 Algorithm:  | 
 Print, using appropriate spacing and formatting. The transaction charges must display with two decimal places.  | 
| 
 Return value:  | 
 None  | 
Requirements for the printTotals Function
| 
 Purpose:  | 
 This function displays totals to the screen at the end of the program.  | 
| 
 Input Parameters:  | 
  | 
| 
 Algorithm:  | 
 Print, using appropriate spacing and formatting. The sum of transaction charges must display with two decimal places.  | 
| 
 Return value:  | 
 None  | 
Requirements for main:
Be sure the first prompt is for actual data, not the continuation response.
IMPORTANT NOTE ABOUT THIS LOOP – You will encounter the situation where there is a scanf for a number immediately before the scanf for the Y or N. We have seen this problem before…
Sample Run
Enter account number and GB used (one space between data): 12345
80
Account number: 12345        GB
Used:    
80       
Charge:     4.00
Do you wish to continue? (y/n) y
Enter account number and GB used (one space between data): 98765
25
Account number: 98765        GB
Used:    
25       
Charge:     2.00
Do you wish to continue? (y/n) Y
Enter account number and GB used (one space between data): 25413
120
Account number: 25413        GB
Used:   
120       
Charge:     4.80
Do you wish to continue? (y/n) Y
Enter account number and GB used (one space between data): 42598
50
Account number: 42598        GB
Used:    
50       
Charge:     3.50
Do you wish to continue? (y/n) n
Total accounts =       
4
Total GB Used =       275
Total Charges =     14.30
In case of any queries,please comment. I would be very happy to
assist all your queries.Please give a Thumps up if you like the
answer.
Program
#include<stdio.h>
void getData(int *acct_num,int *gb);
void printAccountInfo(int *acct_num,int *gb,float *t_charge);
float computeCharges(int *gb);
void printTotals(int *num_accounts,int *total_gb,float
*total_charge);
int main()
{
   int acct_num,gb,total_gb=0,num_accounts=0;
   float t_charge,total_charge=0;
   char ch;
   do
   {
   getData(&acct_num,&gb);
   total_gb=gb+total_gb;
   num_accounts++;
   t_charge=computeCharges(&gb);
   total_charge+=t_charge;
  
printAccountInfo(&acct_num,&gb,&t_charge);
   printf ("Do you want to continue: y/n ");
   scanf (" %c", &ch);
   } while(ch == 'y' || ch == 'Y');
  
printTotals(&num_accounts,&total_gb,&total_charge);
   return 0;
}
void getData(int *acct_num,int *gb)
{
   printf("Enter account number and GB used (one space
between data): ");
   scanf("%d%d",acct_num,gb);
}
void printAccountInfo(int *acct_num,int *gb,float
*t_charge)
{
   printf("Account number: %8d\tGB
Used:%8d\tCharge:%8.2f\n",*acct_num,*gb,*t_charge);
}
float computeCharges(int *gb)
{
   float charge;
   if(*gb<=40 && *gb>=0)
       charge=*gb*.08;
   else if(*gb<=70 && *gb>=41)
       charge=*gb*.07;
   else if(*gb<=110 && *gb>=71)
       charge=*gb*.05;
   else if(*gb>110)
       charge=*gb*.04;
   return charge;
}
void printTotals(int *num_accounts,int *total_gb,float
*total_charge)
{
   printf("Total accounts =%8d\n",*num_accounts);
   printf("Total GB Used =%8d\n",*total_gb);
   printf("Total Charges =%8.2f\n",*total_charge);
}
Output
Enter account number and GB used (one space between data): 12345
80
Account number: 12345   GB Used: 80   Charge:
4.00
Do you want to continue: y/n y
Enter account number and GB used (one space between data): 98765
25
Account number: 98765   GB Used: 25   Charge:
2.00
Do you want to continue: y/n Y
Enter account number and GB used (one space between data): 25413
120
Account number: 25413   GB Used: 120   Charge:
4.80
Do you want to continue: y/n Y
Enter account number and GB used (one space between data): 42598
50
Account number: 42598   GB Used: 50   Charge:
3.50
Do you want to continue: y/n n
Total accounts = 4
Total GB Used = 275
Total Charges = 14.30