Answer to Question #172739 in C++ for Panjumin

Question #172739

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-22T01:59:09-0400
#include <iostream>
using namespace std;

class Customer {
	int cid;
	float cbalance;
public:
	Customer() : cid(0), cbalance(0) { cout << "Default Assignment" << endl; };
	Customer(int cid, float cbalance) : cid(cid), cbalance(cbalance) {};
	void display() {
		cout << cid << " " << cbalance;
	}
};


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