Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines.
Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your type will have to be of the base class, Bank. This will be explained in more detail later.
Step 1:
Create a header file Bank.h to define a Bank class with the following members:
Data members: The program should implement data hiding, so please define data members accordingly.
- accountNumber
- name
- balance
- Account type (see Step 3 below)
Note: The data types are not specified for this problem, so you have some flexibility in your design.
Member functions: Please include only the declaration of the member functions in the header file. The implementation of member functions will later be done in the Bank.cpp file. (You may inline get and set functions.)
Step 2:
Create a Bank.cpp file and implement the member functions of the Bank class.
Step 3:
Create two derived classes with Bank as the base class, Savings and Checking, as follows. Your derived classes must have two constructors, one that takes no arguments and another that takes as arguments all possible fields for the class, including fields in the base class. These derived classes do not need to be in separate files. You can include the header and implementation in Bank.h and Bank.cpp, respectively.
-Savings accounts pay interest, so you need the following additional fields, along with accessors and mutators:
-Annual interest rate, a floating-point number
-Compounding period in days
-Write an AddInterest function that takes a number of days and applies interest to the account at the given rate. It should return the amount of interest added, and the balance should reflect this.
-Checking accounts require two additional fields, along with accesors and mutators:
-Minimum balance, in dollars
-Monthly fee, in dollars.
Step 4:
Also define an independent displayAccountInfo(Bank object) function which takes a Bank object as a parameter and displays the accountNumber, name, and balance of the bank account specified by this Bank object. The displayAccountInfo() function is later called by the main function.
Please note: The displayAccountInfo() function IS NOT a member function of the Bank class. It is an independent function that is called from inside the main function.
Step 5:
Finally, create a main.cpp file to do the following functions. Note that each time you create an account, you must store the pointer to its object in your array.
Display a menu with the following options:
A minimal test would include the following:
Assumptions: There will never be more than 100 accounts. Show an error message if the user tries to deposit to or withdraw from an account number that doesn’t exist. Show an error message if the user attempts to create an account number that already exists. Show any messages returned from the withdraw() function.
The main input validation is that things like names should not be null or blank, and that numeric values are actually numeric. The grader will not test with the intent of breaking your program with invalid input.
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU
ANSWER:
CODE:
#include <stdio.h>
#include <string.h>
#include "Bank.h"
#include <iostream>
#include <stdlib.h>
static const char* const INSUFFICIENT_BALANCE_MSG =
"Insufficient balance";
Bank::Bank()
{
accountNumber = 9999;
balance = 0;
name = "";
}
Bank::Bank(const char* nm, long account, double bal)
{
name = nm;
accountNumber = account;
balance = bal;
}
const char*
Bank::withdraw(double amount)
{
static char balancestr[128];
if (balance > amount)
{
balance -= amount;
sprintf(balancestr,
"%f", balance);
return (const
char*)balancestr;
}
return INSUFFICIENT_BALANCE_MSG;
}
double Bank::deposit(double amount)
{
balance += amount;
return balance;
}
Savings::Savings()
: Bank()
{
compounding_period = 0;
interest = 0;
set_account_type(SAVINGS);
}
Savings::Savings(const char* name, long account, double bal,
float intr, int compounding_per)
: Bank(name, account, bal)
{
interest = intr;
compounding_period = compounding_per;
}
double Savings::AddInterest(int days)
{
double Interest = 0;
double totalInterest = 0;
int num_periods = days/compounding_period;
float net_interest = (interest*
compounding_period)/(365.0);
while (num_periods > 0)
{
Interest = getBalance()*
net_interest;
deposit(Interest);
num_periods--;
totalInterest +=
Interest;
}
return totalInterest;
}
Checking::Checking()
:Bank()
{
minimum_balance = 0;
monthly_fees = 0;
}
Checking::Checking(const char* name, long account, double bal,
double minbal, double fees)
: Bank(name, account, bal)
{
minimum_balance = minbal;
monthly_fees = fees;
}
void displayAccountInfo(Bank* obj)
{
std::cout << "Bank Account: " <<
std::endl;
std::cout << "Name: " <<
obj->getName() << std::endl;
std::cout << "Number: " <<
obj->getAccountNumber() << std::endl;
std::cout << "Balance: " <<
obj->getBalance() << std::endl;
}
// This function will display the menu
char PrintMenu(Bank** AccountArr)
{
char option;
// Displaying the menu
printf("\nMENU\n" );
printf("s - New Savings Account\n" );
printf("c - New Checking Account\n" );
printf("b - New Bank Account\n" );
printf("d - Deposit To Account\n" );
printf("w - Withdraw From Account\n" );
printf("p - Print All Checking/Saving Account
Information\n" );
printf("q - Quit\n" );
// getting the choice entered by the user
printf( "Choose option :\n");
scanf("%c", &option);
static int num_account = 0;
while (getchar() != '\n');
switch(option)
{
case 's':
{
if (num_account > 100)
{
std::cout << "No more accounts can be created" <<
std::endl;
return;
}
num_account++;
std::cout << "Please provide account number " <<
std::endl;
long number;
std::cin >> number;
while (getchar() != '\n');
std::cout << "Please provide account name" <<
std::endl;
std::string name;
std::cin >> name;
while (getchar() != '\n');
double balance;
std::cout << "Please provide account balance" <<
std::endl;
std::cin >> balance;
while (getchar() != '\n');
std::cout << "Please provide the interest rate" <<
std::endl;
float interest;
std::cin >> interest;
while (getchar() != '\n');
std::cout << "Please provide the compounding period in days"
<< std::endl;
int days = 0;
std::cin >> days;
while (getchar() != '\n');
Savings* saving = new Savings(name.c_str(), number, balance,
interest, days);
AccountArr[num_account-1] = saving;
break;
}
case 'c':
{
if (num_account > 100)
{
std::cout << "No more accounts can be created" <<
std::endl;
return;
}
num_account++;
break;
}
case 'b':
{
if (num_account > 100)
{
std::cout << "No more accounts can be created" <<
std::endl;
return;
}
num_account++;
break;
}
case 'd':
{
break;
}
case 'w':
{
break;
}
case 'p':
{
break;
}
case 'd':
break;
default:
printf("Invalid option **" );
break;
}
return option;
}
int main()
{
Bank** AccountArr = new Bank*[100];
for(int i = 0; i < 100; i++)
AccountArr[i] =
NULL;
char quit = ' ';
while (quit != 'q')
{
// calling the function
quit = PrintMenu(AccountArr);
}
return 0;
}
#ifndef _BANK_HXX_
#define _BANK_HXX_
#include <string>
typedef enum { SAVINGS = 0, CHECKING } AccountType;
class Bank
{
public:
Bank();
Bank(const char* nm,
long account, double bal);
const char*
withdraw(double amount);
double deposit(double
amount);
void setName(const char*
nm) { name = nm; }
long getAccountNumber()
{ return accountNumber; }
const char* getName() {
return name.c_str(); }
double getBalance() {
return balance; }
void
set_account_type(AccountType ty) { type = ty; }
AccountType
get_account_type() { return type; }
private:
long
accountNumber;
std::string name;
double balance;
AccountType type;
};
class Savings :public Bank
{
public:
Savings();
Savings(const char*
name, long account, double bal, float intr, int
compounding_per);
double AddInterest(int
days);
float getInterest() {
return interest; }
void setInterest(float
intr) { interest = intr; }
int
get_compounding_period_in_days() { return compounding_period;
}
void
set_compounding_period_in_days(int com) { compounding_period = com;
}
private:
float interest;
int compounding_period;
// in days
};
class Checking : public Bank
{
public:
Checking();
Checking(const char*
name, long account, double bal, double minbal, double fees);
double
get_minimum_balance() { return minimum_balance; }
double
get_monthly_fees() { return monthly_fees; }
void
set_minimum_balance(double val ) { minimum_balance = val ; }
void
set_monthly_fees(double fees) { monthly_fees = fees; }
private:
double
minimum_balance;
double
monthly_fees;
};
#endif
RATE THUMBSUP PLEASE
HOPE IT HELPS YOU
THANKS
Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...
Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...
Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...
c++ please Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...
C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...
Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit...
the programing language is C++ TIC PEO. Design a generic class to hold the following information about a bank account! Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following member functions: Constructor: Accepts arguments for the balance and annual interest rate. deposit: A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also...
Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...
Design a class that contains: we have to make 3 files header file , one .cpp file for function and one more main cpp file 9.3 (The Account class) Design a class named Account that contains: An int data field named id for the account. A double data field named balance for the account. A double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...