using namespace std; #include #include #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 { Discount = spending * 3 / 100; } return Discount; } double Customer :: getBill() //This function returns the total bill by adding the tax and subtracting the discount amounts { return (spending + getTax() - getDiscount()); } /*Definition of output stream overloading function Whenever << operator will be used with an object of class Customer, information about Customer's name, ID, spending, tax, discount and total bill will be displayed on output*/ ostream& operator << (ostream& output, Customer Cust) { output << endl << endl; output << "**************************Customer Billing Information ************************* " <> operator will be used with an object of class Customer, information about Customer's name, ID and spending will be taken from the user*/ istream& operator >> (istream& input, Customer& Cust) { cout << "Enter name of the customer : "; gets(Cust.name); 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(); }