Question: Note: Code for both tasks should be written in single .cpp source file. Ask user which task to perform. Your code should exit after performing
Note: Code for both tasks should be written in single .cpp source file. Ask user which task to perform. Your code should exit after performing one task. Give error message in task 2 if file opening was failed as its possible that user ran task 2 first and there was no file there to read. (Observe whether your code works if you run task 2 consecutively multiple times, and write your observation as comments on top of your source(*.cpp) file ) Task1: File Writing: To store 4 lab scores of five students 1. Initialize 2D char arrays with full names by taking input from user, using cin.getline() function instead of simple cin. This 2D array holds the name record for all five student, where each row corresponds to one student. 2. Initialize 2D int type array for lab scores using rand() function with no lab score greater than 10. This 2D array hold score of total 4 labs of all 5 students. 3. Finally write the data into text file in the following format, where first row should be written as it is: First_Name Last_Name Lab1 Lab2 Lab3 Lab4 Name1 Lname1 10 7 6 3 Name2 Lname2 1 2 5 3 . . Name5 Lname5 3 2 5 9 Task2: Read Names and Lab scores from a file and find the student with highest total lab score. Declare different 2D arrays for this task. 1. Initialize 2D char type array of full names by reading it from a file, also initialize 2D int type array of lab scores by reading values from a file. 2. As each row corresponds to one student in both 2D arrays, find the student with highest score meaning find the row_index. 3. Finally close that file that you opened in read mode and open it again in write mode but with append mode. fstream file_obj; file_obj.open(file path,ios::app) Then move write pointer to the end of file using seekp(0,ios::end) Then write the student name with highest lab score and his/her score. So your file should look like the example given below after completing step 3. First_Name Last_Name Lab1 Lab2 Lab3 Lab4 Name1 Lname1 10 7 6 3 Name2 Lname2 1 2 5 3 . . Name5 Lname5 3 2 5 9 Student with highest score: Name1 Lname1 His/Her score: 25
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
