CS201 Assignment No. 3 Spring 2012 solution

You are required to write a program for calculating the bill of a customer according to the amount spent on shopping. A customer will be an object of a class. Each object has a name, customer ID and amount spent on shopping, as its data members. You will calculate the total bill by adding tax in the spending and subtracting discount offered according to spending.

Detailed Description:

  • You are required to create a class named Customer.
  • It will have name, customer-ID and spending as its private data members.
  • You have to make two constructors for this class, i.e. default constructor and parameterized constructor.
  • Default constructor will initialize the name with “No name”, customer-id with “0” and spending with “0”;
  • Parameterized constructor will take three arguments i.e. name, customer-id and spending.
  • Create getter and setter functions for each data member of the class.
  • A friend function will calculate the total bill for each object of class Customer, passed to it as argument.
  • If total spending is less than 5000, then tax added on total spending is 5% and discount is 1%. If spending is more than 5000 and less than 10,000 then 10% tax and discount is 2% and if spending is more than 10,000 then 15% tax and 3% discount is applicable.
  • Remember that all this calculation will be done inside friend function.
  • In the main() function, create three customer type objects by using new operator. Initialize first object with default constructor, second with parameterized and take input from user for third object (use setter functions to set third object’s values taken from the user).
  • Calculate total bill for all three objects by passing them to friend function and then display the result of calculation as shown in example output.

Solution:

#include <iostream.h>
#include <stdlib.h>
class Customer
{
public:
void display();
void setName(int i);
void setCustomer_id(int i);
void setSpending(int i);

int getName();
int getCustomer_id();
int getSpending();

Customer();
Customer(int, int , int);
// Customer(int, int, int);
~Customer ();

 

 

private:
int FnlBill;
int customer_id;
int spending;
int name;
friend float dis1FnlBill ( Customer ) ;
friend float dis2FnlBill ( Customer ) ;
friend float dis3FnlBill ( Customer ) ;
};
Customer::Customer()
{
name= 0;
customer_id = 0;
spending = 0;
}

Customer::Customer(int thename, int thecustomer_id , int thespending)
{
name = thename;
customer_id = thecustomer_id;
spending = thespending;

}
Customer::~Customer()
{
}
void Customer::display()
{
cout getName() getCustomer_id() getSpending();
}
void Customer::setName(int i)
{
name = i ;
}
void Customer::setCustomer_id(int i)
{
customer_id = i;
}
void Customer::setSpending(int i)
{
spending = i;
}

int Customer::getName()
{
return name;
}
int Customer::getCustomer_id()
{
return customer_id;
}
int Customer::getSpending()
{
return spending;
}
void FnlBill(Customer *d, int )
{
// d->FnlBill ; // Modify private data
}

int main()
{

Customer Bill1, Bill2(1,2,3), Bill3(4,5,6); // taking objects of Date class
Bill1.display();
Customer *aptr;
aptr = new Customer [1];
delete [] aptr;
Bill2.display();
Customer *bptr;
bptr = new Customer [1];
delete [] bptr;
int name;
int customer_id;
int spending;
cout “Enter Customer Name” endl;
cin >> name ;
cout “Enter Customer customer_id” endl;
cin >> customer_id ;
cout “Enter Customer spendings” endl;
cin >> spending ;
Bill3.display();
Customer *cptr;
cptr = new Customer [1];
delete [] cptr;
/*float spend,;
cout “Please enter total spendings ” ;
endl;
cin >> spend;
if ( spend < 5000 )
{
cout “The Bill is : ” dis1FnlBill(Bill3(4,5,6)) endl;
}
else if (spend => 5000 && < 10000)
{
cout “The Bill is : ” dis2FnlBill(Bill3(4,5,6)) endl;
}
else if ( spend => 10000 )
{
cout “The Bill is : ” dis3FnlBill(Bill3(4,5,6)) endl;
}
else
{
cout “Pleae epend some thing” endl;
}
Customer *cptr; // Declared a pointer dptr to MyPointer class object
cptr = new Customer [1]; // Created 10 objects of MyDate and assigned the
// pointer to the first object to dptr pointer variable.
delete [] cptr; // Deleted (freed) the assigned memory to the objects
//display();*/
system (“pause”);
}
/*
float dis1FnlBill ( Bill3(4,5,6))
{
return ( (spend+(5/spend*100))-(1/spend*100)); // Addition of tax
}
float dis2FnlBill ( Bill3(4,5,6))
{
return ( (spend+(10/spend*100))-(2/spend*100)); // Addition of tax
}
float dis3FnlBill ( Bill3(4,5,6))
{
return ( (spend+(15/spend*100))-(3/spend*100)); // Addition of tax
}
*/

DOWNLOAD SOLUTION HERE
loading...
  • Mubeenamin

    ye 2nd assignment ka solution upload kiya hoa hai kya ho gya hai admin????????????

  • Correct Solution has been Shared.