C++ Assignment 4
1. In class we use recursion to solve the Fibonacci problem. Write an iterative function to solve the same problem. Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first.
2. Given a string and a character as input, write a recursive function to remove all the input characters from the string.
Example 1:
Input: hello world, e Output: hllo world Example 1:
Input: hello world, o Output: hell wrld
Function prototype is defined below: String removeC(string input, char c);
Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first.
3. Temperature type conversions.
(1) Provide class methods which allow type conversion between the celcius and farenheit classes below. (Note: to convert from Celcius to Farenheit multiply by 1.8 then add 32, and to convert from Farenheit to Celcius subtract 32 then divide by 1.8.)
(2) Provide a main routine demonstrating the following type conversions: farenheit to celcius celcius to farenheit
Deadline: Dec 8, 23:59pm
Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first
4. What is the output of the following program?
5. An experimental psychologist has designed the following class in C++ to perform a (very) crude simulation of short-term memory:
A Brain is initially empty. add_an_item adds a string to the memory. The memory can only contain up to seven strings. The addition of another string causes the first (oldest) string to be forgotten. A bump on the head causes the most recently added string to be forgotten. display displays the current contents of memory. Write the definitions of the interface functions. You need to write a main function to test the validity of your implemented member functions.
Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first
6. Create a SavingsAccount class. Use a static data member to contain the annualInterestRate for each of the savers. Each member of the class contains a private data member savingsBalance indicating the amount the saver currently has on deposit. Provide a calculateMonthlyInterest member function that calculates the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value. Write a driver program to test class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 3%, then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 4% and calculate the next months interest and print the new balances for each of the savers.
Put the class declaration in SavingsAccount.h and class definition in SavingsAccount.cpp, so that the following main.cpp can run successfully.
Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first
Result is:
Hint: the interest rate is annual, and to calculate the monthly rate, you need to divide by 12.
7. Inheritance
applyInterest.
There is a base Account class that manages the basic operations of a bank account, such as
deposits and withdrawals. The specifics of a checking account and savings account should be
managed by the more specialized classes Checking and Savings.
On both types of accounts you should not let the balance drop below zero, so this should be
checked before making a withdrawal. If below zero, print out Insuffient funds to complete this
transaction, and terminate the transaction.
The savings account should add the interest earned to its balance after calling a function
The default interest rate for a savings account is 1% as specified in the
default value of the constructors parameter. That means if you dont specify a different value
when creating an object, that should be the rate used. I will test your class to see if it works
with the default value and with different interest rates values as well.
A checking account object can be created with two default parameters: one that specifies a
10-cent charge per withdrawal, and one that sets the number of free withdrawals to 5. In that
case, if there is up to 5 withdrawals from the account in a particular month, there are no
charges. For more than 5 withdrawals, there is a 10-cent charge per withdrawal. For example,
if there are 7 withdrawals, there is a 20-cent charge. Again, those parameters can be changed
when the object is created.
It is important that you use what is already implemented in the base BankAccount class by
calling its methods. Do not replicate what is already implemented in BankAccount, since reuse
of code is one of the main purposes of object oriented programming. The more specialized
class is supposed to extend the base class.
The following is provided:
BankAccount.h: The base class implementation. Do not change these files.
BankAccount.h
Checking.h: The specification of your checking account class, which is a subclass of
BankAccount. Do not change this file. You will implement the Checking.cpp
Savings.h: The specification of your savings account class, which is a subclass of BankAccount.
Do not change this file. You will implement the Savings.cpp
Checking.h
Savings.h
You need to write a main.cpp to test the validity of your code. Below is an example:
Example main.cpp
The desired output is:
You need to implement checking.cpp and savings.cpp.
Take a screen shot of your source code and programming execution result and attach it here as the solution of this question. Note that you need to cout your name and student ID first
Reviews
There are no reviews yet.