I have student History it will help you by using that you can convert that into your problem
using System;
//Write a C# program to keep records and perform statistical analysis for a class of 20 students. The information of each student contains ID, Name, Sex, quizzes Scores (2 quizzes per semester), mid-term score, final score, and total score.
//The program will prompt the user to choose the operation of records from a menu as shown below:
//========================================================
// MENU
//========================================================
//1. Add student records
// 2. Delete student records
// 3. Update student records
// 4. View all student records
// 5. Calculate an average of a selected student’s scores
// 6. Show student who gets the max total score
// 7. Show student who gets the min total score
// 8. Find student by ID
//9. Sort records by total scores
// Enter your choice:1
// Note: All students records are stored in an array of structures
namespace Student_History
{
class program
{
struct Student
{
public string StdNumber;
public string StdName;
public string sex;
public float Quizz1;
public float Quizz2;
public float Assigment;
public float Midterm;
public float Final;
public float Total;
};
static void Main(string[] args)
{
try
{
Student[] Std = new Student[20];
int itemcount = 0;
DisplayMenu();
int yourchoice;
string confirm;
do
{
Console.Write("Enter your choice(1-9):");
yourchoice = int.Parse(Console.ReadLine());
switch (yourchoice)
{
case 1: Add(Std, ref itemcount); break;
case 2: delete(Std, ref itemcount); break;
case 3: update(Std, itemcount); break;
case 4: viewall(Std, itemcount); break;
case 5: average(Std, itemcount); break;
case 6: showmax(Std, itemcount); break;
case 7: showmin(Std, itemcount); break;
case 8: find(Std, itemcount); break;
case 9: bubblesort(Std, itemcount); break;
default: Console.WriteLine("invalid"); break;
}
Console.Write("Press y or Y to continue:");
confirm = Console.ReadLine().ToString();
} while (confirm == "y" || confirm == "Y");
}
catch (FormatException f)
{
Console.WriteLine("Invalid input");
}
Console.ReadLine();
}
static void DisplayMenu()
{
Console.WriteLine("========================================= ");
Console.WriteLine(" MENU ");
Console.WriteLine("========================================= ");
Console.WriteLine(" 1.Add student records");
Console.WriteLine(" 2.Delete student records");
Console.WriteLine(" 3.Update student records");
Console.WriteLine(" 4.View all student records");
Console.WriteLine(" 5.Calculate an average of a selected student's scores");
Console.WriteLine(" 6.Show student who get the max total score");
Console.WriteLine(" 7.Show student who get the min total score");
Console.WriteLine(" 8.Find a student by ID");
Console.WriteLine(" 9.Sort students by TOTAL");
}
static void Add(Student[] Std, ref int itemcount)
{
Again:
Console.WriteLine();
Console.Write("Enter Student ID:");
Std[itemcount].StdNumber = Console.ReadLine().ToString();
if (Search(Std, Std[itemcount].StdNumber, itemcount) != -1)
{
Console.WriteLine("This ID already exists.");
goto Again;
}
Console.Write("Enter student's Name:");
Std[itemcount].StdName = Console.ReadLine().ToString();
Console.Write("Enter student's Sex(F or M):");
Std[itemcount].sex = Console.ReadLine().ToString();
Console.Write("Enter student's Quizz1 score:");
Std[itemcount].Quizz1 = float.Parse(Console.ReadLine());
Console.Write("Enter student's Quizz2 score:");
Std[itemcount].Quizz2 = float.Parse(Console.ReadLine());
Console.Write("Enter student's Assigment score:");
Std[itemcount].Assigment = float.Parse(Console.ReadLine());
Console.Write("Enter student's mid term score:");
Std[itemcount].Midterm = float.Parse(Console.ReadLine());
Console.Write("Enter student's final score:");
Std[itemcount].Final = float.Parse(Console.ReadLine());
Std[itemcount].Total = Std[itemcount].Quizz1 + Std[itemcount].Quizz2 + Std[itemcount].Assigment + Std[itemcount].Midterm + Std[itemcount].Final;
++itemcount;
}
static void delete(Student[] Std, ref int itemcount)
{
string id;
int index;
if (itemcount > 0)
{
Console.Write("Enter student's ID:");
id = Console.ReadLine();
index = Search(Std, id.ToString(), itemcount);
if ((index != -1) && (itemcount != 0))
{
if (index == (itemcount - 1))
{
clean(Std, index);
--itemcount;
Console.WriteLine("The record was deleted.");
}
else
{
for (int i = index; i < itemcount - 1; i++)
{
Std[i] = Std[i + 1];
clean(Std, itemcount);
--itemcount;
}
}
}
else Console.WriteLine("The record doesn't exist. Check the ID and try again.");
}
else Console.WriteLine("No record to delete");
}
static void update(Student[] Std, int itemcount)
{
string id;
int column_index;
Console.Write("Enter student's ID:");
id = Console.ReadLine();
Console.Write("Which field you want to update(1-7)?:");
column_index = int.Parse(Console.ReadLine());
int index = Search(Std, id.ToString(), itemcount);
if ((index != -1) && (itemcount != 0))
{
if (column_index == 1)
{
Console.Write("Enter student's Name:");
Std[index].StdName = Console.ReadLine().ToString();
}
else if (column_index == 2)
{
Console.Write("Enter student's Sex(F or M):");
Std[index].sex = Console.ReadLine().ToString();
}
else if (column_index == 3)
{
Console.Write("Enter student's quizz1 score:");
Std[index].Quizz1 = float.Parse(Console.ReadLine());
}
else if (column_index == 4)
{
Console.Write("Enter student's quizz2 score:");
Std[index].Quizz2 = float.Parse(Console.ReadLine());
}
else if (column_index == 5)
{
Console.Write("Enter student's assigment score:");
Std[index].Assigment = float.Parse(Console.ReadLine());
}
else if (column_index == 6)
{
Console.Write("Enter student's mid term score:");
Std[index].Midterm = float.Parse(Console.ReadLine());
}
else if (column_index == 7)
{
Console.Write("Enter student's final score:");
Std[index].Final = float.Parse(Console.ReadLine());
}
else Console.WriteLine("Invalid column index");
Std[index].Total = Std[index].Quizz1 + Std[index].Quizz2 + Std[index].Assigment + Std[index].Midterm + Std[index].Final;
}
else Console.WriteLine("The record deosn't exits.Check the ID and try again.");
}
static void viewall(Student[] Std, int itemcount)
{
int i = 0;
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "0", "1", "2", "3", "4", "5", "6", "7", "8");
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "ID", "NAME", "SEX", "Q1", "Q2", "As", "Mi", "Fi", "TOTAL");
Console.WriteLine("==================================================================");
while (i < itemcount)
{
if (Std[i].StdNumber != null)
{
Console.Write("{0,-5}{1,-20}{2,-5}", Std[i].StdNumber, Std[i].StdName, Std[i].sex);
Console.Write("{0,-5}{1,-5}{2,-5}", Std[i].Quizz1, Std[i].Quizz2, Std[i].Assigment);
Console.Write("{0,-5}{1,-5}{2,-5}", Std[i].Midterm, Std[i].Final, Std[i].Total);
Console.Write("\n");
}
i = i + 1;
}
}
static void average(Student[] Std, int itemcount)
{
string id;
float avg = 0;
Console.Write("Enter students'ID:");
id = Console.ReadLine();
int index = Search(Std, id.ToString(), itemcount);
if (index != -1 && itemcount > 0)
{
Std[index].Total = Std[index].Quizz1 + Std[index].Quizz2 + Std[index].Assigment + Std[index].Midterm + Std[index].Final;
avg = Std[index].Total / 5;
}
Console.WriteLine("The average score is {0}.", avg);
}
static void showmax(Student[] Std, int itemcount)
{
float max = Std[0].Total;
int index = 0;
Console.WriteLine(itemcount);
if (itemcount >= 2)
{
for (int j = 0; j < itemcount - 1; ++j)
if (max < Std[j + 1].Total)
{
max = Std[j + 1].Total;
index = j + 1;
}
}
else if (itemcount == 1)
{
index = 0;
max = Std[0].Total;
}
else Console.WriteLine("Not record found!");
if (index != -1) Console.WriteLine("The student with ID:{0} gets the highest score {1}.", Std[index].StdNumber, max);
}
static void showmin(Student[] Std, int itemcount)
{
float min = Std[0].Total;
int index = 0;
if (itemcount >= 2)
{
for (int j = 0; j < itemcount - 1; ++j)
if (min > Std[j + 1].Total)
{
min = Std[j + 1].Total;
index = j + 1;
}
}
else if (itemcount == 1)
{
index = 0;
min = Std[0].Total;
}
else Console.WriteLine("No record found!");
if (index != -1) Console.WriteLine("The student with ID:{0} gets the lowest score {1}.", Std[index].StdNumber, min);
}
static int Search(Student[] Std, string id, int itemcount)
{
int found = -1;
for (int i = 0; i < itemcount && found == -1; i++)
{
if (Std[i].StdNumber == id) found = i;
else found = -1;
}
return found;
}
static void clean(Student[] Std, int index)
{
Std[index].StdNumber = null;
Std[index].StdName = null;
Std[index].sex = null;
Std[index].Quizz1 = 0;
Std[index].Quizz2 = 0;
Std[index].Assigment = 0;
Std[index].Midterm = 0;
Std[index].Final = 0;
Std[index].Total = 0;
}
static void find(Student[] Std, int itemcount)
{
string id;
Console.Write("Enter student's ID:");
id = Console.ReadLine();
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "0", "1", "2", "3", "4", "5", "6", "7", "8");
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "ID", "NAME", "SEX", "Q1", "Q2", "As", "Mi", "Fi", "TOTAL");
Console.WriteLine("============================================================");
int index = Search(Std, id.ToString(), itemcount);
if (index != -1)
{
Console.Write("{0,-5}{1,-20}{2,-5}", Std[index].StdNumber, Std[index].StdName, Std[index].sex);
Console.Write("{0,-5}{1,-5}{2,-5}", Std[index].Quizz1, Std[index].Quizz2, Std[index].Assigment);
Console.Write("{0,-5}{1,-5}{2,-5}", Std[index].Midterm, Std[index].Final, Std[index].Total);
Console.WriteLine();
}
else Console.WriteLine("The record deosn't exits.");
}
static void bubblesort(Student[] dataset, int n)
{
int i, j;
for (i = 0; i < n; i++)
for (j = n - 1; j > i; j--)
if (dataset[j].Total < dataset[j - 1].Total)
{
Student temp = dataset[j];
dataset[j] = dataset[j - 1];
dataset[j - 1] = temp;
}
}
}
}