C# exercises and solutions-append record to list


C# structure: student records application

Append record to list

Step3: defining the add(student[] st, ref int itemcount) method to add a new record to the the array of student objects. This method takes two arguments. The first argument is the array of student objects(st) and the second argument is the number of items in the array. The two arguments are passed by references. For an array, we don't need to use the ref keyword when we want to pass it by reference. However, we need to use the ref keyword when we want to pass an argument of primitive type such as int, float, dobule,etc. When the new item is added the value itemcount variable increases by 1 that means the number of records in the list increases.

//method add/append a new record
static void add(student[] st,ref int itemcount){

Again:
Console.WriteLine();
Console.Write("Enter student's ID:");
st[itemcount].stnumber=Console.ReadLine().ToString() ;

//making sure the record to be added doesn't already exist
if(search(st,st[itemcount].stnumber,itemcount)!=-1){

Console.WriteLine("This ID already exists.");
goto Again;

}


Console.Write("Enter student's Name:");

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


Console.Write("Enter student's Sex(F or M):");
st[itemcount].sex=Console.ReadLine().ToString();


Console.Write("Enter student's quizz1 score:");
st[itemcount].quizz1=float.Parse(Console.ReadLine());


Console.Write("Enter student's quizz2 score:");
st[itemcount].quizz2=float.Parse(Console.ReadLine());


Console.Write("Enter student's assigment score:");
st[itemcount].assigment=float.Parse(Console.ReadLine());


Console.Write("Enter student's mid term score:");
st[itemcount].midterm=float.Parse(Console.ReadLine());

Console.Write("Enter student's final score:");
st[itemcount].final=float.Parse(Console.ReadLine());

st[itemcount].total=st[itemcount].quizz1+st[itemcount].quizz2+st[itemcount].assigment+st[itemcount].midterm+st[itemcount].final;



++itemcount; //increase the number of items by one



}




Comments

Joseph comment

 Joseph

I want to solve this program by any one
I/p:-1 1 2 4
O/p:-a a b d
k b d
a l d


2018-05-24
Zet comment

 Zet

goto?? wow


2017-04-14



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.