Average Marks of Lowest ID Student


Forum Post 2 Answers Average Marks of Lowest ID Student

Consider this C# Program. It reads lines from the standard input and and does some processing on them by calling processData.

The input is being read in from a file called input.txt, in this format:

22, Data Structures, 45
23, English, 52
22, English, 51
26, Data Structures, 72
23, Data Structures, 61
24, English, 81
Each line consists of three fields "Student ID," "Subject," and "Marks." "Student ID" and "Marks" are integers and "Subject" is a string that does not contain commas or newlines. There can be any number of students and up to 6 subjects.

Currently, the existing program reads the input, puts it into a data-structure, and calls a function/method processData on it. processData returns an integer that is printed to the output file. Unfortunately, processData currently does not do anything useful - it just returns 0.

You have to modify processData to compute the average marks scored across all subjects by the student with the lowest ID.

If your program is run with the input given above, it should print 48 because that is the average of the marks received by the student with ID 22 (which is the lowest ID).


Please make sure of the following:

Please download this C# Program and change it to create your program, and submit your changed program as your answer. If you try to write your own program from scratch, it will take longer, and will probably not work.
All your changes must be inside processData. Do not make any changes to the rest of the program
Make sure that processData returns the correct value
Do not print anything extra to the output. Any unnecessary output will result in a program disqualification.
Copy paste the entire updated program in the space below. You must submit a full, working, program. Please compile, run, and check the output of your program before submitting it.

Answers please using C# and follow this template:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

/* Don't change anything here.
* Do not add any other imports. You need to write
* this program using only these libraries
*/

namespace Program
{
public class Program
{

/* DO NOT CHANGE ANYTHING ABOVE THIS LINE */

private static int processData(IEnumerable<string> lines)
{
/*
* Do not make any changes outside this method.
*
* Modify this method to process `array` as indicated
* in the question. At the end, return the appropriate value
*
* Do not print anything in this method
*
* Submit this entire program (not just this function)
* as your answer
*/
return 0;
}

/* DO NOT CHANGE ANYTHING BELOW THIS LINE */

static void Main(string[] args)
{
try
{
int retVal = processData(File.ReadAllLines("input.txt"));
File.WriteAllLines("output.txt", new []{"" + retVal});
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}

}
}

- sk176214 December 30, 2021 | Flag |


Comment hidden because of low score. Click to expand.
0
of 0 vote

it was very helpful, thanks for your posting!

- James Horder January 22, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

CONTACT THE BEST LOTTERY SPELL CASTER FOR THE RIGHT LOTTERY NUMBERS NOW HIS LOTTERY SPELL IS 100% GUARANTEE

Winner of $533 million Mega Millions jackpot Richard Wahl, I want to share my wonderful testimony of how a powerful spell caster called Dr Prince helped me to win lottery, i have been playing lottery for a long time now but I had no luck everything changed when I messaged Dr Prince about winning the lottery he assured me that I will be the next winner he told me what to do and I did it and 24 hours later he sent me the lottery numbers and I played it I couldn't believe it I won $533 million dollars it's was the best thing that have ever happened to me in my life. If you want to win a lottery or email him at obinnaspelltemple@yahoo.com

- wahl211770 April 14, 2022 | Flag Reply




Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More