Rewrite the following code in correct form.
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:
Q No 3. |
#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; };
Rewrite the following code in correct form.
a) Assume the following prototype of destructor is declared in class Time: void ~Time(int);
b) Assume the following prototype of constructor is declared in class Employee: int Employee(string, string);
c) The following is a definition of class Example:
class Example { public: Example(int y = 10) data(y) { } int getIncrementedData() const { return ++data; } static int getCount() { cout << "Data is " << data << endl; return count; } private: int data; static int count;}; |
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images