Write a program that will first receive as input the name of an input file and an output file. It will then read in a list of names, id #s, and balances from the input file specified (call it InFile.txt) which you will create from the data provided below. The program will then prompt the user for a name to search for, when it finds the name it will output to a file (call it OFile.txt) the person’s id#, name, and balance. Please see the next page for the expected format of your output file. The program should prompt for another name until the word “done” is entered. Calculate and output the average of all balances for the found names.
Finally, create a header file for all your preprocessor directives, prototypes and constants as discussed in class. NOTE: For this assignment do not make the array size a GLOBAL constant, pass it as a parameter as necessary.
Your program will need the following functions:
1 – print heading function – prints your heading to
OFile.txt.
2 – input function - that will propagate the arrays (reads in all
the data) – you
will need 3 parallel arrays for this assignment (one for the names, one for the ids and one for the balances). This function should read all the data from InFile.txt.
3 – search function- this function will search for the name and return the proper index (of type int) to the calling function.
Programming language C++
// IFile.txt
Jean Rousseau
1001 15.50
Steve Woolston
1002 1423.20
Michele Rousseau
1005 52.75
Pete McBride
1007 500.32
Florence Rousseau
1010 1323.338
Lisa Covl
1009 332.356
Don McBride
1003 12.32
Chris Carroll
1008 32.356
Yolanda Agredano
1004 356.00
Sally Sleeper
1006 32.362
______________________
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
int search(string names[],string name,int cnt);
void printHeader(ofstream &dataOut);
void readData(ifstream &dataIn,string names[],int ids[],double
balArr[],int cnt);
int main() {
int cnt=0;
string fname,lname,name="";
int id;
double bal,tot=0,avg=0;
string infile,outfile;
//Setting the precision
cout<<setprecision(2)<<fixed<<showpoint;
//defines an input stream for the data file
ifstream dataIn;
//Defines an output stream for the data file
ofstream dataOut;
cout<<"What input file would you like to use ?";
cin>>infile;
//Opening the input file
dataIn.open(infile.c_str());
//checking whether the file name is valid or not
if(dataIn.fail())
{
cout<<"** File Not Found **";
return 1;
}
else
{
while(dataIn>>fname>>lname>>id>>bal)
{
cnt++;
}
dataIn.close();
// Creating array dynamically
string* names = new string[cnt];
int* ids = new int[cnt];
double* balArr = new double[cnt];
dataIn.open(infile.c_str());
readData(dataIn,names,ids,balArr,cnt);
cout<<"What output file would you like to use
?";
cin>>outfile;
//creating and Opening the output file
dataOut.open(outfile.c_str());
printHeader(dataOut);
cin.ignore();
cout<<"Who do you want to search for (enter done to
exit):";
getline(cin,name);
while(name.compare("done")!=0)
{
int indx=search(names,name,cnt);
if(indx==-1)
{
cout<<name<<" was not
found."<<endl;
}
else
{
dataOut<<ids[indx]<<"
"<<names[indx]<<"
"<<balArr[indx]<<endl;
tot+=balArr[indx];
cout<<"found."<<endl;
}
cout<<"Who do you want to search for (enter done
to exit):";
getline(cin,name);
}
//Closing the output file.
dataOut.close();
avg=tot/cnt;
cout<<"Average :"<<avg<<endl;
}
return 0;
}
void readData(ifstream &dataIn,string names[],int ids[],double
balArr[],int cnt)
{
string fname,lname;
int id;
double bal;
for(int i=0;i<cnt;i++)
{
dataIn>>fname>>lname>>id>>bal;
names[i]=fname+" "+lname;
ids[i]=id;
balArr[i]=bal;
}
dataIn.close();
}
void printHeader(ofstream &dataOut)
{
dataOut<<"Names found in input
file."<<endl;
}
int search(string names[],string name,int cnt)
{
for(int i=0;i<cnt;i++)
{
if(name.compare(names[i])==0)
{
return i;
}
}
return -1;
}
______________________
Output(Console):
_______________________
OFile.txt
_______________Could you plz rate me well.Thank
You
Write a program that will first receive as input the name of an input file and an output file. It will then read in a list of names, id #s, and balances from the input file specified (call it InFile.t...
c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...
Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do: 1. Add a new name 2. Change a name 3. Delete a name 4. Print the list or 5. Quit When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...
python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...
Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...