


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!



using namespace std;
#include
// Definition of Customer class class Customer{
friend ostream& operator << (ostream& ,Customer); // Decarlation of output stream overloading function friend istream& operator >> (istream& ,Customer&); // Decarlation of output stream overloading 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/
char* getName(); int getID(); double getSpending(); double getTax(); double getDiscount(); double getBill(); };
// Default constructor Definition Customer::Customer() { strcpy(name, "No Name"); custID = 0; spending = tax = discount = 0; }
char* Customer :: getName() // getName() returns the name of the Customer { return name; }
int Customer :: getID() // Returns ID of the Customer { return custID; }
double Customer :: getSpending() // returns spending by the Customer { return spending; }
double Customer :: getTax() // getTax() returns the tax based on spending by Customer { double Tax;
if(spending <= 5000) { Tax = spending * 5 / 100; }
if(spending > 5000 && spending <=10000) { Tax = spending * 10 / 100; }
else { Tax = spending * 15 / 100; }
return Tax; }
double Customer :: getDiscount() // This function returns total discount on spending { double Discount; if(spending <= 5000) { Discount = spending * 1 / 100; }
if(spending > 5000 && spending <=10000) { Discount = spending * 2 / 100; }
else
cout << "Enter ID of the customer : "; cin >> Cust.custID; cout << "Enter total spending by customer : "; cin >> Cust.spending; return input;
}
main() { Customer obj; //createing an object of Customer class cin >> obj; // Overloaded input stream operator >> is called here cout << obj; // Overloaded output stream operator << is called here
getch(); }