Hi can someone help me with this - the language is C++ and I already have the Na
ID: 3838346 • Letter: H
Question
Hi can someone help me with this - the language is C++ and I already have the Name and Date classes
Name.h
// Name.h
#include <string>
using namespace std;
#ifndef Name_H
#define Name_H
class Name
{
private:
string firstname;
string lastname;
string middlename;
public:
Name(); //default constructor
Name(string fn, string ln, string mn); //constructor
string getfirstname(); //accessor for the firstname
string getlastname(); //accessor for the lastname
string getmiddlename(); //accessor for the middlename
void setfirstname(string fn); //mutator for firstname
void setlastname(string ln); //mutator for lasttname
void setmiddlename(string mn); //mutator for middlename
};
#endif
Name.cpp
// Name.cpp
#include "Name.h"
#include <iostream>
using namespace std;
Name::Name()
{
firstname=" ";
lastname=" ";
middlename=" ";
}
Name::Name(string fn, string ln, string mn)
{
firstname=fn;
lastname=ln;
middlename=mn;
}
string Name :: getfirstname() //accessor for the firstname
{
return firstname;
}
string Name :: getlastname() //accessor for the lastname
{
return lastname;
}
string Name :: getmiddlename() //accessor for the middlename
{
return middlename;
}
void Name :: setfirstname(string fn) //mutator for firstname
{
firstname=fn;
}
void Name :: setlastname(string ln) //mutator for lasttname
{
lastname=ln;
}
void Name :: setmiddlename(string mn) //mutator for middlename
{
middlename= mn;
}
Date.h
// Date.h
using namespace std;
#ifndef Date_H
#define Date_H
class Date
{
private:
int month;
int day;
int year;
public:
Date(); //default constructor
Date(int m, int d, int y); //constructor
int getmonth(); //accessor for the month
int getday(); //accessor for the day
int getyear(); //accessor for the year
void setmonth(int m); //mutator for month
void setyear(int d); //mutator for year
void setday(int y); //mutator for month
};
#endif
Date.cpp
// Date.cpp
#include "Date.h"
#include <iostream>
using namespace std;
Date::Date()
{
month=0;
day=0;
year=0;
}
Date::Date(int m, int d, int y)
{
month=m;
day=d;
year=y;
}
int Date :: getmonth() //accessor for the month
{
return month;
}
int Date :: getday() //accessor for the day
{
return day;
}
int Date :: getyear() //accessor for the year
{
return year;
}
void Date :: setmonth(int m) //mutator for month
{
month=m;
if(month>12)
cout<<" ERROR: Invalid month!!!"<<endl;
}
void Date :: setday(int d) //mutator for lasttname
{
day=d;
if(day>31)
cout<<" ERROR: Invalid day!!!"<<endl;
}
void Date :: setyear(int y) //mutator for year
{
year= y;
if(year>2017)
cout<<" ERROR: Invalid year!!!"<<endl;
}
Explanation / Answer
#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();
};
Name::Name()
{
firstname="";
middle_initial="";
lastname="";
}
Name::Name(string f, string m, string l){
firstname=f;
middle_initial=m;
lastname=l;
}
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<<""<<firstname;
cout<<" "<<middle_initial;
cout<<" "<<lastname;
}
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();
};
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<<" " <<day<<"/"<<month<<"/"<<year;
}
class SavingsAccount{
private:
Name *customer;
int accountNumber;
double balance;
public:
static Name *accountOfficer;
static Date *oDate;
static double annualInterestRate;
SavingsAccount(Name *cust,int account,double bal){
customer=cust;
accountNumber=account;
balance=bal;
}
SavingsAccount(){
customer=NULL;
accountNumber=0;
balance=0.0;
}
void displayName(){
customer->display();
}
double getBalance(){
return balance;
}
};
Name *SavingsAccount::accountOfficer = NULL;
Date *SavingsAccount::oDate = NULL;
double SavingsAccount::annualInterestRate=0.0;
int main(){
string fname = "John";
string lname = "Williams";
Name * name = new Name(fname,"",lname);
Date * date = new Date(11,14,2018);
double interest = 5.0;
SavingsAccount::accountOfficer = name;
SavingsAccount::oDate = date;
SavingsAccount::annualInterestRate = 5.0;
cout <<" Current Account Officer: ";
SavingsAccount::accountOfficer->display();
cout <<" Current Date:";
SavingsAccount::oDate->display();
int SIZE = 3;
SavingsAccount accounts[SIZE];
int count =0;
while(count<SIZE){
cout << " Enter Customer Name(FirstName LastName) : ";
string f,l;
cin >>f>>l;
cout << " Enter Starting balance : ";
double bal;
cin >>bal;
Name * n = new Name(f,"",l);
SavingsAccount ac(n,111,bal);
accounts[count] = ac;
count++;
}
cout <<"Accumulating Interest for one year... -----------------------------------------------------"<<endl;
for(int i=0;i<count;i++){
SavingsAccount ac = accounts[i];
ac.accountOfficer->display();
cout<<" ";
ac.oDate->display();
cout<<" ";
ac.displayName();
cout<<" ";
cout<<(ac.getBalance()+(ac.getBalance()/100.0*SavingsAccount::annualInterestRate))<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.