Banner Ad

    A    L    W    A    Y    S           D    E    S    I    R    E           T    O           L    E    A    R    N           S    O    M    E    T    H    I    N    G           U    S    E    F    U    L   

Monday, May 9, 2011

2010 Final IPE_UNIXC-1151a question 4

//customer.h

#include <iostream>
using namespace std;
#include <cstring>

class customer
{

private:
int customerno;
char name[20];
char address[50];
int monthlyunitsconsumed[3];
double monthlycost[3];
double averageunits;


public:
customer(int pcustomerno,char pname[],char paddress[]);
void monthlyunits();
void calculatemonthlycost();
void calculateaverageunits();
void displaycustomerdetails();



};

//customer.cpp

#include"customer.h"
#include <iostream>
using namespace std;
#include <cstring>


      customer::customer(int pcustomerno,char pname[],char paddress[])
      {
      customerno=pcustomerno;
      strcpy(name,pname);
      strcpy(address,paddress);

      }
void customer::monthlyunits()
      {
      for(int i=0;i<3;i++)
            {
            cout<<"Enter monthly units for month  "<<i+1<<"  ";
            cin>>monthlyunitsconsumed[i];
           
            }
      }
void customer::calculatemonthlycost()
{
      for(int i=0;i<3;i++)
      {
           
      if( monthlyunitsconsumed[i]<=30)
            {
      monthlycost[i]=10.50*monthlyunitsconsumed[i];
            }
              
        else if( monthlyunitsconsumed[i]<=90)
                  {
       monthlycost[i]=10.50*30+(monthlyunitsconsumed[i]-30)*20.75;
                }
             
      else if( monthlyunitsconsumed[i]>=90)
            {
      monthlycost[i]=10.50*30+60*20.75+(monthlyunitsconsumed[i]-90)*35;
                }

      }

}

void customer::calculateaverageunits()
{
     
   averageunits=(monthlyunitsconsumed[0]+monthlyunitsconsumed[1]+monthlyunitsconsumed[2])/2.0;


}

void customer::displaycustomerdetails()
{

cout<<"customer no   :"<<customerno<<endl;
cout<<"customer name :"<<name<<endl;
cout<<"Address       :"<<address<<endl<<endl;
cout<<"\t\tmonth 1    month 2     month 3"<<endl;
cout<<"units consumed        "<<monthlyunitsconsumed[0]<<"\t"<<monthlyunitsconsumed[1]<<"\t"<<monthlyunitsconsumed[2]<<endl;
cout<<"Monthly cost is       "<<monthlycost[0]<<"\t"<<monthlycost[1]<<"\t"<<monthlycost[2]<<endl;
cout<<"monthly average usage is  =  "<<averageunits<<endl;

}
//paperla_4.cpp
#include "customer.h"
#include <iostream>
using namespace std;
int main()
{

      customer c1(101,"Nimal Perera","41,Gall Road,Bambalapitiya.");
      c1.monthlyunits();
      c1.calculatemonthlycost();
      c1.calculateaverageunits();
      c1.displaycustomerdetails();






      return 0;

}

0 comments:

Related Posts Plugin for WordPress, Blogger...

your comments