Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please program with c++ Write a complete program that: 1. Prompts the user for a filename and reads the filename into a string. 2. Opens

please program with c++ image text in transcribed
Write a complete program that: 1. Prompts the user for a filename and reads the filename into a string. 2. Opens the file name from (1) into an if stream variable and verifies that it opened. If the file does not open the program should output an error and continue from (1). a. The file contains 2 columns, one of names and another of numbers(scores). These are to be read into 2 parallel arrays. The file contains at max 100 values (This means for this lab you should just use 2 arrays with a static size of 100). 3. Prompts the user to enter a name and reads a name into a string variable (referred to as toFind in this pdf). 4. Reads the names and numbers (scores) from the file opened in (2) into 2 parallel arrays. To do this you will need to read in from your ifstream object to a 1d array called names and a ld array called scores using a while loop that terminates when the end of the file is hit. Note: Make sure to keep track of how many nameumber combinations are read in as you read from the file. Note: You can assume all data in the file is correct, that is no error checking is needed while reading from the file. 5. Prints both arrays from (4) forwards by iterating from the first element to the last element of the 2 arrays. 6. Prints both arrays from (4) backwards by iterating from the last element to the first element of the 2 arrays. 7. Calculates the minimum, maximum, sum, and average of toFind's scores held in the scores array. To do this: a. Initialize a double sum to 0.0 . b. Initialize some integers: min to 0 , max to 0 , and foundCnt to 0 . c. Iterate over the elements of the names and scores arrays at the same time: i. Check if the current element in names is equal to toFind. - If they are equal then add the element in scores at the same index to your sum and increment foundCnt. Then you will need to check if the score you are currently checking is the new min or max by checking if the current score is less than or greater than the score at the index currently held in min and max. If it is, save the index of the score you are looking at currently in either your min or max variable (whichever is appropriate). - Otherwise continue to (ii) ii. Continue from (i) until you have checked every index. Note: If the entered user is not found then foundCnt will be 0 . 8. Outputs the foundCnt, min, max, sum, and avg score found if one was found, and an error message if one is not found. Your program should be able to attempt to open any file name the user enters and should not statically open a file name. You must read your data from the input files into two parallel single dimensional arrays, failing to do so will result in you receiving a 0 for this lab. Output values should be set to a precision of 2 . See the example output for examples and formatting

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

What's your favorite kind of weather?

Answered: 1 week ago

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago