In: Computer Science
IN C# lang
Write a console app (review Module 5 for console app) that stores 3 students test stores in 3 separate arrays as integers. Some did not not take all the tests, so they each have a their own length and we use separate arrays.
Declare and initialize each array. Use meaningful names.
Print each array as follows:
Morgan 98, 72, 65 Bowie 15, 47, 35, 92, 94 Ananya 91, 68, 87, 75 |
Extra credit: Compute the average for each with reusable code (do not have 3 separate pieces of code for the average) This is worth up to 3 points.
Extra extra credit: Ask the user to input the test scores. This is worth up to 2 points.
Submit zipped file. File name is
LastName_M07_ArrayBasics.zip
using System; class MainClass { public static double avg(int[] arr) { double sum = 0; for(int i=0; i<arr.Length; i++) { sum += arr[i]; } return sum/arr.Length; } public static void Main (string[] args) { string[] names = { "Morgan" , "Bowie", "Ananya" }; int[] score1 = {98, 72, 65}; int[] score2 = {15, 47, 35, 92, 94}; int[] score3 = {91, 68, 87, 75}; Console.WriteLine("Average of " + names[0] + " is " + avg(score1)); Console.WriteLine("Average of " + names[1] + " is " + avg(score2)); Console.WriteLine("Average of " + names[2] + " is " + avg(score3)); } }
Please upvote, as i have given the exact answer as asked in
question. Still in case of any concerns in code, let me know in
comments. Thanks!