﻿ C# exercises and solutions-min and max scores

# C# exercises and solutions-min and max scores

## C# structure: student records application

### Min and Max scores

Step9: Defining the showmax(student[] st, int itemcount) and showmin(student[] st, int itemcount) methods show about the student who gets the maximum score and the student who gets the minimum score. To find the highest total core or lowest total core, we need to compare every total score of each element.

static void showmax(student[] st, int itemcount)
{
float max = st[0].total;
int index=0;
Console.WriteLine(itemcount);
if (itemcount >= 2)
{

for (int j = 0; j < itemcount-1; ++j)
if (max < st[j+1].total) {
max = st[j+1].total;
index = j+1;

}

}

else if (itemcount == 1)
{
index = 0;
max = st[0].total;
}

else Console.WriteLine("Not record found!");

if (index != -1) Console.WriteLine("The student with ID:{0} gets the highest score {1}.", st[index].stnumber, max);

}
\

static void showmin(student[] st, int itemcount)
{

float min = st[0].total;
int index = 0;
if (itemcount >= 2)
{
for (int j = 0; j < itemcount-1; ++j)
if (min > st[j+1].total)
{
min = st[j+1].total;
index = j+1;

}

}

else if (itemcount == 1)
{
index = 0;
min = st[0].total;
}
else Console.WriteLine("No record found!");

if (index != -1) Console.WriteLine("The student with ID:{0} gets the lowest score {1}.", st[index].stnumber, min);

}
//method to find record
static void find(student[] st, int itemcount)
{
string id;
Console.Write("Enter student's ID:");

int index=search(st,id.ToString(),itemcount);
if (index != -1)
{
Console.Write("{0,-5}{1,-20}{2,-5}", st[index].stnumber, st[index].stname, st[index].sex);

Console.Write("{0,-5}{1,-5}{2,-5}", st[index].quizz1, st[index].quizz2, st[index].assigment);

Console.Write("{0,-5}{1,-5}{2,-5}", st[index].midterm, st[index].final, st[index].total);
Console.WriteLine();

}
else Console.WriteLine("The record deosn't exits.");

}

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.