)In C++ 1. Create a class named SavingsAccount 2. The class should be defined in
ID: 3837764 • Letter: #
Question
)In C++
1. Create a class named SavingsAccount
2. The class should be defined in its own header file and have at least the following data members and functions:
Data Members
- accountOfficer, pointer to an object of class Name to represent the account officer who is responsible for the account.
- oDate, pointer to an object of class Date to represent the date that the account was opened.
- annualInterestRate, data member to represent the interest currently on the account. This value should be the same for all objects created.
- customer, an object of type Customer to represent the Customer of this account.
- accountNumber, data member to represent the account number of the account.
- balance, data member to represent the current balance of the account.
Data members shared by all objects of the class:
- activeOfficer, an object of class Name to represent the current account officer who is creating accounts
- cdate, an object of class Date to represent today's date
Note that this class is composed of several classes that have already been built namely Name, Date and Customer. You should not need to make any changes to these classes and should set-up a symbolic link to the necessary files. If you do not have working versions of these embedded classes use primitive types as data members (i.e. string to represent customer name, etc.)
Member functions:
- Default Constructor(), this constructor should initialize that data members appropriately
- Constructor(), this constructor should initialize that data members customer, savingsBalance, and accountNumber to the corresponding values passed to it.
Note that the data members, accountOfficer, and oDate should be initialized to the activeOfficer and tDate objects respectively.
- modifyInterestRate(), this function should modify the value of the data member annualInterestRate to the value of the parameter passed to it.
- updateSavingsBalance(), this function should calculate the monthly interest and update the savings balance data member with the interest results
- Any other methods as necessary
3. Write a class source code implementation file that contains any necessary declaration of the static variable in global space and code implemenation of all methods in the class.
4. Write a driver program to test this class. The program should:
- Prompt you to enter the current Account Officer on duty.
- Prompt you to enter today's date
- Prompt you to enter current interest rate.
- Create an array of pointers for up to some maximum number of accounts that can be created.
- Allow for the program to continuosly create new accounts (up to maximum) requesting the appropriate information each time.
5. Once all the accounts have been created, the program should:
- invoke a local function accumulateInterest() whose purpose is to update savings balnce for each account created for one year (e.g. 12 months) of savings. This function should take as an argument the array of accounts and accumulate teh interest for one year (i.e. 12 times) on each object of the array.
- invoke a local function to output a blance summary for each account.
Sample Run:
Current Account Officer: John Williams
Current Date: 11/14/2018
Current annual interest rate: 5%
Enter Customer name: Ted Johnson
Enter Starting balance: 10000.0
Enter Customer name: Raul Lopez
Enter Starting balance: 100.0
Enter Customer Name: -
Accumulating Interest for one year...
Account Officer Date Opened Customer Current Balance
John Williams 11/14/2018 Ted Jones $105000.00
John Williams 11/14/2018 Raul Lopez $105.0
-----------------------------------------------------------------------
I have the Name and Date class (they do not need to be used as the question already stated, but they may if you wish.
Name.h
#ifndef _NAME
#define _NAME
#include<iostream>
using namespace std;
class Name
{
private:
string firstname;
string lastname;
string middle_initial;
public:
Name();
Name(string, string, string);
void set_first_name(string);
void set_middle_name(string);
void set_last_name(string);
string get_first_name();
string get_middle_name();
string get_last_name();
void display();
};
#endif
Name.cpp
#include<iostream>
#include"Name.h"
#include<string>
using namespace std;
Name::Name()
{
firstname="";
middle_initial="";
lastname="";
}
void Name::set_first_name(string fname)
{
firstname=fname;
}
void Name::set_middle_name(string mname)
{
middle_initial=mname;
}
void Name::set_last_name(string lname)
{
lastname=lname;
}
string Name::get_first_name()
{
return firstname;
}
string Name::get_middle_name()
{
return middle_initial;
}
string Name::get_last_name()
{
return lastname;
}
void Name::display()
{
cout<<"First name -->"<<firstname<<endl;
cout<<"Middle name -->"<<middle_initial<<endl;
cout<<"Last name -->"<<lastname<<endl;
}
Date.h
#include<iostream>
#include"Name.h"
#include<string>
using namespace std;
Name::Name()
{
firstname="";
middle_initial="";
lastname="";
}
void Name::set_first_name(string fname)
{
firstname=fname;
}
void Name::set_middle_name(string mname)
{
middle_initial=mname;
}
void Name::set_last_name(string lname)
{
lastname=lname;
}
string Name::get_first_name()
{
return firstname;
}
string Name::get_middle_name()
{
return middle_initial;
}
string Name::get_last_name()
{
return lastname;
}
void Name::display()
{
cout<<"First name -->"<<firstname<<endl;
cout<<"Middle name -->"<<middle_initial<<endl;
cout<<"Last name -->"<<lastname<<endl;
}
[odolah@storm lab2]$ cat Date.h
#ifndef _MY_DATE
#define _MY_DATE
class Date
{
private:
int month;
int day;
int year;
public:
Date();//Default constructor
Date(int, int, int);//overload constructor
int get_day();
int get_month();
int get_year();
void set_day(int);
void set_month(int);
void set_year(int);
void display();
};
#endif
Date.cpp
#include<iostream>
#include"Date.h"
using namespace std;
Date::Date()
{
month=12;
year=2000;
day=10;
}
Date ::Date(int d, int m, int y)
{
day=d;
month=m;
year=y;
}
void Date::set_day(int d)
{
if(d>31||d<1)
cout<<"Invalid Day"<<endl;
else
day=d;
}
void Date::set_month(int m)
{
if(m<1 ||m>12)
cout<<"Invalid month"<<endl;
else
month=m;
}
void Date::set_year(int y)
{
year=y;
}
int Date::get_day()
{
return day;
}
int Date::get_month()
{
return month;
}
int Date::get_year()
{
return year;
}
void Date::display()
{
cout<<"DOB -->" <<day<<"/"<<month<<"/"<<year<<endl;
}
Explanation / Answer
class Name
{
private:
string firstname;
string lastname;
string middle_initial;
public:
Name();
Name(string, string, string);
void set_first_name(string);
void set_middle_name(string);
void set_last_name(string);
string get_first_name();
string get_middle_name();
string get_last_name();
void display();
};
#endif
Name.cpp
#include<iostream>
#include"Name.h"
#include<string>
using namespace std;
Name::Name()
{
firstname="";
middle_initial="";
lastname="";
}
void Name::set_first_name(string fname)
{
firstname=fname;
}
void Name::set_middle_name(string mname)
{
middle_initial=mname;
}
void Name::set_last_name(string lname)
{
lastname=lname;
}
string Name::get_first_name()
{
return firstname;
}
string Name::get_middle_name()
{
return middle_initial;
}
string Name::get_last_name()
{
return lastname;
}
void Name::display()
{
cout<<"First name -->"<<firstname<<endl;
cout<<"Middle name -->"<<middle_initial<<endl;
cout<<"Last name -->"<<lastname<<endl;
}
Date.h
#include<iostream>
#include"Name.h"
#include<string>
using namespace std;
Name::Name()
{
firstname="";
middle_initial="";
lastname="";
}
void Name::set_first_name(string fname)
{
firstname=fname;
}
void Name::set_middle_name(string mname)
{
middle_initial=mname;
}
void Name::set_last_name(string lname)
{
lastname=lname;
}
string Name::get_first_name()
{
return firstname;
}
string Name::get_middle_name()
{
return middle_initial;
}
string Name::get_last_name()
{
return lastname;
}
void Name::display()
{
cout<<"First name -->"<<firstname<<endl;
cout<<"Middle name -->"<<middle_initial<<endl;
cout<<"Last name -->"<<lastname<<endl;
}
[odolah@storm lab2]$ cat Date.h
#ifndef _MY_DATE
#define _MY_DATE
class Date
{
private:
int month;
int day;
int year;
public:
Date();//Default constructor
Date(int, int, int);//overload constructor
int get_day();
int get_month();
int get_year();
void set_day(int);
void set_month(int);
void set_year(int);
void display();
};
#endif
#include<iostream>
#include"Date.h"
using namespace std;
Date::Date()
{
month=12;
year=2000;
day=10;
}
Date ::Date(int d, int m, int y)
{
day=d;
month=m;
year=y;
}
void Date::set_day(int d)
{
if(d>31||d<1)
cout<<"Invalid Day"<<endl;
else
day=d;
}
void Date::set_month(int m)
{
if(m<1 ||m>12)
cout<<"Invalid month"<<endl;
else
month=m;
}
void Date::set_year(int y)
{
year=y;
}
int Date::get_day()
{
return day;
}
int Date::get_month()
{
return month;
}
int Date::get_year()
{
return year;
}
void Date::display()
{
cout<<"DOB -->" <<day<<"/"<<month<<"/"<<year<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.