Answer to Question #197996 in C++ for Navkar

Question #197996

a class Customer: Private Members :Customer_no , Customer_name , OrderQty, Price, TotalPrice, Discount, Netprice . Member Functions are:

Public members: A constructer to assign initial values of Customer no , Customer name as , Order Quantity as (0) and Price, Discount, Netprice as (0.0) respectively. A Function Input( ) – to read data members (Customer_no, Customer_name, Quantity and Price) and call calDiscount() function. A function Show( ) –to display Customer details with values for all data members. Protected members: A function calDiscount( ) - to calculate Discount according to TotalPrice and to calculate value of NetPrice.

TotalPrice>=50000

Discount 25% of TotalPrice

TotalPrice>=25000 and TotalPrice<50000

Discount 15% of TotalPrice

TotalPrice<250000

Discount 10% of TotalPrice

Write a program for customer class and enter data for two customers one using constructor and other using input function display value of all data members for both objects.



1
Expert's answer
2021-05-24T18:02:38-0400
#include<bits/stdc++.h>
using namespace std;
class Customer
{
    int Customer_no , OrderQty;
    double Price, TotalPrice, Discount, Netprice;
    string Customer_name;
public:
    Customer()
    {
        Customer_no=0;
        OrderQty=0;
        Price=0.0;
        Discount=0.0;
        Netprice=0.0;
        TotalPrice=0;
        Customer_name="";
    }
    void Input()
    {
        cout<<"Enter Customer name : ";
        getline(cin,Customer_name);
        cout<<"Enter Customer number : ";
        cin>>Customer_no;
        cout<<"Enter quantity : ";
        cin>>OrderQty;
        cout<<"Enter Price : ";
        cin>>Price;
    }
    double calDiscount()
    {
        TotalPrice=OrderQty*Price;
        if(TotalPrice>=50000)
        {
            Discount=0.25*TotalPrice;
        }
        if(TotalPrice<50000 && TotalPrice>=25000)
        {
            Discount=0.15*TotalPrice;
        }
        if(TotalPrice<25000)
        {
            Discount=0.10*TotalPrice;
        }
        return Discount;
    }
    void Show()
    {
        TotalPrice=OrderQty*Price;
        Netprice=TotalPrice-calDiscount();
        cout<<"\nCustomer Name : "<<Customer_name;
        cout<<"\nCustomer Number : "<<Customer_no;
        cout<<"\nOrder quantity : "<<OrderQty;
        cout<<"\nPrice : "<<Price;
        cout<<"\nTotal Price : "<<TotalPrice;
        cout<<"\nDiscount : "<<calDiscount();
        cout<<"\nNet Price : "<<Netprice;
    }
};
int main()
{
    Customer c1,c2;
    c1.Show();
    c2.Input();
    c2.Show();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog