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

#include <iostream> #include <fstream> #include <string> #include <iomanip> #inc

ID: 3640627 • Letter: #

Question

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;

const int MAX = 50;


void ProcessCustomerInfo();
void LoadFile();
int GetUserSelection();
void DisplayMenu();
void PerformTask(double Balance[], int index, int selection);
void LoadID();
void LoadName();
void LoadBalance();


void AddBalance(double Balance[], int& index);
void DoTask1(double Balance[], int& index);
void DoTask2();
void DoTask3();
void DoTask4(double Balance[], int index);
void DoTask5();
bool TryAgain();

enum {Add_Customer = 1, Search_ID, Search_Name, Print_All, Exit};

int main()
{
do
{
ProcessCustomerInfo();

} while (TryAgain());

return 0;
}


void ProcessCustomerInfo()
{
//int ID[MAX];
double Balance[MAX];
int index = 0, selection;

/*for ( int i = 0; i < MAX ; i++)
{
Balance[i] = 0;
} */

//LoadFile();
selection = GetUserSelection();
PerformTask(Balance, index, selection);

}

void LoadFile()
{
LoadID();
LoadName();
LoadBalance();

}
void LoadID()
{
ifstream inFile;

string filename = "infile.dat";

inFile.open(filename.c_str());
if ( inFile.fail())
{
cout << "Input file opening failed. ";

//system("pause");
}

}

void LoadName()
{

}

void LoadBalance()
{

}

void PerformTask(double Balance[], int index, int selection)
{

switch (selection)
{
case Add_Customer : DoTask1(Balance, index); break;
case Search_ID : DoTask2(); break;
case Search_Name : DoTask3(); break;
case Print_All : DoTask4(Balance, index); break;
case Exit : DoTask5(); break;
}
}



void DoTask1(double Balance[], int& index)
{
AddBalance(Balance, index);
}


void AddBalance(double Balance[], int& index)
{
index = 0;
bool valid;

do
{
cout << "Balance ";
cin >> Balance[index];


if (cin.fail() || Balance[index] <= 0 )
{
cin.clear();
cin.ignore(1000, ' ');
cout << " **InValid input** try again";
valid = false;
}
else
{
//index++;
valid = true;
}
} while (!valid);
}


void DoTask2()
{
cout << "#2";
}

void DoTask3()
{
cout << "#3";
}

void DoTask4(double Balance[], int index)
{
cout << Balance[index] << endl;
}

void DoTask5()
{

}


int GetUserSelection()
{
int selection;
string userInput;

do
{
DisplayMenu();
cin >> selection;


} while( selection < 1 || selection > 5);

return selection;
}

void DisplayMenu()
{
cout << "1) Add Customer "
<< "2) Search by ID "
<< "3) Search by Name "
<< "4) Print All "
<< "5) Exit "
<< "Enter 1-5 ";
}

bool TryAgain()
{
char choice;
bool valid;

do
{
cout << " Do you want to try again (y)es or (n)o? ";
cin >> choice;
choice = toupper(choice);


if (choice == 'Y' || choice == 'N')
{
valid = true;

}
else
{
cout << " Please type yes or no. ";
valid = false;
cin.ignore(1000, ' ');
}
} while (!valid);

if (choice == 'Y')
{
return true;
}
else
{
return false;
}
}

/************************************************************
1) Add Customer
2) Search by ID
3) Search by Name
4) Print All
5) Exit
Enter 1-5
1
Balance 547

Do you want to try again (y)es or (n)o? y
1) Add Customer
2) Search by ID
3) Search by Name
4) Print All
5) Exit
Enter 1-5
4
-9.25596e+061 <------------------------------------------- Getting wrong output

Do you want to try again (y)es or (n)o?






*/

Explanation / Answer

PS: Please rate I see some problem in your code. Consider this void ProcessCustomerInfo() { //int ID[MAX]; double Balance[MAX]; int index = 0, selection; /*for ( int i = 0; i