Docsity

C++ Program for Customer Class with Overloaded Operators, Exercises of Applications of Computer Sciences

Toggle sidebar
bg1
using namespace std;
#include<iostream>
#include <conio.h>
#include <iomanip>
// 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;
}
docsity.com
pf3
pf4

Partial preview of the text

Download C++ Program for Customer Class with Overloaded Operators and more Exercises Applications of Computer Sciences in PDF only on Docsity!

using namespace std;

#include #include <conio.h> #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(); }