Heres what I got to do. My program is getting a couple errors.(program at the en
ID: 3936833 • Letter: H
Question
Heres what I got to do. My program is getting a couple errors.(program at the end of question) I need to have the prototypes stuct then main and then the functions at the bottom . please help. I will post the description with the input.dat file data.
Write a program that declares a struct to store the following data of a NorthEast Bank customer :
Customer last name 10 characters (this will contain no spaces)
Customer type 1 character (valid values : D, E, P)
Checking Account number 4 digits
Savings Account number 4 digits
Credit Card account number 6 digits
Mortgage account number 5 digits
Declare an array of 10 components to store the data of 10 customers. The program must contain a function to input the data from a file (attached) and a function to output all the data. Also, there must be a function to find a customer by name and a function to find a customer by checking account number.
Lastly, a function must output all information for a specific customer.
The program is to load the data from the input file and then present the user with the following menu :
Welcome to the NEB Customer Lookup
a Lookup customer by checking account and output customer data
b Lookup customer by name account and output customer data
c. Output all customers data
d. Exit program
input.dat file
Meyers P 3823 2981 595844 38110
Raymonds E 1293 4982 598733 38444
Ganson D 4232 5964 596743 38561
Oshi E 4521 5900 598732 38120
Peters P 5013 2958 593723 38955
Mason D 5832 4927 598127 38912
My program with a couple of errors please run and fix thanks
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void output_customer(int );
void getMenuChoice(char );
int read_data(int *,string);
void output_data(int *,int);
void lookup_by_name(int *,int);
void lookup_by_checkings_account_number(int *, int);
struct customer{
string name;
char type;
int checkings_account_number;
int savings_account_number;
int credit_card_number;
int mortgate_account_number;
};
int main(){
cout << "Welcome to the NEB Customer Lookup" << endl;
char choice;
customer *arr = new customer[100];
int count = read_data(arr, "input.dat");
while(true){
choice = getMenuChoice();
if(choice == 'a')
lookup_by_checkings_account_number(arr, count);
else if(choice == 'b')
lookup_by_name(arr, count);
else if(choice == 'c')
output_data(arr, count);
else
return 0;
}
return 0;
}
int read_data(customer *arr, string fileName){
ifstream in(fileName.c_str());
int count = 0;
string name;
char type;
int checkings_account_number;
int savings_account_number;
int credit_card_number;
int mortgate_account_number;
if(in.is_open()){
while(in >> name >> type >> checkings_account_number >> savings_account_number >> credit_card_number >> mortgate_account_number){
arr[count].name = name;
arr[count].type = type;
arr[count].checkings_account_number = checkings_account_number;
arr[count].savings_account_number = savings_account_number;
arr[count].credit_card_number = credit_card_number;
arr[count].mortgate_account_number = mortgate_account_number;
++count;
}
in.close();
}
return count;
}
void output_customer(customer c){
cout << "Name: " << c.name << endl;
cout << "Type: " << c.type << endl;
cout << "Checkings account number: " << c.checkings_account_number << endl;
cout << "Savings account number: " << c.savings_account_number << endl;
cout << "Credit card number: " << c.credit_card_number << endl;
cout << "Mortgate account number: " << c.mortgate_account_number << endl << endl;
}
void lookup_by_name(customer *arr, int size){
string name;
cout << "Enter customer name: ";
cin >> name;
int ind = -1;
for(int i = 0; i < size; ++i){
if(arr[i].name == name){
ind = i;
break;
}
}
if(ind == -1)
cout << "Customer with name of " << name << " not found" << endl;
else
output_customer(arr[ind]);
}
void lookup_by_checkings_account_number(customer *arr, int size){
int number;
cout << "Enter checkings account number: ";
cin >> number;
int ind = -1;
for(int i = 0; i < size; ++i){
if(arr[i].checkings_account_number == number){
ind = i;
break;
}
}
if(ind == -1)
cout << "Customer with checkings account number of " << number << " not found" << endl;
else
output_customer(arr[ind]);
}
void output_data(customer *arr, int size){
for(int i = 0; i < size; ++i){
output_customer(arr[i]);
}
}
char getMenuChoice(){
char choice;
cout << "a. Lookup customer by checking account and output customer data" << endl;
cout << "b. Lookup customer by name account and output customer data" << endl;
cout << "c. Output all customers data" << endl;
cout << "d. Exit program" << endl;
while(true){
cout << "Enter your choice: ";
cin >> choice;
if(choice < 'a' || choice > 'd'){
cout << "Error. Invalid input. Try again!!" << endl;
}
else{
return choice;
}
}
}
Explanation / Answer
I have corrected all the error, you have to use same type of datatype in prototype definitions in the program. Please find the updated code.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void output_customer(int );
char getMenuChoice();
int read_data(struct customer *,string);
void output_data(struct customer *,int);
void lookup_by_name(struct customer *,int);
void lookup_by_checkings_account_number(struct customer *, int);
struct customer{
string name;
char type;
int checkings_account_number;
int savings_account_number;
long int credit_card_number;
long int mortgate_account_number;
};
int main(){
cout << "Welcome to the NEB Customer Lookup" << endl;
char choice;
customer *arr = new customer[100];
int count = read_data(arr,"input.dat");
while(true){
choice = getMenuChoice();
if(choice == 'a')
lookup_by_checkings_account_number(arr, count);
else if(choice == 'b')
lookup_by_name(arr, count);
else if(choice == 'c')
output_data(arr, count);
else
return 0;
}
return 0;
}
int read_data(customer *arr, string fileName){
ifstream in(fileName.c_str());
int count = 0;
string name;
char type;
int checkings_account_number;
int savings_account_number;
int credit_card_number;
int mortgate_account_number;
if(in.is_open()){
while(in >> name >> type >> checkings_account_number >> savings_account_number >> credit_card_number >> mortgate_account_number){
arr[count].name = name;
arr[count].type = type;
arr[count].checkings_account_number = checkings_account_number;
arr[count].savings_account_number = savings_account_number;
arr[count].credit_card_number = credit_card_number;
arr[count].mortgate_account_number = mortgate_account_number;
++count;
}
in.close();
}
return count;
}
void output_customer(customer c){
cout << "Name: " << c.name << endl;
cout << "Type: " << c.type << endl;
cout << "Checkings account number: " << c.checkings_account_number << endl;
cout << "Savings account number: " << c.savings_account_number << endl;
cout << "Credit card number: " << c.credit_card_number << endl;
cout << "Mortgate account number: " << c.mortgate_account_number << endl << endl;
}
void lookup_by_name(customer *arr, int size){
string name;
cout << "Enter customer name: ";
cin >> name;
int ind = -1;
for(int i = 0; i < size; ++i){
if(arr[i].name == name){
ind = i;
break;
}
}
if(ind == -1)
cout << "Customer with name of " << name << " not found" << endl;
else
output_customer(arr[ind]);
}
void lookup_by_checkings_account_number(customer *arr, int size){
int number;
cout << "Enter checkings account number: ";
cin >> number;
int ind = -1;
for(int i = 0; i < size; ++i){
if(arr[i].checkings_account_number == number){
ind = i;
break;
}
}
if(ind == -1)
cout << "Customer with checkings account number of " << number << " not found" << endl;
else
output_customer(arr[ind]);
}
void output_data(customer *arr, int size){
for(int i = 0; i < size; ++i){
output_customer(arr[i]);
}
}
char getMenuChoice(){
char choice;
cout << "a. Lookup customer by checking account and output customer data" << endl;
cout << "b. Lookup customer by name account and output customer data" << endl;
cout << "c. Output all customers data" << endl;
cout << "d. Exit program" << endl;
while(true){
cout << "Enter your choice: ";
cin >> choice;
if(choice < 'a' || choice > 'd'){
cout << "Error. Invalid input. Try again!!" << endl;
}
else{
return choice;
}
}
}