loading...

CS201 Introduction to Programming Assignment No. 02 Fall 2012

Assignment 
Problem Statement: Pakistan Electric Supply Company (PESCO) supplies electricity for domestic and commercial usage all over Pakistan.
You are required to write a program for calculating the amount of bill paid by the customer for both domestic and commercial usage. User will enter customer number and amount of units consumed, and the program will calculate the amount of bill accordingly.


Detailed Description:
  • The program should take customer type as input which must be ‘1’ or ‘2’and the number of units consumed.
  • If the user enters ‘1’ then he/she is a domestic user.
  • If the user enters ‘2’ then he/she is a commercial user.
  • If user enters any other number except 1 or 2, the program should terminate after displaying a message “Invalid choice”.
  • After taking valid customer type from user, program should ask user to enter the customer number, number of consumed units and number of days.
  • For domestic customer, if the units consumed are between 0 and 100, the price isRs.5 per unit and there will be no extra charges.
  • If the units consumed are between 101 and 300, the price is

Rs.8 per unit plus Rs.100 as extra charges.

  • If the units consumed are between 301 and 500, the price is

Rs.10 per unit plus Rs.230 as extra charges.

  • For commercial customers, the price is Rs.15 per unit, which is uniform for any number of units.
  • If user deposits bill within 10 days, he/she will not be incurred for any extra charges.
  • If user deposits bill after 10 days, he/she will be charges for Rs. 200 as extra charges.
  • You are required to write 2 functions. One for calculating the bill for domestic customer, and 2nd to calculate the bill for commercial customer.
  • Use switch structure to determine the customer type. Then pass the customer number, consumed units and number of days to the corresponding function as arguments.
  • These functions will calculate and return the total bill for the customer.

NOTE:
The sample output is attached with this assignment named Assignment2.gif.
Solution:
#include <iostream.h>
float dom_user(int,int,int);
float com_user(int,int,int);
main()
{
      int typ;
      int unit;
      int cus_nub;
      int days;
      cout<<"1-----------Domectice User:n";
      cout<<"2-----------Commercial User:n";
      cout<<"Please Choose your choice From the Above menu:";
      cin>> typ;
      while(typ<1000)
      {
      cout<<"Please enter the customer number:";
      cin>>cus_nub;
      cout<<"Please enter unit consumed:";
      cin>>unit;
      cout<<"Please enter number of days:";
      cin>>days;

      switch(typ)
      {
             case 1:
                  dom_user(cus_nub,unit,days);
                  break;

             case 2:
                  com_user(cus_nub,unit,days);
                  break;

             default:
                     cout<<"invalid entryn";
      }
      system("pause");
      }
}
float dom_user(int cus_nub,int unit,int days)
{
      float bill;
      if(unit<101)
                  {
                              bill=unit * 5;
                  }
                  else if(unit>101 && unit<301)
                  {
                       bill = ((unit*8)+100);
                  }
                  else if(unit>301 && unit<501)
                  {
                       bill = ((unit * 10) + 230);
                  }
                  cout<<" Amount to be paid by te custoer No."<<cus_nub<<"is" <<bill<<"n";
}
float com_user(int cus_nub,int unit,int days)
{
      float bill;
      bill = unit*15;
                  if(days>10)
                  {
                             bill = bill +200;
                  }
                  cout<<" Amount to be paid by te custoer No."<<cus_nub<<"is" <<bill<<"n";
}
DOWNLOAD SOLUTION HERE
loading...