Answer to Question #174170 in C++ for V.Karthickraja

Question #174170

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-24T01:56:17-0400
#include <iostream>
 
using namespace std;
 
class Customer {
public:
// Default constructor
  Customer(){
    cid = 0;
    cbalance = 0;
    cout << "Default Assignment" << endl;
 }
 
// Parameterized constructor
  Customer(int id, float balance){
    cid = id;
    cbalance = balance;
 }
  void display(){
    cout<<cid<<" "<<cbalance;          
}
 
private:
    int cid;
    float 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