Question

In: Computer Science

Please do this in C++ only. Please Show your code and your output too. Would you...

Please do this in C++ only. Please Show your code and your output too. Would you focus on number 2 in the Required functions:? Please use all the variables in the program.

The assignment problem:

You are asked to develop an application that prints a bank’s customers' names, IDs, and accounts balances in different ways. In this program, you need to read a file of customer’s data into different arrays, pass these arrays to functions as (array parameter), calculate the total balance for all customers, then print some information. The input file “input.txt” contains the following information (ID, first name, last name, savings account balance, checking account balance). You have to store these different columns in different arrays where each index represents customer data.


Preliminaries

1. We will consider the file contains 10 rows maximum. So all your arrays size must be at least 10.

2. Since the size of all the arrays is 10, so it is better to create a constant variable with the value 10 than hard coding the arrays size.

3. Create five different arrays with different types based on the data in the file (for ID, First, Last, saving, and checking)

4. Create a “switch” statement with four options and the output should be generated based on the chose option. Check the options below:

1. Print customer information

2. Print all customer Names ordered by their Last Name.

3. Print Bank’s total amount.

4. Enter q/Q to quit

Required functions:

1. A function “printCustomersData” should be called when the user chooses the first option. This function is of type void (it does not return anything). “printCustomersData” function should print a table of the customers data with the following order format: “LastName , First Name , ID , Saving Account, Checking Account.”

2. The function “printNames” will print the Names (first and last) of customers in alphabetic order by their last name.

3. The function “printBankTotal” that prints the summation of the balance of all customers saving account ($17410.31) and the summation of the balance of all customers checking accounts ($27430.01).


4. If the user entered something not in the options such as the letter ‘a’, the application should not be terminated. Instead, the application should print a message that tells the user that his/her input was incorrect, then the options should be displayed again, and the application should ask the user to enter another option.

5. The Menu options will be printed after each selection. Even when the user enters an invalid value. The only way to terminate the program is to enter ‘q’ or ‘Q’ which is the fourth option.

Hints:

1. Create an “if” statement to check if the file reading process went well. You can use many expressions such as: (!fin) or (fin.fail()), etc.

2. Use the function “setw(number)” that helps you to print the data in a shape of table. This function sets the number of spaces for each output. The function is in the <iomanip> library.

3. Save the whole project and zip it before uploading it to Canvas. (Do not submit only the ‘.cpp’ file and do not copy and paste your code to a ‘.txt’ file or Word file).

This what you will have in the “input.txt”

10 Homer Smith 810.2 101.10
20 Jack Stanely 100.0 1394.90
30 Daniel Hackson 333.90 7483.77
40 Sara Thomson 1930.02 4473.20
50 Thomas Elu 932.0 2334.30
60 Sam Carol 33.0 0.0
70 Tina Jefferson 334.90 777.5
80 Wael Lion 8843.2 88.90
90 Carol Smith 3994.09 2343.30
100 Jack Carlton 99.0 8433.04

Solutions

Expert Solution

The program is given below: that open file, read file into array, then print menu to user, take choice from user and continue until user enters Q/q, if user enter invalid option then print invalid and ask again, if user enter 1 then call printCustomersData() function that print customer data, if user enter 2 then call printNames() function that print first and lastname of customer in alphabetic order by last name, if user enter 3 then call printBankTotal() function that print sum of the balance of all customers saving account and sum of the balance of all customers checking accounts.

#include <iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<fstream>
using namespace std;
const int SIZE=10;
int ID[SIZE];
string First[SIZE],Last[SIZE];
float saving[SIZE],checking[SIZE];

//printCustomersData() function print customers data
void printCustomersData(int count)
{
int i;
cout<<left<<setw(10)<<"LastName"<<left<<setw(10)<<"First Name"<<left<<setw(10)<<"ID";
cout<<left<<setw(10)<<"Saving Account"<<left<<setw(10)<<"Checking Account.";
//execute for loop from 0 to count
for(i=0;i<count;i++)
{ //print data
cout<<"\n"<<left<<setw(10)<<Last[i]<<left<<setw(10)<<First[i]<<left<<setw(10)<<ID[i];
cout<<left<<setw(10)<<saving[i]<<left<<setw(10)<<checking[i];
}
}
//printNames() function print first and lastname of customer in alphabetic order by last name
void printNames(int c)
{
string val;
int i,min_Index;
string temp,temp1;
string new_lastname[10],new_fname[10];
cout<<"Print customers in alphabetic order by their last name.";
//execute for loop from 0 to c
for(i=0;i<c;i++)
{ //store values from last[i] into new_lastname[i] and First[i] into new_fname[i]
new_lastname[i]=Last[i];
new_fname[i]=First[i];
}
//sort data in alphabetic order by last name
for(i=0;i<c-1;i++)
{
for (int j=i+1; j<c; j++)
{
if (new_lastname[i]>new_lastname[j])
{
temp=new_lastname[i];
new_lastname[i]=new_lastname[j];
new_lastname[j]=temp;
temp1=new_fname[i];
new_fname[i]=new_fname[j];
new_fname[j]=temp1;
}
}
}
//print first and last name of sorted data in alphabetic order by last name
for(i=0;i<c;i++)
{
cout<<"\n"<<left<<setw(10)<<new_fname[i]<<left<<setw(10)<<new_lastname[i];
}
}
//printBankTotal() function print sum of the balance of all customers saving account
//and sum of the balance of all customers checking accounts.
void printBankTotal(int c)
{
int i;
float total_saving_acc=0,total_checking_acc=0;
//execute for loop from 0 to c
for(i=0;i<c;i++)
{ //perform sum
total_saving_acc=total_saving_acc+saving[i];
total_checking_acc=total_checking_acc+checking[i];
}
//print sum of the balance of all customers saving and checking account
printf("\nbalance of all customers saving account: $%.2f",total_saving_acc);
printf("\nbalance of all customers checking account: $%.2f",total_checking_acc);
}

int main()
{
  
ifstream fin;
char ch='a';
int count=0;
//open file
fin.open("input.txt");
  
//if file not opened
if(fin.fail())
{ //then print file not opened.
cout<<"\ncould not open file";
exit(1);
}

//read into arrays   
while(fin>>ID[count]>>First[count]>>Last[count]>>saving[count]>>checking[count])
{ //increment count by 1
count=count+1;
}
//close file
fin.close( );
  
//print menu
cout<<"\n1. Print customer information";
cout<<"\n2. Print all customer Names ordered by their Last Name.";
cout<<"\n3. Print Bank’s total amount.";
cout<<"\n4. Enter q/Q to quit\n";
//take choice from user
cin>>ch;
//continue until user enters q or Q
while(!(ch=='Q' || ch=='q'))
{
switch(ch)
{
//if ch is 1
case '1'://call printCustomersData() function
printCustomersData(count);
break;
//if ch is 2 the call printNames() function
case '2':printNames(count);
break;
//if ch is 3 then call printBankTotal() function
case '3':printBankTotal(count);
break;
//if ch is 4 then simply break
case '4':break;
//for any other choice print Inavalid option
default: cout<<"\nInvalid option ";
break;
}
//print menu
cout<<"\n1. Print customer information";
cout<<"\n2. Print all customer Names ordered by their Last Name.";
cout<<"\n3. Print Bank’s total amount.";
cout<<"\n4. Enter q/Q to quit\n";
//take choice from user
cin>>ch;
}
return 0;
}

The screenshot of code is given below:

Output:


Related Solutions

Please do this question in R and show the code too, please. The alternating current (AC)...
Please do this question in R and show the code too, please. The alternating current (AC) breakdown voltage of an insulating liquid indicates its dielectric strength. The article “Testing Practices for the AC Breakdown Voltage Testing of Insulation Liquids” (IEEE Electrical Insulation Magazine, 1995: 21–26) gave the accompanying sample observations on breakdown voltage (kV) of a particular circuit under certain conditions. 62 50 53 57 41 53 55 61 59 64 50 53 64 62 50 68 54 55 57...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials * * 2. Adding polynomials * * 3. Multiplying polynomials. * * 4. Displaying polynomials * * 5. Clearing polynomials. * * 6. Quit. * *********************************** Select the option (1 through 6): 7 You should not be in this class! ************************************* *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
********* Section C only. Please show your excel formula************** In addition to risk-free securities, you are...
********* Section C only. Please show your excel formula************** In addition to risk-free securities, you are currently invested in the Tanglewood Fund, a broad-based fund of stocks and other securities with an expected return of 11% and a volatility of 24%. Currently, the risk-free rate of interest is 4%. Your broker suggests that you add a venture capital fund to your current portfolio. The venture capital fund has an expected return of 22%, a volatility of 80%, and a correlation...
This question is about java program. Please show the output and the detail code and comment...
This question is about java program. Please show the output and the detail code and comment of the each question and each Class and interface. And the output (the test mthod )must be all the true! Thank you! Question1 Create a class Animal with the following UML specification: +-----------------------+ | Animal | +-----------------------+ | - name: String | +-----------------------+ | + Animal(String name) | | + getName(): String | | + getLegs(): int | | + canFly(): boolean | |...
APPLIED STATISTICS 2 PLEASE USE R, SHOW R CODE AND OUTPUT, with conclusion Let x<-c(1,2,3,4,5,6,7,8), y<-c(4,6,3,7,8,3,9,...
APPLIED STATISTICS 2 PLEASE USE R, SHOW R CODE AND OUTPUT, with conclusion Let x<-c(1,2,3,4,5,6,7,8), y<-c(4,6,3,7,8,3,9, 6.5). By vector operation (other method will get 0 point), find a). the equation of regression line, that is, find a, b. b). Find SSR, SSE c). Find F-value d). Find p-value e). Make your decision, that is, answer the question, can we say y and x have linear relationship at alpha=0.05?.
USING C++ ONLY. Please study the code posted below. the goal is to rewrite the code...
USING C++ ONLY. Please study the code posted below. the goal is to rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max capacity using namespace std; /** Queue structure definition */ struct QueueType { int data; struct QueueType *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT