In: Computer Science
i have attached my code here and we are supposed to create two classes. one is date the other switches accounts for bank and then displays the bank account,type,name,date(pulled from first class and then prints out. i am having issues getting my code to pull from the first class and dont know how to make it read the data from date class if someone can look at my code and tell me how to fix this i would greatly appreciate it. Thank you!
include <iostream>
#include <string>
using namespace std;
#ifndef date_H
#define Date_H // dont know if need these two
class Date
{
private:
int month, day, year;
public:
//These are consturctors
Date();// programmer defined default constructor
without parameters
Date(int, int, int);
//Destructor
~Date() {}// destroy the data put into this time for
new one
void setDay(int); // set the day(mutator) not
returning anything
void setMonth(int);// set the month(mutator)not
returning anything
void setYear(int);// set the year(mutator)not
returning anything
void DisplDate();// displays the date which passed to
class 2 Accounts
};
#endif// or this
Date::Date()// initialize the default constructor holding no
parameters
{
//Initialize variables.
month = day = year = 0;// default values all set to
0
}//not returning anything
Date::Date(int Month, int Day, int Year)// default constructor hold
3 ints
{
month = Month;
day = Day;
year = Year;
}//not returning anything
void Date::setDay(int d)
{
cout<< "enter the day of your last
payment"<< endl;
cin >> day;
}//not returning anything
void Date::setMonth(int m)// need this between 1 and 12 for
months
{
cout << " enter the month of your last payment"
<< endl;
cin >> month;
}//not returning anything
void Date::setYear(int y)
{
cout << "enter a year number" <<
endl;
cin >> year;
}
void Date::DisplDate()// display out the month day and year
{
cout << month << " /" << day
<< " /" << year << endl;
}//not returning anything but holds the valid input data
class Account: private Date // calling the private date values
relationship
{
private:
int ActNum;// account number is
integers i.e (1234567890)
char ACCT_TYPE, Name[20];//
checking, savings and user name
Date defaultdate;
//object of class date
float ActBal;// must be float
dealing with decimals
public://default parameterized constructor
Account(int AccountNum, string Name, char ActType,
float balance, Date day, Date month, Date year)
{
ActNum = AccountNum;
string ActName = Name;
char ACCT_Type = ActType;
float ActBal =balance;
defaultdate.day = 0;
defaultdate.month = 00;
defaultdate.year = 0000;// how to
call this from first
}
void AccountData(); // idk if date goes in
here
void Accountdeposit();
void Accountwithdrawl();
void Accounttransfer();
void Accountdisplay();
//~Account() {};
};
void Account::AccountData(void)
{
cout << "\nEnter account number : ";
cin >> ActNum;
cout << "\nEnter account type (c/s) : ";
cin >> ACCT_TYPE;
cout << "\nEnter name : ";
cin >> Name;
getchar();
cout << "\nEnter balance : ";
cin >> ActBal;
cout << "\nEnter date of last transaction :
";
cout << "\n Day : ";
cin >>day;
cout << "\n Month : ";
cin >> month;
cout << "\n Year : ";
cin >> year;
}
void Account::Accountdeposit() //depositing an amount
{
int DepositAmt;
cout << "\n Enter Deposit Amount = ";
cin >> DepositAmt;
cout << " enter the account to be deposited
into" << endl;
cin >> ACCT_TYPE;
ActBal += DepositAmt;
}
void Account::Accountwithdrawl() //withdrawing an amount
{
int WithdrwlAmt;
cout << "\n enter ammount to withdraw = ";
cin >> WithdrwlAmt;
cout << " which account do you want to be
withdrawn from?" << endl;
cin >> ACCT_TYPE;
if (WithdrwlAmt > ActBal)
cout << "\n Exceeds balance
ammount to withdraw";
else
ACCT_TYPE=ActBal -= WithdrwlAmt;//
the account balance of said act is
}
void Account::Accountdisplay()
{
cout << "\n ----------------------";
date;
cout << "\n Accout No. : " <<
ActNum;
cout << "\n Name : " << Name;
cout << "\n Account Type : " <<
ACCT_TYPE;// checking and savings
cout << "\n Balance : " << ActBal;
}
void Account::Accounttransfer()
{
char ACCT_TYPE;
double Savings, Checking, ammount;// ammount to
transfer
//cin >> selection;
cout << " enter the ammount to transfer"
<< endl;
cin >> ammount;
cout << " select whihc account to transfer from
and to" <<
"checking or savings as an s or c"
<< endl;
cin >> ACCT_TYPE;
if (ACCT_TYPE == Savings)
{
if (Savings > 0.00)
{
Savings -=
ammount;
Checking +=
ammount;
}
else
cout <<
"error not enough money" << endl;
if (ACCT_TYPE==Checking )
{
if (Checking
> 0.00)
{
Checking -= ammount;
Savings += ammount;
}
else
cout << " error not enough money" <<
endl;
}
}
}
int main()
{ //so far below prints out data for date
int Month, Day, Year;
cout << "please enter month day and year in
numerical values" <<
"then press enter " <<
endl;
cin >> Month >>Day >>Year;
//now that the user inputted data, goes to class and
evaluate for new
//date other than default
Date newDate(Month, Day, Year);// call to date
class
cout << " the date of your last payment was"
<< endl;
newDate.DisplDate();// maybe as showpoint? without
this nothing prints out
cin.get();// getting the data from the class for the
new date
cout<< " your last payment was made on" <<
cin.get();// getting the data to display function
return 0;
}
#include<bits/stdc++.h>
using namespace std;
/* I would have helped you implement all the functionality of the
programm
But as you have just asked me to help you set the values from
the Account class into the Date
class I have pretty much did it,
Inorder to set the values into the date Obj you can use you setters
to set their values,
and similary to use the values some palces you can
make use of the getters;
you can get rid of this function AccountData and
take the input in the main and there try to create the object of
the
customers and you can strore them in some data
structure to use it later;
//You have not provided the complete statement soo as far i have understood i have suggested you some stuffs below
// if your trying to fetch the
details just on basis of certain date it make no sense as there
would be number of transactions that can happen
at the same
time, so you rather try accessing the details using [Unique Account
Number] and there in which you can access the date
thank you,
//next time make sure to briefly describe what exactly
your programm is doing,
*/
class Date
{
private:
int month, day, year;
public:
//These are consturctors
Date();// programmer defined default constructor without
parameters
Date(int Month, int Day, int Year);
//Destructor
// destroy the data put into this time for new one
void setDay(int); // set the day(mutator) not returning
anything
void setMonth(int);// set the month(mutator)not returning
anything
void setYear(int);// set the year(mutator)not returning
anything
void DisplDate();// displays the date which passed to class 2
Accounts
int getDay(){
return this->day;
};
int getMonth(){
return this->month;
}
int getYear(){
return this->year;
}
~Date() {}
};
Date :: Date() {
month = day = year = 0;
}
Date::Date(int Month, int Day, int Year)// default constructor
hold 3 ints
{
month = Month;
day = Day;
year = Year;
}
void Date::setDay(int d)
{
cout<< "enter the day of your last payment"<<
endl;
cin >> day;
}
void Date::setMonth(int m)// need this between 1 and 12 for
months
{
cout << " enter the month of your last payment" <<
endl;
cin >> month;
}
void Date::setYear(int y)
{
cout << "enter a year number" << endl;
cin >> year;
}
void Date::DisplDate()// display out the month day and
year
{
cout << month << " /" << day << " /"
<< year << endl;
}
class Account: private Date // calling the private date values
relationship
{
//You need to store the data inorder to access
them
private:
int ActNum;// account number is integers i.e (1234567890)
char ACCT_TYPE;
string Name;// checking, savings and user name
Date defaultdate;
//object of class date
float ActBal;// must be float dealing with decimals
public://default parameterized constructor
Account(int accountNum, string accountHolderName,
char accountType, float accountBal, int Month = 0, int Day = 0, int
Year = 0)
{
ActNum =
accountNum;
Name =
accountHolderName;
ACCT_TYPE =
accountType;
ActBal =
accountBal;
defaultdate.setMonth(Month);
defaultdate.setDay(Day);
defaultdate.setYear(Year);
}
void AccountData(); // idk if date goes in here
void Accountdeposit();
void Accountwithdrawl();
void Accounttransfer();
void Accountdisplay();
//~Account() {};
};
void Account::AccountData(void)
{
cout << "\nEnter account number : ";
cin >> ActNum;
cout << "\nEnter account type (c/s) : ";
cin >> ACCT_TYPE;
cout << "\nEnter name : ";
cin >> Name;
getchar();
cout << "\nEnter balance : ";
cin >> ActBal;
cout << "\nEnter date of last transaction : ";
cout << "\n Day : ";
int transactionDay, transactionMonth,
transactionYear;
cin >> transactionDay; //As you have declared them private
you cannot assigned them values from different class, for which you
have to make use of getters and setters || or you try changing the
day, month, and year in Date to pubic;
cout << "\n Month : ";
cin >> transactionMonth;
cout << "\n Year : ";
cin >> transactionYear;
}
void Account::Accountdeposit() //depositing an amount
{
int DepositAmt;
cout << "\n Enter Deposit Amount = ";
cin >> DepositAmt;
cout << " enter the account to be deposited into" <<
endl;
cin >> ACCT_TYPE;
ActBal += DepositAmt;
}
void Account::Accountwithdrawl() //withdrawing an amount
{
int WithdrwlAmt;
cout << "\n enter ammount to withdraw = ";
cin >> WithdrwlAmt;
cout << " which account do you want to be withdrawn from?"
<< endl;
cin >> ACCT_TYPE;
if (WithdrwlAmt > ActBal)
cout << "\n Exceeds balance ammount to withdraw";
else
ACCT_TYPE=ActBal -= WithdrwlAmt;// the account balance of said act
is
}
void Account::Accountdisplay()
{
cout << "\n ----------------------";
cout << defaultdate.getDay() << ' '
<< defaultdate.getMonth() << ' ' <<
defaultdate.getYear() << endl;
cout << "\n Accout No. : " << ActNum;
cout << "\n Name : " << Name;
cout << "\n Account Type : " << ACCT_TYPE;// checking
and savings
cout << "\n Balance : " << ActBal;
}
void Account::Accounttransfer()
{
//char ACCT_TYPE; dont use the same variable what you have declared inside the class again and again
char accontType;
double Savings, Checking, ammount;// ammount to transfer
//cin >> selection;
cout << " enter the ammount to transfer" << endl;
cin >> ammount;
cout << " select whihc account to transfer from and to"
<<
"checking or savings as an s or c" << endl;
cin >> accontType;
if (accontType == Savings)
{
if (Savings > 0.00)
{
Savings -= ammount;
Checking += ammount;
}
else
cout << "error not enough money" << endl;
if (accontType==Checking )
{
if (Checking > 0.00)
{
Checking -= ammount;
Savings += ammount;
}
else
cout << " error not enough money" << endl;
}
}
}
int main()
{ //so far below prints out data for date
int Month, Day, Year;
cout << "please enter month day and year in numerical
values then press enter " << endl;
cin >> Month >>Day >>Year;
//now that the user inputted data, goes to class and evaluate for
new
//date other than default
Date newDate(Month, Day, Year);// call to date class
cout << " the date of your last payment was" <<
endl;
newDate.DisplDate();// maybe as showpoint? without this nothing
prints out
cin.get();// getting the data from the class for the new date
cout<< " your last payment was made on" << cin.get();//
getting the data to display function
return 0;
}