CMPS358 Project2


Category: You will Instantly receive a download link for .zip solution file upon Payment


5/5 - (2 votes)

Average University requires all incoming students to take the course “Becoming an Average Student”. At
the end of the semester, all grades in the course are collected in a text file called – appropriately enough –
“grades.txt”. Each line in the file contains the grades of one student in the course and is organized as


The names are strings. Exam grades are integers in the range of 0 to 100. (Of course, in a text file, the
entire file can be considered a string, just as every line of data can be considered a single string.)
Your job will be to create C# solution to process the data in the file “grades.txt”. First, in Visual Studio
Code, create a project and name it “p2_your-ulid”. Then, download and copy the file “grades.txt” into the
main project folder. Finally, write the C# code to:

1. Read in all data in the file “grades.txt”.

2. From the data read in, calculate the rounded average grade for each student and output this
information to the text file “averages.txt”. Each line of the file will contains the average of one
student and will be organized as follows:


3. Convert the data read in to XML and store it in the file “grades.xml”.

Tips and Suggestions

• The example “Chapter09/WorkingWithStreams” (as used in class and available via the link given on
‘Moodle Example code for “C# 9 and .NET 5″ by Mark J. Price’) is an excellent source of example
code for this assignment.

• Using ReadAllText with a split on the end-of-line character is an easy way to organize the lines of
data in the file into an array. Caveat: This can produce an array with an empty string (a string with
length of zero) at the end, so be sure and compensate or check for this before using the data in an
element of the array.

• Use of Split on a comma on an element on the string containing one line will produce an array of
strings. Using Parse (for instance: Double.parse) can be used to convert the exam grades to a
numeric type.

• Each time a call is made to WriteStartElement(“element-name”), a new element that contain sub
elements is created. Calling WriteEndElement ends the element established by the preceding call to

• The brave can use the XML serialization techniques as shown in

Example data taken from “grades.txt”


Example of output to “averages.txt”

Example of output to “grades.xml”
<?xml version=”1.0″ encoding=”utf-8”?>


General requirements:

• Use of Combine(CurrentDirectory, “file-name”) to create file paths that end in the main folder /
directory of the project is required for all files.

• At the top of each file containing your C# code, insert the following comments:

// your-name

// your-ulid

// CMPS 358

// project #the-number-of-the-project


When the project runs correctly, clean the project, zip the project folder and upload it in Moodle. The
zip archive name must be the same the required project name (with “.zip” on the end, of course).