using System;
namespace ConsoleApplication1
{
class StudetCompare
{
static void Main(string[] args)
{
int x;
Student[] student = new Student[3];
for (x = 0; x < student.Length; ++x)
{
Console.Write("Student #{0} ID = ", x + 1);
int id = Convert.ToInt32(Console.ReadLine());
student[x].ID = id;
Console.Write("Name: ");
string name = Console.ReadLine();
student[x].Name = name;
Console.Write("GPA = ");
double gpa = Convert.ToDouble(Console.ReadLine());
student[x].GPA = gpa;
Console.WriteLine();
}
Console.WriteLine("Student #{0} ID = {1}, Name: {2}, GPA = {3}", student[x].ID, student[x].Name, student[x].GPA);
Console.ReadKey();
}
}
class Student : IComparable
{
public int ID { get; set; }
public string Name { get; set; }
public double GPA { get; set; }
public int CompareTo(Student student)
{
int returnVal;
if (this.ID > student.ID)
returnVal = 1;
if (this.ID < student.ID)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
}
}
/*
Student #1 ID = 200
Name: Maha
GPA = 2.9
Student #2 ID = 300
Name: Cad
GPA = 3.5
Student #3 ID = 100
Name: Tef
GPA = 4.6
Student #1 ID = 100, Name: Tef, GPA = 4.6
Student #2 ID = 200, Name: Maha, GPA = 2.9
Student #3 ID = 300, Name: Cad, GPA = 3.5
*/
VulpesPosted Dec 20, 2011, 4:51 AM
Posted Dec 20, 2011, 5:33 AM
Suthish NairPosted Dec 20, 2011, 2:56 AM