main.cpp #include <iostream> #include \"Name.h\" #include \"Date.h\" using names
ID: 3837814 • Letter: M
Question
main.cpp
#include <iostream>
#include "Name.h"
#include "Date.h"
using namespace std;
int main()
{
Name n;
Date d;
string firstname;
string lastname;
string middlename;
int day, month,year;
cout << "Please enter first name: ";
cin >> firstname;
cout << "Please enter last name: ";
cin >> lastname;
cout << "Please enter middle name: ";
cin >> middlename;
cout << "Please enter month: ";
cin >> month;
cout << "Please enter day: ";
cin >> day;
cout << "Please enter year: ";
cin >> year;
//n.Name(firstname,lastname,middlename);
n.setfirstname(firstname);
n.setlastname(lastname);
n.setmiddlename(middlename);
d.setmonth(month);
d.setday(day);
d.setyear(year);
cout << "Name is " << n.getfirstname()<<" "<<n.getmiddlename()<<" "<<n.getlastname()<<endl;
cout << "Date is " << d.getmonth()<<"/"<<d.getday()<<"/"<<d.getyear()<<endl;
return 0;
}
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;
}
This is the existing Name and Date class
1. Create a class named ccount. 2. The class should be defined in its' own header file and have at least the following data members and member 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 balance, data member to represent the current balance of the account Data members shared by all objects of the class activeOficer, 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 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.). Feel free to add additional data members as necessary. organization and style will be taken into account to receive full credit.Explanation / Answer
SavingsAccount.cpp
// Date.cpp
#include "SavingsAccount.h"
#include <iostream>
using namespace std;
float SavingsAccount::annualInterestRate = 5;
Name SavingsAccount::activeOfficer;
Date SavingsAccount::cdate;
SavingsAccount::SavingsAccount(){
};
SavingsAccount::SavingsAccount(string cN,float b, long aN){
customerName= cN;
accountNumber = aN;
balance = b;
accountOfficer = &activeOfficer;
oDate = &cdate;
};
void SavingsAccount::modifyInterestRate(float rate){
annualInterestRate = rate;
};
void SavingsAccount::updateSavingsBalance(){
balance += (balance*annualInterestRate/100);
} ;
void SavingsAccount::getAccountDetails(){
cout<<accountOfficer->getfirstname()<<" "<<oDate->getday()<<"/"<<oDate->getmonth()<<"/"<<oDate->getyear()<<" "<<customerName<<" "<<balance;
};
SavingsAccount.h
#include "Date.h"
#include "Name.h"
using namespace std;
#ifndef SavingsAccount_H
#define SavingsAccount_H
class SavingsAccount
{
private:
Name *accountOfficer;
Date *oDate;
string customerName;
long accountNumber;
float balance;
public:
static float annualInterestRate;
static Name activeOfficer;
static Date cdate;
SavingsAccount(); //default constructor
SavingsAccount(string cN,float b, long aN); //constructor
void modifyInterestRate(float rate);
void updateSavingsBalance();
void getAccountDetails();
};
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.