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;
}
#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;
}
Comments
Leave a comment