Given this class specification: Class: BankAccount Data members: int balance Write these function definitions: 1. An external definition of a member function that can be a const member function. 2. An external definition for a member function that should not be a const member function.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

paste indedte code....need help with C++

---

**Question 1**

**Given this class specification:**

- **Class:** BankAccount
- **Data members:** int balance

**Write these function definitions:**

1. An external definition of a member function that can be a const member function.
2. An external definition for a member function that should not be a const member function.

---
Transcribed Image Text:--- **Question 1** **Given this class specification:** - **Class:** BankAccount - **Data members:** int balance **Write these function definitions:** 1. An external definition of a member function that can be a const member function. 2. An external definition for a member function that should not be a const member function. ---
Expert Solution
Step 1

In C++ , if the member function is defined inside the class definition it can be defined directly ,but if its defined outside the class, then we have to use the scope resolution : : operator along with class name and function name.

Here in the following code,getValue has been made a const  member function, which means we can call it on any const objects.  For member functions defined outside of the class definition, the const keyword must be used on both the function prototype in the definition and on the function definition.

Algorithm:

1,Defining the class name

2.Defining variable name balance of type int

3. Defining constructor 

4.Defining constant member function

5.Printing the value in the main function

1.

#include<iostream>
using namespace std;

class BankAccount {
    int balance;
public:
        BankAccount (int b=0) 
        {
            balance = b;
        }
        int getValue() const;
};
int BankAccount::getValue() const
{
    return cout<<"Balance is:", balance;
}
int main()
{
    BankAccount t(20);
    cout<<t.getValue();
    return 0;
}

Output: 200000

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education