Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

C# Programming Platform II Sorting Basics Assignment For this assignment you need to do the following: Step 1: Create a console application named yourname_sortingbasics. Make sure that you use a...

1 answer below »
C# Programming Platform II
Sorting Basics Assignment

For this assignment you need to do the following:
Step 1:
Create a console application named yourname_sortingbasics. Make sure that you use a windows
classic desktop console application/.Net Framework console application and not a .Net Core
console application.
Step 2:
Create a Student class that has the following:
a. StudentID, LastName, FirstName, CourseID and Course Grade properties.
. A constructor that collects the above property information.
c. A method that retrieves test data for this Student class. This method will use the following
code for testing purposes:

public static List getTestStudents()
{

For testing purposes some duplicate student infomation will be used.

XXXXXXXXXXList students = new Liststudents.Add(new Student(1, "Jones", "Joan", "art0024", 3.0));
students.Add(new Student(2, "Einstein", "Jose", "math0001", 3.3));
students.Add(new Student(5, "Gonzales", "Miranda", "cs0024", 2.7));
students.Add(new Student(4, "Lee", "Kim", "bs0024", 2.7));
students.Add(new Student(3, "Jaspers", "Rachel", "cs0001", 2.7));
students.Add(new Student(6, "gates", "Bill", "cs0001", 4.0));
students.Add(new Student(6, "Gates", "Bill", "art0024", 3.0));
students.Add(new Student(6, "Gates", "bill", "art0024", 1.0));
students.Add(new Student(7, "Allison", "George", "math0023", 2.7));
students.Add(new Student(7, "Allison", "Alice", "cs0001", 2.7));
students.Add(new Student(8, "Sills", "Carol", "cs0001", 1.7));
students.Add(new Student(8, "Sills", "Albert", "cs0001", 2.7));
students.Add(new Student(9, "Sta
", "Bert", "chem0020", 3.7));

XXXXXXXXXXreturn students;
}
d. Ove
ide the ToString method to dump out the cu
ent student test data situation (data will
sometimes be not sorted and then sorted various ways).
e. Support methods for adding a sort title and column headers for a report on your student
data. These methods will be used to display student data before and after various sorting
conditions.
Step 3:
In your main method test your Employee class with the following code:
List students = Student.getTestStudents();
Console.WriteLine(Student.SortTitle("Not Sorted"));
Console.WriteLine(Student.ColumnHeader());
foreach (Student student in students)
{
Console.WriteLine(student);
}
Console.WriteLine("\nPress to quit...");
Console.ReadKey();
You should see a data dump on the test student data similar to the following:

Note: Google string format operations to see what options you have in terms of using right hand
justification, left hand justification, PadLeft, PadRight, etc.
Step 4:
Modify your Student class to add a default last name, first name sort capability. The IComparable
interface is used typically to compare the cu
ent class instance with other instances of the same
type. To use this technique, you would add to the Student class the IComparable
interface:
public class Student : IComparableThe compiler will then warn you that you need to implement the interface member CompareTo.
Now implement the CompareTo method to allow sorting by last name and then first name. Note:
when doing name comparisons you usually uppercase all of the string characters first before
processing the sort options. Thus make sure you UpperCase first and last name so that no sort
differences with occur based on case differences.
Bill Gates versus bill Gates or bill gates.
10 points are scored if you co
ectly implement the CompareTo method to provide this last name,
first name sort capability.
To test your CompareTo method in your main method add the following code:
Sort using built in Student IComparer default sort...
Console.WriteLine(Student.SortTitle("Sorted by Last Name and First Name Using Built in
IComparable"));
Console.WriteLine(Student.ColumnHeader());
students.Sort();
foreach (Student s in students)
{
Console.WriteLine(s);
}
Your console screen should then show the following:

Note: Original data is preserved. However, you can output upper cased string data if you wish.
Step 5:
Now let’s examine the common situation of multiple sorts done on multiple sort fields. The
ICompare
T> interface is used when you want to compare 2 objects of the same type. It can be
implemented with nested classes or separate external classes. As an example let’s set up a
separate class called StuSortCourseGradeLastFirst that provides sorting capability on course
grade, then last name and first name:
Points scored for implementing co
ectly a sort by course grade, last name and then first name: 10
points
To test this sort add the following code to your Main method:
Console.WriteLine(Student.SortTitle("Sorted by Course Grade, Last Name, and then First Name
Using IComparer"));
Console.WriteLine(Student.ColumnHeader());
students.Sort(new StuSortCourseGradeLastFirst());
foreach (Student s in students)
{
XXXXXXXXXXConsole.WriteLine(s);
}
Step 6:
Now let’s sort your students by Last Name, First Name and then CourseID with another sort class
such as StuSortLastFirstCourseID.
Points: 10
Step 7:
Finally let’s sort your students by Last Name, First Name and then CourseID and then
CourseGrade you would just add another sort class such as
StuSortLastFirstCourseIDCourseGrade.
Points: 10
Step 8:
Save your work and run your application! When you finish your project put your zipped project in
the UCLA Module 2 application submission area. Remember that I need to run your project from
my machine so make sure your zipped project folder contains all of your work. Also note that we
are not using LINQ, SQL or Lambda expressions yet for a sorting technique. When we examine
functional programming, you are going to find that sorting becomes an extremely simple operation.
Total points for this project: XXXXXXXXXXpoints for each sort condition for a total of 4 sorts) with the
emainder of the points being distributed based upon project functionality, report formatting, coding
style, etc.
Answered Same Day Jul 07, 2021

Solution

Shweta answered on Jul 07 2021
143 Votes
87635/FloWang_sortingbasics/.vs/FloWang_sortingbasics/v16/.suo
87635/FloWang_sortingbasics/FloWang_sortingbasics/App.config




87635/FloWang_sortingbasics/FloWang_sortingbasics
in/Debug/FloWang_sortingbasics.exe
87635/FloWang_sortingbasics/FloWang_sortingbasics
in/Debug/FloWang_sortingbasics.exe.config




87635/FloWang_sortingbasics/FloWang_sortingbasics
in/Debug/FloWang_sortingbasics.pd
87635/FloWang_sortingbasics/FloWang_sortingbasics/FloWang_sortingbasics.csproj



Debug
AnyCPU
{259A06CF-19E4-48B8-9422-2092378C4F29}
Exe
FloWang_sortingbasics
FloWang_sortingbasics
v4.7.2
512
true
true


AnyCPU
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4


AnyCPU
pdbonly
true
bin\Release\
TRACE
prompt
4























87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/FloWang_sortingbasics.csproj.CoreCompileInputs.cache
99
595c81642432ace7375b95e0d409afb2bc9e
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/FloWang_sortingbasics.csproj.FileListAbsolute.txt
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\obj\Debug\FloWang_sortingbasics.csprojAssemblyReference.cache
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\obj\Debug\FloWang_sortingbasics.csproj.CoreCompileInputs.cache
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\bin\Debug\FloWang_sortingbasics.exe.config
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\bin\Debug\FloWang_sortingbasics.exe
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\bin\Debug\FloWang_sortingbasics.pd
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\obj\Debug\FloWang_sortingbasics.exe
C:\Users\Acer\source\repos\FloWang_sortingbasics\FloWang_sortingbasics\obj\Debug\FloWang_sortingbasics.pd
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/FloWang_sortingbasics.csprojAssemblyReference.cache
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/FloWang_sortingbasics.exe
87635/FloWang_sortingbasics/FloWang_sortingbasics/obj/Debug/FloWang_sortingbasics.pd
87635/FloWang_sortingbasics/FloWang_sortingbasics/Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FloWang_sortingbasics
{
class Program
{

Main method to call all the classess with sorted and non sorted data.
static void Main(string[] args)
{
List students = Student.getTestStudents();
Console.WriteLine(Student.SortTitle("Not Sorted\n"));
Console.WriteLine(Student.ColumnHeader());
foreach (Student student in students)
{
Console.WriteLine(student);
}

Console.WriteLine("\n\n");
Console.WriteLine(Student.SortTitle("Sorted by Last Name and First Name Using Built in IComparable\n"));
Console.WriteLine(Student.ColumnHeader());
students.Sort();
foreach (Student s in students)
{
Console.WriteLine(s);
}
Console.WriteLine("\n\n");
Console.WriteLine(Student.SortTitle("Sorted by Course Grade, Last Name, and then First Name Using ICompare\n"));
Console.WriteLine(Student.ColumnHeader());
students.Sort(new StuSortCourseGradeLastFirst());
foreach (Student s in students)
{
Console.WriteLine(s);
}
Console.WriteLine("\n\n");
Console.WriteLine(Student.SortTitle("Sorted by Last Name, First Name, and then Course ID Using IComparer\n"));
Console.WriteLine(Student.ColumnHeader());
students.Sort(new StuSortLastFirstCourseID());
foreach (Student s in students)
{
Console.WriteLine(s);
}
Console.WriteLine("\n\n");
Console.WriteLine(Student.SortTitle("Sorted by Last Name, First Name,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here