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.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Consider the following class and answer questions after this class
#include <string> 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. |
Step by step
Solved in 5 steps