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

C# Jagged Array of Exam Scores Dr. Hunter teaches three sections of her Intro to

ID: 3760880 • Letter: C

Question

C#
Jagged Array of Exam Scores

Dr. Hunter teaches three sections of her Intro to Computer Science class. She has
12 students in section 1, 8 students in section 2, and 10 students in section 3. In the
Chap07 folder of the Student Sample Programs, you will find the following files:
• Section1.txt—This file contains the final exam scores for each student in section 1.
Section1.txt contains: 87,93,72,98,65,70,89,78,77,66,92,72
• Section2.txt—This file contains the final exam scores for each student in section 2.
Section2.txt contains: 71,98,93,79,84,90,88,91
• Section3.txt—This file contains the final exam scores for each student in section 3.
Section3.txt contains: 88,81,56,72,69,74,80,66,71,73
Create an application that reads these three files and stores their contents in a jagged
array. The array’s first row should hold the exam scores for the students in section
1, the second row should hold the exam scores for the students in section 2, and the
third row should hold the exam scores for the students in section 3.
The application should display each section’s exam scores in a separate ListBox
control and then use the jagged array to determine the following:
• The average exam score for each individual section
• The average exam score for all the students in the three sections
• The highest exam score among all three sections and the section number in
which that score was found
• The lowest exam score among all three sections and the section number in
which that score was found

Explanation / Answer

private void button1_Click(object sender, EventArgs e) { StreamWriter section1; StreamWriter section2; StreamWriter section3; StreamReader section1read; StreamReader section2read; StreamReader section3read; section1 = File.CreateText("Section1.txt"); section2 = File.CreateText("Section2.txt"); section3 = File.CreateText("Section3.txt"); int[][] Scores = new int[3][]; Scores[0] = new int[12]; Scores[1] = new int[8]; Scores[2] = new int[10]; Random randnum = new Random(); for (int i = 0; i < 12; ++i) { int num = randnum.Next(55, 99); section1.WriteLine(num); } for (int j = 0; j < 8; ++j) { int num1 = randnum.Next(55, 99); section2.WriteLine(num1); } for (int k = 0; k < 10; ++k) { int num3 = randnum.Next(55, 99); section3.WriteLine(num3); } section1.Close(); section2.Close(); section3.Close(); section1read = File.OpenText("Section1.txt"); int nums = 0; while (!section1read.EndOfStream) { Scores[0][nums] = int.Parse(section1read.ReadLine()); ++nums; } for (int i = 0; i