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

CS37 Total Point: 12 Description: Develop a polymorphism banking program using t

ID: 3837154 • Letter: C

Question

CS37

Total Point: 12

Description: Develop a polymorphism banking program using the Account class hierarchy which includes three classes: Account, SavingsAccount and CheckingAccount as defined in Assignment 4. Write a test driver application program that uses these classes to demonstrate how polymorphism works.

Tasks:

Implement the three classes as defined in Assignment 4. You must also add a printAccount() member function to each class to print the class name and appropriate data members of each class (e.g. accountNumber, accountOwner, accountBalance, interestRate, fee, etc.) in nice format.

Create a vector of Account pointers (i.e. each element of the vector has type Account *). The vector will be used to store the pointers to the account objects (which could be Account, SavingsAccount or CheckingAccount objects) created in the main() program.

Use the C++ STL vector template for this task. Chapter 7 of textbook contain information about using vector template. Fig. 12.19 on p. 568 of textbook also contain sample codes.

Create at least five account objects of different types using the new operator and assign their addresses to the pointers in the vector. Refer to Fig. 12.19 for sample codes.

For each account in the vector, allow the user to specify an amount of money to deposit into or withdraw from the account. The polymorphism will dynamically decide on which credit or debit member functions to use for each accounting object.

You must declare some member functions (e.g. credit, debit, printAccount, etc.) as “virtual functions” in the base class to make the polymorphism possible. Do not try to use “pure virtual function” in the base class Account because this would make it impossible to create objects of this class.

For each selected transaction (credit, debit, checkBalance, …), the program should print clear message about the transaction including information such as: type of transaction, account number or account owner, the type of account (e.g. SavingsAccount, ,,.), amount of money involved, and the result of transaction.

You could define a member variable (a string) in each class to store the type of account information (i.e. class name of each account object) for printing purpose.

For extract credit, you should use the Runtime Type Information (RTTI) capability (e.g. typeid and name functions) to find out the type of account, See Fig.12.19 in textbook for sample codes.

This item is optional and is for extra credit. Define a virtual destructor for each class to release the memory space of each object (because the object was created using the new operator). Inside the descructor, make sure to include a cout statement to display message such as “Destructor of class Account (or SavingsAccount or CheckingAccont) is called” to show that proper destructor has been called.

Your main() function should perform various kind of transactions on all three types of accounts that is enough to show that the polymorphism works.

Turn in the source code and program input/output (including content of at least five accounting objects, as well as information and result of each transaction) for grading.

******************************************************************************************

How to get the extra credit (5 points) from this assignment:

In item (5) (three bonus points): Using RTTI to find out the type of account objects

Implement a member function getClass_ID which uses the Runtime Type Information (RTTI) capability (e.g. typeid and name functions) to find the name string of the class that the current object belongs to. For example, if the pointer points to a SavingsAccount object, then this member function should return a “SavingsAccount” string.

One way to show that the getClass_ID function works is: Calling the getClass_ID function within the printAccount() function when you have to print the content of each accounting object.

Another way to show it works is: you can use a for-loop in the main() to traverse through the vector that contains pointers to accounting objects, and use each pointer in the vector to invoke this getClass_ID function to print out the class name of each object in the vector.

In item (6) (two bonus points): Define a virtual destructor for each class to release the memory space of each object (because the object was created using the new operator) and showing the class name of the object being deleted.

    

The Bonus program must be turned in the same time as the Assignment 5 by the due date.

Explanation / Answer

import turingMachine.State;
import turingMachine.Transition;
import turingMachine.TuringMachine;

/**
* electronic computer
* Coded by emir El Bawab
* Date: three January 2015
* License: university License ~ Please browse License.txt for a lot of info concerning the usage of this software system
* */
public category AcceptReject produce the machine which will solely settle for 1's
       TuringMachine atomic number 69 = new TuringMachine('q');
      
       // produce the states
       State[] alphabetic character = new State[3];
       q[0] = tm.addState(State.INITIAL);
       q[1] = tm.addState(State.FINAL);
       q[2] = tm.addState(State.NORMAL);
      
       // Add transition
       tm.addTransition(q[0], q[0], '1', '1', Transition.RIGHT);
       tm.addTransition(q[0], q[1], Transition.BLANK, Transition.BLANK, Transition.LEFT);
       tm.addTransition(q[0], q[2], '0', '0', Transition.RIGHT);
      
       // method input 111
       if(tm.process("111")) // settle for as a result of solely 1's
           System.out.println("Accept 111");
       else
           System.out.println("Reject 111");
      
       // method input 1011
       if(tm.process("1011")) // Reject as a result of there is a zero
           System.out.println("Accept 1011");
       else
           System.out.println("Reject 1011");
   }
}
import java.io.FileNotFoundException;

import turingMachine.TuringMachine;

/**
* Turing Machine
* Coded by Amir El Bawab
* Date: three January 2015
* License: university License ~ Please browse License.txt for a lot of info concerning the usage of this software system
* */
public category Addition {
   public static void main(String[] args) {
       try {
          
           // Import addition machine
           TuringMachine addition = TuringMachine.inParser("addition");
          
           // Print addition machine
           System.out.println("Machine content:");
           System.out.println(addition);
          
           // method input
           addition.process("1011");
          
           // Print the tape content once the method
           System.out.println("Tape content once process '1011':");
           System.out.println(addition.getTapeSnapshot());
          
       } catch (FileNotFoundException e)
      
   }
}