Answer to Question #327399 in C++ for rav

Question #327399

A customer opens an account at a bank with an initial amount. The account number, name, and balance of the customer are generated. The customer can deposit money and withdraw money as per need, this will modify the existing account balance. It should also be checked if the demanded amount is available during withdrawal. The customer can also close the account, the available amount will be paid out. Write a programme to input and display data for 5 customers with the use of Constructor and Destructor


1
Expert's answer
2022-04-11T16:50:26-0400
#include <iostream>
#include <string>
#include<cstdlib>
#include<ctime>

using namespace std;

class Account
{
	int accNum;
	string name;
	float balance;
public:
	Account(){}
	Account(int _accNum, string _name, float _balance)
	:accNum(_accNum), name(_name), balance(_balance){}
	void Assign()
	{
		srand(static_cast<unsigned int>(time(0)));
		accNum = rand();
		cout << "Please, enter your name: ";
		cin >> name;
		cout<< "Please, enter your balance: ";
		cin >> balance;
	}
	void Deposit()
	{
		float value;
		cout << "\nPlease, enter a value to deposit: ";
		cin >> value;
		balance += value;
		
	}
	void Withdraw()
	{
		float x;
		cout << "Please, enter a value to withdraw: ";
		cin >> x;
		if (x > balance)
			cout << "This sum isn`t available";
		else
			balance -= x;
	}
	void Display()
	{
		cout << "\nYour Account number is " << accNum
			<< "\nYour Account name is " << name
			<< "\nYour balance is " << balance;
	}
	~Account() { cout << "\nAccount was closed"; }
};


void Menu()
{
	cout << "\n1 - Open Account"
		<< "\n2 - Deposit money"
		<< "\n3 - Withdraw money"
		<< "\n4 - Show info"
		<< "\n5 - Close Account and exit program";
	cout << "\nMake a choice:";
}
int main()
{
	char ch;
	Account a;
	do
	{
		Menu();
		cin >> ch;
		switch (ch)
		{
		case '1':
		{
			a.Assign();
			break;
		}
		case '2':
		{
			a.Deposit();
			break;
		}
		case '3':
		{
			a.Withdraw();
			break;
		}
		case '4':
		{
			a.Display();
			break;
		}
		}
	} while (ch != '5');
}


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