Jump to content

arrange the rows


softweb001

Recommended Posts

Hi..

 

I want to arrange the output of my code like this

 

Maths Eng

Student1 40 60

 

Student2 40 60

 

 

buh am having a problem doing it.......

 

here is my code

 

using System;
class WorkFile
{
private string[] studentsarray;
private string[] subjectsarray;
private int[,] studentiesarray;
public string CourseName {get; set; }
public string[] students
{
get
{
return studentsarray;
}
set
{
studentsarray = value;
}
}
public string[] subjects
{
get
{
return subjectsarray;
}
set
{
subjectsarray = value;
}
}
public WorkFile( string name, int[ , ] studenties, string[] students, string[] subjects )
{
CourseName = name;
studentiesarray = studenties;
studentsarray=students;
subjectsarray=subjects;
}
public void DisplayMessage()
{
Console.WriteLine( "Welcome to the grade book forn{0}!n",
CourseName );
}
public void processgrades()
{
outputgrades();
}
public int getaverage(int Row)
{
int total = 0;
for (int column = 0; column < studentiesarray.GetLength(1); ++column)
total += studentiesarray[Row, column];
int over= (int)total/studentiesarray.GetLength(1);
return over;
}
public void outputgrades()
{
Console.WriteLine("The grades are");
Console.Write(" ");
for (int test = 0; test < subjects.Length; ++test)
{
Console.Write("{0} ",subjects[test]);
}
Console.WriteLine("Average");
for (int Row = 0; Row < studentiesarray.GetLength(0); ++Row)
{
Console.WriteLine(students[Row]);
for (int grade = 0; grade < studentiesarray.GetLength(1); ++grade)
{
Console.Write("{0, 8}", studentiesarray[Row, grade]);
}
Console.WriteLine("{0,9:F}", getaverage(Row));
}
}
}
And the class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentScores
{
class Program
{
static void Main(string[] args)
{
string[] students = new string[2];
string[] subjects = { "Maths", "English", "Biology", "Chemistry", "Physics", "Economics", "Geography", "Agriculture" };
int[,] studenties = new int[2, 8];
WorkFile myworkfile = new WorkFile("Welcome to the main man", studenties, subjects, students );
for (int request = 0; request < students.Length; ++request)
{
Console.Write("Input the name of the student: ");
students[request] =Convert.ToString(Console.ReadLine());
for (int scores = 0; scores < subjects.Length; ++scores)
{
Console.Write("input his {0} score: ", subjects[scores]);
studenties[request, scores] = Convert.ToInt32( Console.ReadLine());
}
}
myworkfile.processgrades();
Console.ReadKey();
}
}
}
pls help....Thanks...

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...