Answer to Question #43688 in C# for MUTHURAMAN.N

Question #43688
simple c#program to get student details including name roll no, and also to calculate the average total,display in table and also give grades using call by value method
1
Expert's answer
2014-06-26T10:27:01-0400
usingSystem;

classProgram
{

class Subject
{
private intmark;
private stringname;

publicSubject(string name, intmark)
{
this.name= name;
this.mark= mark;
}

public intGetMark()
{
returnmark;
}

public voidPrintSubject()
{
Console.WriteLine("|{0, -10} | {1, 10} |", name,mark);
}
}

// Student details
static stringname;
static int no;
static Subject[]subjects = newSubject[5];
static intnumOfSub = 0;


//By value method
public static voidAddSubject(string name,intmark)
{
subjects[numOfSub] = newSubject(name,mark);
numOfSub++;
}

public static floatAverage()
{
intsum = 0;
for (int i = 0; i <numOfSub; i++)
{
sum =sum + subjects[i].GetMark();
}

return (float)sum / numOfSub;
}

public static voidDisplay()
{
Console.WriteLine("---------------------------");
Console.WriteLine("|Student {0, -7} no. {1, 3} |",name, no);
for (int i = 0; i <numOfSub; i++)
{
Console.WriteLine("---------------------------");
subjects[i].PrintSubject();
}
Console.WriteLine("---------------------------");
Console.WriteLine("|Average: {0, 6} |",Average());
Console.WriteLine("---------------------------");

}

public static voidMain()
{
Console.Write("Enteryour name: ");
name =Console.ReadLine();

Console.Write("Enterroll no: ");
no = int.Parse(Console.ReadLine());

// The subjects arereaded.
stringsubjectName;
intsubjectMark;

Console.Write("Entersubject name: ");
subjectName =Console.ReadLine();
Console.Write("Entersubject mark: ");
subjectMark = int.Parse(Console.ReadLine());

AddSubject(subjectName,subjectMark);

Console.Write("Entersubject name: ");
subjectName =Console.ReadLine();
Console.Write("Entersubject mark: ");
subjectMark = int.Parse(Console.ReadLine());

AddSubject(subjectName,subjectMark);


Display();

}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS