Consider the following class and answer questions after this class
#include using namespace std; class Account { public: Account(string accountName, int initialBalance) { name=accountName; if (initialBalance > 0) { balance = initialBalance; } } void deposit(int depositAmount) { if (depositAmount > 0) { balance = balance + depositAmount; } } int getBalance() const { return balance; } void setName(string accountName) { name = accountName; } string getName() const { return name; } private: string name; int balance;};a) Rewrite the above class. Write prototype of all functions inside class and definition outside.b) Write two friend functions to change the value of name and balance.c) Write a print function and use this pointer in the body.d) Consider the private data members are constant. Create a constructor which initializes the private members.
using namespace std;
class Account
{
public:
Account(string accountName, int initialBalance)
name=accountName;
if (initialBalance > 0) {
balance = initialBalance;
}
void deposit(int depositAmount) {
if (depositAmount > 0) {
balance = balance + depositAmount;
int getBalance() const {
return balance;
void setName(string accountName) {
name = accountName;
string getName() const {
return name;
private:
string name;
int balance;
};
a) Rewrite the above class. Write prototype of all functions inside class and definition outside.
b) Write two friend functions to change the value of name and balance.
c) Write a print function and use this pointer in the body.
d) Consider the private data members are constant. Create a constructor which initializes the private members.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here