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

EXERCISES FOR C++ 1. What\'s wrong with this code? How do we fix it? class Item

ID: 3912608 • Letter: E

Question

EXERCISES FOR C++

1. What's wrong with this code? How do we fix it?

          class Item {

                    private:

                              const int size; // must be initialized with value 10

                    public:

                              Item ( );

          } ;

          Item::Item ( ) {

                  size = 10;

          }

2. Copy/paste the BankAccount class in sub-module "Classes - the heart of OOP" into your IDE and compile with an empty main function such as

          int    main   ( )   { }

       // Have you seen enough of no-opt function with empty brackets like this { } ?

3. Now add code to the main function to

              a. Create a default bank account

              b. Create a non-default bank account

              c. Output to Console the bank routing member. How many ways can you do it? What's the correct way to do it?

              d. Invoke accessor/mutator functions on non-default account (output to console if needed)

              e. Invoke behavioral functions and verify that it works (try both negative/positive amounts)

           Finally recompile the code and run the program to verify your code is working.

Explanation / Answer

Hi,

class Item {

                    private:

                              const int size; // must be initialized with value 10

                    public:

                              Item ( );

          } ;

          Item::Item ( ) {

                  size = 10;

          }

in the above code the problem is size is a constant type variable .and in the constructor value is assigning to the variable like size = 10;.

it will be corrected like below:

#include<iostream>

using namespace std;

class Item {

private:

const int size=10; // must be initialized with value 10

public:

Item ( );

} ;

Item::Item ( ) {

}

int main()

{

return 0;

}

/////// second problem BankAccount . please include it so that can assist you.

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