Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the code please answer this question in c++ Write the tests to the SavingsAccountType object to the driver.cpp file. Include only the necessary preprocessor

Using the code please answer this question in c++ Write the tests to the SavingsAccountType object to the driver.cpp file. Include only the necessary preprocessor directives, the driver function prototypes, the main function which includes the calls to the defined driver functions in exercises 3 through 4, and the driver function definitions themselves. To properly call the previously listed driver and member functions, the main function must declare all the appropriate variables as follows: A SavingsAccountType array that holds 5 accounts stored in a file The total cost of books purchased File input (Note: the name of the file is called accountsList.txt) Add a separate driver function definition to print the values of the SavingsAccountType array object to the console (called printAccountList). The main function should display the array and total bill for purchased books to the console.

Code-

#include #include

using namespace std;

class SavingsAccountType { private: int accountNumber; string firstName; string lastName; double amount; int daysOpen;

public: // Default constructor SavingsAccountType() { accountNumber = 0; firstName = "NA"; lastName = "NA"; amount = 0.0; daysOpen = 0; }

// Constructor with arguments SavingsAccountType(int accountNumber, string firstName, string lastName, double amount, int daysOpen) { this->accountNumber = accountNumber; this->firstName = firstName; this->lastName = lastName; this->amount = amount; this->daysOpen = daysOpen; }

// Setters (mutator functions) void setAccountNumber(int accountNumber) { this->accountNumber = accountNumber; } void setFirstName(string firstName) { this->firstName = firstName; } void setLastName(string lastName) { this->lastName = lastName; } void setAmount(double amount) { this->amount = amount; } void setDaysOpen(int daysOpen) { this->daysOpen = daysOpen; }

// Getters (accessor functions) int getAccountNumber() const { return accountNumber; } string getFirstName() const { return firstName; } string getLastName() const { return lastName; } double getAmount() const { return amount; } int getDaysOpen() const { return daysOpen; }

// Member function to print account information void print() { cout << "ID: " << accountNumber << endl; cout << "Name: " << lastName << ", " << firstName << endl; cout << "Savings amount: $" << amount << endl; }

// Member function to check if account has enough money to withdraw bool validate(double amount) { return (this->amount >= amount); }

// Member function to add 4% interest to account if it has been open for more than 30 days void interest() { if (daysOpen > 30) { amount += (amount * 0.04); } } };

int main() { // Create an account with the default constructor SavingsAccountType account1;

// Set the account information using the setters account1.setAccountNumber(123456); account1.setFirstName("Katherine"); account1.setLastName("Janeway"); account1.setAmount(1580.54); account1.setDaysOpen(45);

// Print the account information account1.print();

// Check if the account has enough money to withdraw $500 if (account1.validate(500.0))

cout << "Account has enough money to withdraw $500." << endl; cout << "Account does not have enough money to withdraw $500." << endl;}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions