I am admittedly very new to c++ and am working on a project, with which I am very stuck.
((I articulate that I am very new as I know this is a forum where most assume the posters know the basics. Please forgive me if I am missing something incredibly obvious.))
Program will read data from a file which includes student names and grades, and will prompt user to enter a student's name for grade information. Then the program will calculate said grades with respective scores and assignment percentages. Then this data will be used to calculate a final numerical grade. The program will then assign a letter grade based on the final numerical grade. Descriptive information will output regarding the student's grades.
I am running into issue with the grade values computing incorrectly (though we are given a specific formula to use verbatim), and gaining general understanding of what is wanted overall.
The instruction is to abide by these stipulations:
• Create an array of the structure in main to hold 10 components, i.e., an array of size 10.
• Using a function, open the input file, the output file for report and an error file to log errors. If any file fails to open, display a proper message to the customer and exit the program. Request the input and report file names from the user. The error file name may be a literal. Call the function from main.
• Using a function, close all files prior to program end. Call this function from main.
• Read the file and process the data via a function. This function will call the remaining functions EXCEPT the output/display function. Read until end of file. Do not “hard-code” the number of rows to read. Read the first name and last name into the student array data members. Since the array may hold more components than there is data, use and increment a counter to count how many rows “actually” read. Pass that counter into the output function.
• The other data for the student should be read into non-structure variables.
• There will be errors in the file, i.e., divide by zero. If a divide by zero error is encountered, do not calculate the numerical grade, lookup the final letter grade, lookup the comment or output the student grade information. Write an error to the error file indicating that the grade cannot be calculated for the student. Include the student name. If there is an error, set the student’s numerical grade to 0, letter grade to space (‘ ‘) and comment to “Error in Data”.
• Calculate numerical grade. Store the numerical grade in the student array data member. You may call this function from the read and process function.
• Look up the final letter grade using a function. Store the letter grade in the student array data member. You may call this function from the read and process function.
• Retrieve the comment via a function. Store the comment in the student array data member. You may call this function from the read and process function.
• Using a function, for each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns, set any floating-point numbers to 2 decimal places. Call this function from main.
after you tag it up, can you also explain what the input is, what the expected output is, what the actual output is, and if you know, where the incorrect output was produced (line #).
Take the bullet list from the instructions and paste it into your code as a comment. As you write your code, move the sentences/phrases from the instructions to the code that implements that part. Here are the instructions with some important pieces that you're missing underlined:
• Create an array of the structure in main to hold 10 components, i.e., an array of size 10.
• Using a function, open the input file, the output file for report and an error file to log errors. If any file fails to open, display a proper message to the customer and exit the program. Request the input and report file names from the user. The error file name may be a literal. Call the function from main.
• Using a function, close all files prior to program end. Call this function from main.
• Read the file and process the data via a function. This function will call the remaining functions EXCEPT the output/display function. Read until end of file. Do not “hard-code” the number of rows to read. Read the first name and last name into the student array data members. Since the array may hold more components than there is data, use and increment a counter to count how many rows “actually” read. Pass that counter into the output function.
• The other data for the student should be read into non-structure variables.
• There will be errors in the file, i.e., divide by zero. If a divide by zero error is encountered, do not calculate the numerical grade, lookup the final letter grade, lookup the comment or output the student grade information. Write an error to the error file indicating that the grade cannot be calculated for the student. Include the student name. If there is an error, set the student’s numerical grade to 0, letter grade to space (‘ ‘) and comment to “Error in Data”.
• Calculate numerical grade. Store the numerical grade in the student array data member. You may call this function from the read and process function.
• Look up the final letter grade using a function. Store the letter grade in the student array data member. You may call this function from the read and process function.
• Retrieve the comment via a function. Store the comment in the student array data member. You may call this function from the read and process function.
• Using a function, for each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns, set any floating-point numbers to 2 decimal places. Call this function from main.