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

Question #173928

Create a class Account with the following members

protected data members:

integer accno,name as char array ,float balance

public member functions:

empty constructor- It initialize the accno as zero,name as "NIL" and balance as 0.

parameterized constructor-It initialize the class members using input parameters.

copy constructor-It is used to copy the content from one object(received as argument) to another object.

void display()-This function is used to display the details such as accno, name & balance which are separated by a space.

destructor- It display the string "object destruction,".

Main method:

Create an object A1 of type Account(it should call empty constructor).

Get three inputs from user such as accno, name & balance.

Create an object A2 of type Account and pass parameters to parameterized constructor. i.e. A2(accno,name,balance).

Create an object A3 and assign value of object A2 into A3 by using copy constructor.

Finally call display method for objects A1,A2,A3.


1
Expert's answer
2021-03-27T04:06:32-0400
#include <iostream>
using namespace std;
class Account
{
public:
	Account() {}
	Account(int ac, string nm, float bl)
		:accno(ac), name(nm), balance(bl)
	{}
	Account(Account &other):
	accno(other.accno), name(other.name),balance(other.balance)
	{}
    ~Account() 
	{
		std::cout << " object destruction"<<std::endl;
	}
	void display() 
	{
		cout << "accno " << accno<<" ";
		cout << "name " << name << " ";
		cout << "balance " << balance << endl;
     }	
protected:
	int accno{ 0 };
	string name{"NIL"};
	float balance{ 0 };	
};
int main()
{
	Account A1;
	int accno_user;
	float balance_user;
    string name_user;
	cout << "Enter accno:" << endl;
	cin >> accno_user;
	cout << "Enter name:" << endl;
	cin >> name_user;
	cout << "Enter balance:" << endl;
	cin >> balance_user;
	Account A2(accno_user, name_user, balance_user);
	Account A3(A2);
	A1.display();
	A2.display();
	A3.display();
}

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