Question
--------------------------------------------------------------------------------------------- #ifndef LAB5_H_INCLUDED #define LAB5_H_INCLUDED #include #include typedef struct chk{ std::string name; int acountNo; float minimum_banlance; float over_limit_charge; float balance; void initialize(std::string name); void display();
---------------------------------------------------------------------------------------------
#ifndef LAB5_H_INCLUDED #define LAB5_H_INCLUDED
#include
#include
typedef struct chk{ std::string name; int acountNo; float minimum_banlance; float over_limit_charge; float balance; void initialize(std::string name); void display(); void deposit(float m); void withdraw(float m); }chk;
#endif // LAB5_H_INCLUDED
-------------------------------------------------------------------------------
/* * Lab5.cpp * * NAME: * STUDENT No: */
#include "Lab5_2.h" #include
using namespace std;
void chk::initialize(string n){ /* This function is for initializing structure member variables. Please set the variables to: minimum balance 1000; under limit fine 5 balance initialized to 0; assign user name from the argument n assign a random integer to account No */ name = n; acountNo = rand()%1000 + 1; //Random integer from 1 to 1000 balance = 0.0; minimum_banlance = 1000; over_limit_charge = 5.0; }
void chk::display(){ /* this function is for printing the content of the structure, using the following format User: John Jone Acount number: 50024077 Balance: 2999 */ cout
void chk::deposit(float m){ /* This function adds the m to the account balance */ balance = balance + m; }
void chk::withdraw(float m){ /* This function withdraw amount of money of m First please check if the balance is sufficient for this time withdraw, if not, print a message such as "There is not sufficent balance to withdraw!", and then exit the function (using return). Then check if the balance is already lower than the limitation, if yes, withdraw the amount of money m and apply the over limit charge, otherwise just withdraw. */ if(balance
------------------------------------------------------------------------------
#include "Lab5_2.h" #include
using namespace std;
int main(){ // create an acount chk chk1; int menu; float m; chk1.initialize("John Jone"); /* // input and select the menu, with the menu items as follows. Please select a function (0-3): 0---exit 1---display balance 2---deposit 3---withdraw using while loop keep receive menu input till encouting a 0. */ while(1){ // build the menu cout > menu; switch (menu){ case 0:return 0; case 1: //display the balance //here call display function chk1.display(); break; case 2: //deposit cout > m; //here call deposit function chk1.deposit(m); break; case 3: //withdraw cout > m; //here call withdraw function chk1.withdraw(m); break; } } return 0; }
---------------------------------------------------------------
Thank you for help my task 1-5
Access control, constructor and destructor, and overloading Description Write and execute C++ programs for the following purposes: Access control for member variables and functions Utilize constructor and destructor Explore constructor overloading Utilize default argument Task 1 Access control Based on Lab5, change the structure to class and add control access to class. Step : create a new project Lab6_1, copy and change the files Lab5_2.h, Lab5_2.cpp, and Lab5 2 test.cpp to Lab6_1.h, Lab6_1.cpp, and Lab6_1 test.epp and import them to the project Step 2: in Lab6_1.h, change the structure to class, add key word public to the four member functions and keep these member variables as default private. Change the corresponding directives in this head file. Step3: in Lab6_1.cpp, you only need to change the include file to include the proper the header. Step 4: in Lab6_1_test.cpp, you only need to change the include file to include the proper the header. Step 5: compile the project and run and test the program. Extra tests: ETI: in Lab61 test.cpp, line 12: after "chk l.initialize"John Jone"):", try add a sentence "chk1.name and compile and see what is the error information. Explain the reason. Task 2 Constructor Based on Taskl, change to use a constructor instead of using member function initialize. Step : create a new project Lab6_2, copy and change the files Lab6_1.h, Lab6_1.cpp, and Lab6_1 test.cpp to Lab6_2.h, Lab6_2.cpp, and Lab6_2 test.cpp and import them to the project. Step 2: in Lab6_2.h, delete the declaration of initialize function, instead adding a constructor with an argument with type of string. Note that the constructor should not have return type and use std::string for the argument if you do not want to use namespace in the head file. Change the corresponding directives in this header fileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started