Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q2 const in class Based on lab 6, change the accountNo to constant member variab

ID: 3893669 • Letter: Q

Question

Q2 const in class
Based on lab 6, change the accountNo to constant member variable and change constructors correspondently. Name the program files as Ass6_2.h, Ass6_2.cpp, and Ass6_2_test.cpp.
Note, to simplify the problem, let’s remove all overloaded constructors but leave “chk(std::string,int no);”.

// Ass6_2.h, Ass6_2.cpp, Ass6_2_test.cpp, inline.cpp.


Q3 In-line functions
Based on Q2, change the constructor chk(std::string,int no) and member functions display and deposit into in-line functions.

/*
* Lab6_3_test.cpp
* NANE:
* STUDENT NUMBER:
*/
#include "Lab6_3.h"
#include <iostream>
using namespace std;
int main(){
    // create an acount
    //chk chk1;
    //chk chk1("Jone John");
    chk chk1("Jone John",1234,1000,2,300);
    // input and select the menu
    while(1){
        // build the menu
        int menu;
        cout << "Please select a function (0-3): " << endl;
        cout << "0---exit " << endl;
        cout << "1---display balance " << endl;
        cout << "2---deposit " << endl;
        cout << "3---withdraw " << endl;
        cout << "4---withdraw with a special fine " << endl;
        cin >> menu;
        switch (menu){
            case 0:return 0;
            case 1:
                //display the balance
                chk1.display("CIBC");
                break;
            case 2:
                float m;
                cout << "Input the amount of cash you want ot deposit: " << endl;
                cin >> m;
                chk1.deposit(m);
                break;
            case 3:
                cout << "Input the amount of cash you want ot withdraw: " << endl;
                cin >> m;
                chk1.withdraw(m);
                break;
            case 4:
                cout << "Input the amount of cash you want ot withdraw: " << endl;
                cin >> m;
                float sfine;
                cout << "Input the special fine rate: " << endl;
                cin >> sfine;
                chk1.withdraw(m,sfine);
                break;
    }
    }
}

/*
* Lab6_3.cpp
*
*
* NAME:
* STUDENT No:
*/
#include "Lab6_3.h"
#include <stdlib.h>
#include <time.h>

using namespace std;

chk::chk(){
    cout << "Please enter the user name (Without space): ";
    cin >> name;
    minimum_banlance = 1000;
    over_limit_charge = 5;
    balance = 0;
    srand(time(NULL));
    acountNo = rand();
}
chk::chk(string n){
    name = n;
    minimum_banlance = 1000;
    over_limit_charge = 5;
    balance = 0;
    srand(time(NULL));
    acountNo = rand();
}
chk::chk(string n, int no){
    name = n;
    acountNo = no;
    minimum_banlance = 1000;
    over_limit_charge = 5;
    balance = 0;
}
chk::chk(string n, int no, float mb){
    name = n;
    acountNo = no;
    minimum_banlance = mb;
    over_limit_charge = 5;
    balance = 0;
}
chk::chk(string n, int no, float mb, float olc, float ini_balance){
    name = n;
    acountNo = no;
    minimum_banlance = mb;
    over_limit_charge = olc;
    balance = ini_balance;
}
void chk::display(){
    cout << "User: " << name << endl;
    cout << "Acount number: " << acountNo << endl;
    cout << "Balance: " << balance << endl;
}
void chk::display(string bankname){
    cout << "Bank name: " << bankname << endl;
    cout << "User: " << name << endl;
    cout << "Acount number: " << acountNo << endl;
    cout << "Balance: " << balance << endl;
}
void chk::deposit(float m){
    balance += m;
}
void chk::withdraw(float m){
    if (balance < m){
        cout << "There is not sufficent balance to withdraw!";
        return;
    }
    balance -= m;
    if (balance < minimum_banlance)
        balance -= over_limit_charge;
}
void chk::withdraw(float m, float special){
    if (balance < m){
        cout << "There is not sufficent balance to withdraw!";
        return;
    }
    balance -= m;
    if (balance < minimum_banlance)
        balance -= special; //apply special over limit rate here
}

/*
* Lab6_3.h
*
* Created on: Sep 11, 2017
* NAME:
* STUDENT No:
*/

#include <iostream>
#include <string>

class chk{
    std::string name;
    int acountNo;
    float minimum_banlance;
    float over_limit_charge;
    float balance;
public:
    chk();
    chk(std::string);
    chk(std::string,int no);
    chk(std::string,int no, float mb);
    chk(std::string,int no, float mb,float olc, float ini_balance = 0);
    void display();
    void display(std::string bank);
    void deposit(float m);
    void withdraw(float m);
    void withdraw(float m, float special); //apply special over limit charge
};

Explanation / Answer

#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct Bank_Account
{
    int account_no;
    char first_name[80];
    char LastName[80];
    char User_id[80];
   char Password[80];
   int balance;
};
class Account{
   public:
       string username,Password;
       double balance;
       Account(string username,string Password)
       {
           this->username=username;
           this->Password=Password;
           balance=0;
       }
   public:
   int getUserName(char uname[],char pass[],struct Bank_Account array[],int size)
   {
       int index;
       for(index=0;index<size;index++)
       {
           if (!(strcmp(array[index].User_id,uname)))
           {
               return 1;
           }  
       }
        return -1;
   }
   void currentBalance(struct Bank_Account array[], int size, int Account_number)
   {
       int index;
       index=Search_Account(array, size, Account_number);
       if(index==-1)
       {
             cout<<" **** Data Not Found:****"<<endl;
       }  
       else
       {
           balance=array[index].balance;
           cout<<" The Available Balance is: "<<balance<<endl;
       }
   }
   void Read_Data(struct Bank_Account list[], int size)
   {
       int i;
       for(i=0;i<size;i++)
       {
           cout<<" ------------------------------"<<endl;
           cout<<" Please Record Person "<<i+1<<" Details"<<endl;
           list[i].account_no=i+1;
           fflush(stdin);
           cout<<"Enter the FirstName: "<<endl;
           gets(list[i].first_name);
           cout<<"Enter the LastName: "<<endl;
           gets(list[i].LastName);
           cout<<" Please Create Userid:"<<endl;
           gets(list[i].User_id);
           cout<<" Please Create your Password"<<endl;
           gets(list[i].Password);
           list[i].balance = 100;
           cout<<" Your Account Number is: "<<list[i].account_no<<endl;
       }
   }
   void Display_Record(struct Bank_Account array[], int size)
   {
       int index;
       cout<<" A/c Number: Name: Balance:"<<endl;
       for(index=0;index<size;index++)
       {
              cout<<array[index].account_no<<" "<<array[index].first_name<<" "<<array[index].balance<<endl;
       }
   }

   int Search_Account(struct Bank_Account array[], int size, int Account_number)
   {
       int index;
       for(index=0;index<size;index++)
       {
           if (array[index].account_no == Account_number)
           {
               return index;
           }  
       }
        return - 1;
   }
   void Deposit(struct Bank_Account array[], int size, int Account_number, int Amount)
   {
       int index;
       index=Search_Account(array, size, Account_number);
       if(index==-1)
       {
             cout<<" **** Data Not Found:****"<<endl;
       }  
       else
       {
           array[index].balance=array[index].balance+Amount;
       }
   }
   void withdrawal(struct Bank_Account array[], int size, int Account_number, int Amount)
   {
       int index;
       index=Search_Account(array, size, Account_number);
       if(index==-1)
       {
              cout<<" **** Data Not Found:****"<<endl;
       }  
       else
       {
           if (array[index].balance<Amount)
           {
               cout<<"Insufficient balance "<<endl;
           }
           else
           {
               array[index].balance=array[index].balance-Amount;
           }
       }
   }
      
};
using namespace std;
int main()
{
    struct Bank_Account array[10];
    Account obj("venky","Venky@547");
    int size, option, account_no, amount;
    int retval,position;
    char Username[100],Password[100];
   cout<<" ----------------------------------"<<endl;
    cout<<" **** Welcome to Banking System*****"<<endl;
    cout<<" Please Read Number of customer records you want to Store:"<<endl;
    cin>>size;
    obj.Read_Data(array, size);
    do{
       cout<<" Please Login to your account with Password Credentials"<<endl;
        cout<<" Please Enter UserName"<<endl;
        cin>>Username;
       cout<<" Please Enter the Password"<<endl;
        cin>>Password;
        retval=obj.getUserName(Username,Password,array,size);
        if(retval==-1)
        {
                cout<<" !invalid username or password please try again "<<endl;
        }
    }while(retval==-1);
    while(1)
    {
       cout<<" ----------------------------------"<<endl;
       cout<<" ****** MENU ********"<<endl;
        cout<<" 1.To view Their Account Balance"<<endl;
        cout<<" 2.To deposit amount"<<endl;
        cout<<" 3.To withdraw amount"<<endl;
        cout<<" 4.Display Account Holder Details"<<endl;
        cout<<" 5.Exit/Logout:"<<endl;
        cout<<" Select Any Option "<<endl;
        cin>>option;
        switch (option)
        {
            case 1:
               cout<<" Please Enter your account number:"<<endl;
                cin>>account_no;
                obj.currentBalance(array, size,account_no);
                break;
            case 2:
                cout<<" Please Enter your account number:"<<endl;
                cin>>account_no;
                cout<<" Please Enter amount to deposit:"<<endl;
                cin>>amount;
                obj.Deposit(array, size, account_no, amount);
                break;
            case 3:
                cout<<" Please Enter your account number:"<<endl;
                cin>>account_no;
                cout<<" Please Enter amount to withdraw:"<<endl;
                cin>>amount;
                obj.withdrawal(array, size, account_no, amount);
                break;
            case 4:
               cout<<" Please Enter account number to search"<<endl;
                cin>>account_no;
                retval = obj.Search_Account(array, size, account_no);
                position=retval;
                if (retval == - 1)
                {
                   cout<<" No Record Found"<<endl;
                }
                else
                {
                   cout<<" A/c Number: Name: Balance: "<<endl;
                   cout<<array[position].account_no<<" "<<array[position].first_name<<" "<<array[position].balance<<endl;
                }
                break;
            case 5:
               exit(0);
        }
    }

    return 0;
}