I can not run the code i need screen shot when i run the code . Using the MS Vis
ID: 3789134 • Letter: I
Question
I can not run the code i need screen shot when i run the code .
Using the MS Visual Studio IDE for C++, write a C++ code for the following, make proper use of const and references where necessary – you are expected to know where and when to use them. Code must compile and run correctly for any credit, there is no credit for code that does not compile
Part A: Classes and Objects
1. Create a class definition for an object called Account. Add a constructor and destructor to it.
2. Add 2 internal data member of char or string type which should be named firstName and lastName.
3. Then add two methods debitFrom which takes a double as a call parameter and creditTo which also takes a double data type.
4. Add an internal data member to the Account class called currentBalance of type double.
5. Instantiate an object of type Account with a starting balance of $100.00 belonging to a customer by the name of John Smith
6. Show how you would create constant members functions in this class – what is the benefit of such member functions.
Explanation / Answer
Below is a working example of class Accounts:
#include<iostream>
#include<string>
using namespace std;
class Account
{
string firstName,lastName;
double currentBalance;
public:
Account() //default constructor
{
currentBalance = 0;
}
Account(double a) //parametrized constructor
{
cout<<"Obj created ";
currentBalance = a;
}
double debitFrom(double a);
double creditTo(double a);
~Account() //destructor
{
cout<<"Object getting Destroyed ";
}
};
double Account::debitFrom(double a)
{
if(currentBalance-a > 0)
currentBalance -= a;
}
double Account::creditTo(double a)
{
currentBalance += a;
}
int main()
{
Account obj(100);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.