


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



/****************** Assignment No. 3 : Solution **********************/
using namespace std;
#include
// Definition of customer class class customer{
friend double calculateBill(customer*); // Declaration of Non-member friend function private: char name[30]; int custID; double spending; double tax; double discount;
public: customer(); //Default constructor customer(char[], int, double); //Parameterized constructor
/Setter and getter functions for the class/ void setName(char[]); void setID(int); void setSpending(double); char* getName(); int getID(); double getSpending();
};
// Default constructor Definition customer::customer() { strcpy(name, "No Name"); custID = 0; spending = tax = discount = 0;
}
// Parameterized constructor Definition customer :: customer(char Name[], int ID, double Spending) { strcpy(name, Name); custID = ID;
spending = Spending; tax = 0; discount = 0;
}
//Definition of setter and getter functions void customer :: setName(char Name[]) { strcpy(name, Name); }
void customer :: setID(int ID) { custID = ID; }
void customer :: setSpending(double Spending) { spending = Spending; }
char* customer :: getName() { return name; }
int customer :: getID() { return custID; }
double customer :: getSpending() { return spending; }
/* Defining friend function calculateBill which takes an object as parameter and calculates total bill after adding tax and subtracting discount from the bill*/ double calculateBill(customer *obj) { double bill = 0;
if(obj->spending <= 5000) //if the spending is less than 5000, then tax is 5% and discount is 1% { obj->tax = obj->spending * 5 / 100; obj->discount = obj->spending * 1 / 100; bill = obj->spending + obj->tax - obj->discount; }
customer *cus3 = new customer();
/The following code takes input in three ordinary variables and then these variables are passed to object pointed by the pointer cus3, through setter functions/ cout << "Enter name of customer 3 : "; cin >> NAME;
cout << "Enter ID of customer 3 : "; cin >> id;
cout << "Enter total spending of customer 3 : "; cin >> Spending;
cus3->setName(NAME); cus3->setID(id); cus3->setSpending(Spending); cout << endl;
//Showing the values of object pointed by the pointer cus3. cout << "Bill detail for customer 3, input entered by the user" <<endl; cout <<"Customer Name : " << cus3->getName() << endl << "ID : " << cus3-
getID() << endl << "Spending : " << cus3->getSpending() << endl << "Total Bill : " << calculateBill(cus3) << endl; cout << endl << endl;
getch();
}