Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Step 2: Enter, save, compile and execute the following program in MSVS. Call the

ID: 3681519 • Letter: S

Question

Step 2: Enter, save, compile and execute the following program in MSVS. Call the new project “IntroClassesExp2” and the program “IntroClasses2.cpp”.    Answer the questions below:

#include <iostream>

using namespace std;

class Bank_Transaction

{

public:

      Bank_Transaction( ); //default constructor

      Bank_Transaction(double);

      double Check_Balance( );

      void Deposit(double);

      void Withdrawal(double);

private:

      double balance;

};

Bank_Transaction::Bank_Transaction()

{

      balance = 0;

}

Bank_Transaction::Bank_Transaction(double amount)

{

      balance = amount;

}

double Bank_Transaction::Check_Balance()

{

      return balance;

}

void Bank_Transaction::Deposit(double amount)

{

      balance = balance + amount;

}

void Bank_Transaction::Withdrawal(double amount)

{

      balance = balance - amount;

}

int main()

{

      Bank_Transaction my_Acct;

      Bank_Transaction your_Acct(10340.85);

      cout<<"Your Account Balance = "<<your_Acct.Check_Balance()<<endl;

      your_Acct.Deposit(512.30);

      cout<<"Your Account Balance = "<<your_Acct.Check_Balance()<<endl;

      your_Acct.Withdrawal(8284.56);

      cout<<"Your Account Balance = "<<your_Acct.Check_Balance()<<endl;

      cout<<"My Account Balance = "<<my_Acct.Check_Balance()<<endl;

      my_Acct.Deposit(2516.83);

      cout<<"My Account Balance = "<<my_Acct.Check_Balance()<<endl;

      my_Acct.Withdrawal(25.96);

      cout<<"My Account Balance = "<<my_Acct.Check_Balance()<<endl;

      return 0;

}

Question 9:Write the statement(ie. the actual line of code) in the program in Step 2 that initializes the balance of the object “your_Acct”.

Question 10:Give the full name of the function(This is also referred to as the function header) and state the type of the constructor that initialized the object “your_Acct”.

Question 11:What happens if you add the statement “my_Acct.Balance = 0;” to the main function of the program in Step 2 after the object declarations? Explain your answer.

Question 12:    What do we mean when we use the following phases?

a. Inside the class

b. Outside the class

Explanation / Answer

Output of above program is:

Your Account Balance = 10340.9
Your Account Balance = 10853.1
Your Account Balance = 2568.59
My Account Balance = 0
My Account Balance = 2516.83
My Account Balance = 2490.87

ANSWERS:

(9)   Bank_Transaction your_Acct(10340.85);

(10) Bank_Transaction::Bank_Transaction(double amount)

Parametrized constructor initializes the balance of the object "your_Acct".

(11) Compile time error is occured when "my_Acct.Balance = 0;" is added to main function.

Reason for error is: 'balance' being private member of the class is not visible outside the class. So we cannot access it in the main function.

(12)

Outside the Class: Defining a member function outside a class requires the function declaration (function prototype) to be provided inside the class definition. The member function is declared inside the class like a normal function. This declaration informs the compiler that the function is a member of the class and that it has been defined outside the class. After a member function is declared inside the class, it must be defined (outside the class) in the program.

The function name in the function header is preceded by the class name and the scope resolution operator (: :). The scope resolution operator informs the compiler what class the member belongs to.

Inside the Class: A member function of a class can also be defined inside the class. However, when a member function is defined inside the class, the class name and the scope resolution operator are not specified in the function header. Moreover, the member functions defined inside a class definition are by default inline functions.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote