The goal of this assignment is to design and implement classes. We will continue
ID: 3804952 • Letter: T
Question
The goal of this assignment is to design and implement classes. We will continue the lesson from the 2/27 lecture on the banking model. Write a program that implements a class model for storing and managing the following date: Test Data: Create a customer using your name and address. Create two accounts for yourself, a Checking and a Savings. Start with a $100 Credit balance in each account. Fill in the other required data as you like (date opened, time stamp). The customer should be able to perform the following actions: Customer: 1. Get the current balance of funds in a specific account identified by the account ID value. 2. Get the total amount of funds across ALL accounts 3. Add money to an account specified by the ID 4. Retrieve money from an account specified by an ID Once you have built your Class Model, write your program to implement your class by outputting to standard output the following transactions: 1. Get balance into for your checking account. 2. Add $10 to both checking and saving account. 3. Retrieve $50 from your checking account. 4. Get the total available balance you now have in both accounts.Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <vector>
#include <ctime>
#include <sstream>
using namespace std;
int t_id = 1;
int a_id = 1;
int c_id;
enum Type{Credit, Debit};
enum a_Type{Checkin, Saving};
string get_time() {
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer,sizeof(buffer),"%d-%m-%Y %I:%M:%S",timeinfo);
string str(buffer);
return str;
}
class transaction {
int id;
float amount;
Type type;
string time_stamp;
public:
transaction(Type T, float Amount) {
id = t_id++;
type = T;
amount = Amount;
time_stamp = get_time();
}
void print_t() {
cout <<"Transaction Summary" << endl;
cout <<"T ID:" << id << endl;
cout << "T Type :" << "Debit" << endl;
cout <<"amount:" << amount << endl;
cout <<"Time:" << time_stamp << endl;
cout << " .................................... " << endl;
}
};
class account {
string name;
int id;
float balance;
a_Type a_type;
string date_opened;
vector <transaction> transactions;
public :
account(string name, a_Type t, float amount) {
name = name;
id = a_id++;
a_type = t;
transaction t(Credit, amount);
balance = amount;
t.print_t();
transactions.push_back(t);
}
float get_balance() {
return balance;
}
int get_id() {return id;}
void deposit(float amount) {
transaction t(Credit, amount);
transactions.push_back(t);
t.print_t();
balance += amount;
}
void withdraw(float amount) {
if (amount <= balance) {
transaction t(Debit, amount);
t.print_t();
transactions.push_back(t);
balance -= amount;
} else {
cout << "Insufficient Balance";
}
}
};
class customer {
string name;
int id;
string address;
vector <account> accounts;
public:
customer(string name, string address, float amount,a_Type type, int id) {
name = name;
address = address;
id = id;
accounts.push_back(account(name, Checkin, amount));
}
void add_account(float amount, a_Type type) {
cout << amount << endl;
accounts.push_back(account(name, type, amount));
}
void deposit(float amount, int id) {
for (int i = 0; i < accounts.size(); i++) {
if (accounts[i].get_id() == id) {
accounts[i].deposit(amount);
return;
}
}
cout << "Account not found ";
}
void withdraw(float amount, int id) {
for (int i = 0; i < accounts.size(); i++) {
if (accounts[i].get_id() == id) {
accounts[i].withdraw(amount);
return;
}
}
cout << "Account not found ";
}
float get_total() {
float sum = 0;
for (int i = 0; i < accounts.size(); i++) {
sum += accounts[i].get_balance() ;
}
return sum;
}
};
int main()
{
// type 1: checking 2: saving
string name = "john caq";
string address = "Albanda view";
customer c1(name, address, 100, Checkin, 1);
c1.add_account(100, Saving) ;
c1.deposit(10, 1);
c1.deposit(10,2);
c1.withdraw(50, 2);
cout << c1.get_total() << endl;;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.