C# exercises and solutions-update record


C# structure: student records application

Update record

Step7: Defining the update_rec(struct student st[], int itemcount) method to update a specified record. The update process starts by asking the user to input the id of the record to be changed. The id value is check to make sure it really exists. If it exits the change to the target record can be made after asking the user to input the new value of the field that need change.

static void update(student[] st, 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(st, id.ToString(),itemcount);

if ((index != -1) && (itemcount != 0))
{
if (column_index == 1)
{
Console.Write("Enter student's Name:");

st[index].stname = Console.ReadLine().ToString();
}

else if (column_index == 2)
{
Console.Write("Enter student's Sex(F or M):");
st[index].sex = Console.ReadLine().ToString();
}
else if (column_index == 3)
{
Console.Write("Enter student's quizz1 score:");
st[index].quizz1 = float.Parse(Console.ReadLine());
}
else if (column_index == 4)
{
Console.Write("Enter student's quizz2 score:");
st[index].quizz2 = float.Parse(Console.ReadLine());
}
else if (column_index == 5)
{
Console.Write("Enter student's assigment score:");
st[index].assigment = float.Parse(Console.ReadLine());
}
else if (column_index == 6)
{
Console.Write("Enter student's mid term score:");
st[index].midterm = float.Parse(Console.ReadLine());
}
else if (column_index == 7)
{
Console.Write("Enter student's final score:");
st[index].final = float.Parse(Console.ReadLine());
}
else Console.WriteLine("Invalid column index");
st[index].total = st[index].quizz1 + st[index].quizz2 + st[index].assigment + st[index].midterm + st[index].final;


}
else Console.WriteLine("The record deosn't exits.Check the ID and try again.");

}


Comments




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.