Tuesday, June 12, 2012

Assignment No. 03 Semester: Spring 2012CS201: Introduction to Programming


 #include <iostream.h>
#include <string.h>
#include <conio.h>
using namespace std;
class Customer
{
     public:
             Customer();
             Customer(string, int, int);
             void setName(string);
             void setCID(int);
             void setSpend(int);
             string getName();
             int getCID();
             int getSpend();
      private:
              string name;
              int id;
              int spending;
              friend void sum(Customer&);            
};
//-----------------------------------------------------------------------
Customer::Customer()
{
        name = "no name";
        id=0;
        spending=0;
}
Customer::Customer(string n, int id, int spend)
{
      name = n;
      this->id=id;
      spending=spend;
}
void Customer::setName(string n)
{
      name = n;
}
void Customer::setCID(int n)
{
     id = n;
}
void Customer::setSpend(int n)
{
     spending = n;
}
string Customer::getName()
{
       return name;
}
int Customer::getCID()
{
    return id;
}
int Customer::getSpend()
{
     return spending;
}
//-----------------------------------------------------------------------
void sum(Customer &cus)
{
     double tax=0,d=0,t=0;
     if(cus.spending < 5000)
     {
                     tax = cus.spending*.05;
                     d = cus.spending*.01;
     }
     else if(cus.spending > 5000 && cus.spending < 10000)
     {
                     tax = cus.spending*.10;
                     d = cus.spending*.02;
     }
     else if(cus.spending > 10000)
     {
                     tax = cus.spending*.15;
                     d = cus.spending*.03;
     }
     t = cus.spending+tax-d;
    
     cout<<"Customer Name :\t\t"<<cus.name<<endl;
     cout<<"ID :   \t\t\t"<<cus.id<<endl;
     cout<<"Spending :\t\t"<<cus.spending<<endl;
     cout<<"Total Bill :\t\t"<<t<<endl<<endl<<endl;
}


main()
{
      Customer *cus1 = new Customer();
      Customer *cus2 = new Customer("Ali", 112, 8550);
      Customer *cus3 = new Customer();
     
      cout<<"Bill detail for customer 1"<<endl;
      sum(*cus1);
      cout<<"Bill detail for customer 2"<<endl;
      sum(*cus2);
      char n[30];
      int i;
      int s;
      cout<<"Enter the name of customer 3 : ";
      cin>>n;
      cout<<"Enter the ID of the customer 3 : ";
      cin>>i;
      cout<<"Enter total spending of customer 3 : ";
      cin>>s;
      cus3->setName(n);
      cus3->setCID(i);
      cus3->setSpend(s);
     
      cout<<"\nBill detail for customer 3"<<endl;
      sum(*cus3);
getch();
}

No comments:

Post a Comment