Answer to Question #173923 in C++ for Vimal D

Question #173923

create a class Customer with the following members:

Member variables: cid(integers) and cbalance (float).

Member functions:

Default(empty) constructor: It assigns cid and cbalance value as zero(0). Finally it print "Default Assignment".

Parameterized constructor: It receives two arguments and assign it to cid and cbalance.

void display(): This method display the values of cid and cbalance which are separated by a space.

Main method:

Implement the below code in main method and check your program output.

int main()

{

int cid;

float cbalance;

cin>>cid>>cbalance;

Customer obj1;

Customer obj2(cid,cbalance);

obj1.display();cout<<endl;

obj2.display();

return 0;

}


1
Expert's answer
2021-03-22T20:07:14-0400
#include <iostream>

using namespace std;


class Customer
{
private:
    int cid;
    float cbalance;


public:
    Customer()
    {
        this->cid = 0;
        this->cbalance = 0;


        cout << "Default Assignment" << endl;
    }
    Customer(int cid, float cbalance)
    {
        this->cid = cid;
        this->cbalance = cbalance;
    }


    void display()
    {
        cout << cid << " " << cbalance << endl;
    }
};


int main()
{


    int cid;


    float cbalance;


    cin>>cid>>cbalance;


    Customer obj1;


    Customer obj2(cid,cbalance);


    obj1.display();cout<<endl;


    obj2.display();


    return 0;


}

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
APPROVED BY CLIENTS