rickyiou
Newbie level 3
I have a code file for a term test result system,now I want to make it work by c# windows application,I don't know how to use it ,I appreciate that someone can give some help or examples because I must be finish it by tonight.
The cs file and the output diagram are attached below.
using System;
namespace Assignment1_secondExample
{
/// <summary>
/// TermTest is a class that computes the
/// Highest score, Lowest score, Average Score,
/// Number of Students Passed and the Percentage Passed
/// given a set of test results in an Array of double type
/// </summary>
public class TermTest
{
private double[] scoreArray;
/// <summary>
/// Constructor that takes in an array of double scores
/// </summary>
/// <param name="scoreArray"></param>
public TermTest(double[] scoreArray)
{
this.scoreArray = scoreArray;
}
/// <summary>
/// AverageScore() returns the average score of the scoreArray
/// </summary>
/// <returns></returns>
public double AverageScore()
{
double sum = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
sum += scoreArray;
}
return (sum/scoreArray.Length);
}
/// <summary>
/// HighestScore() returns the highest of the scoreArray
/// </summary>
/// <returns></returns>
public double HighestScore()
{
double highest = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (highest < scoreArray)
highest = scoreArray;
}
return highest;
}
/// <summary>
/// LowestScore() returns the lowest score of the scoreArray
/// </summary>
/// <returns></returns>
public double LowestScore()
{
double lowest = 100.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (lowest > scoreArray)
lowest = scoreArray;
}
return lowest;
}
/// <summary>
/// NumStudentsPassed() returns the number of students who scored 50 and over.
/// </summary>
/// <returns></returns>
public int NumStudentsPassed()
{
int numStudents = 0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (scoreArray >= 50)
numStudents++;
}
return numStudents;
}
/// <summary>
/// PercentagePassed() returns the percentage of students passed as a double type
/// </summary>
/// <param name="numPassed"></param>
/// <param name="total"></param>
/// <returns></returns>
public double PercentagePassed()
{
return 100*((double)NumStudentsPassed()/(double)scoreArray.Length);
}
/// <summary>
/// FormatOutput() prints the score to 1 decimal place given a double parameter
/// </summary>
/// <param name="score"></param>
/// <returns></returns>
static double FormatOutput(double score)
{
int tempScore = (int)(10 * score);
double scoreToReturn = (double) tempScore/10;
return scoreToReturn;
}
/// <summary>
/// PrintResults() simply prints the results to the screen
/// </summary>
public void PrintResults()
{
Console.WriteLine("Computing....");
Console.WriteLine("The highest score is: " + HighestScore());
Console.WriteLine("The lowest score is: " + LowestScore());
Console.WriteLine("The average score is: " + FormatOutput(AverageScore()));
Console.WriteLine("The number of Students who have taken the test: " + scoreArray.Length);
Console.WriteLine("The number of Students Passed: " + NumStudentsPassed());
Console.WriteLine("The percentage passed is: " + FormatOutput(PercentagePassed()) + "%");
}
}
}
The cs file and the output diagram are attached below.
using System;
namespace Assignment1_secondExample
{
/// <summary>
/// TermTest is a class that computes the
/// Highest score, Lowest score, Average Score,
/// Number of Students Passed and the Percentage Passed
/// given a set of test results in an Array of double type
/// </summary>
public class TermTest
{
private double[] scoreArray;
/// <summary>
/// Constructor that takes in an array of double scores
/// </summary>
/// <param name="scoreArray"></param>
public TermTest(double[] scoreArray)
{
this.scoreArray = scoreArray;
}
/// <summary>
/// AverageScore() returns the average score of the scoreArray
/// </summary>
/// <returns></returns>
public double AverageScore()
{
double sum = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
sum += scoreArray;
}
return (sum/scoreArray.Length);
}
/// <summary>
/// HighestScore() returns the highest of the scoreArray
/// </summary>
/// <returns></returns>
public double HighestScore()
{
double highest = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (highest < scoreArray)
highest = scoreArray;
}
return highest;
}
/// <summary>
/// LowestScore() returns the lowest score of the scoreArray
/// </summary>
/// <returns></returns>
public double LowestScore()
{
double lowest = 100.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (lowest > scoreArray)
lowest = scoreArray;
}
return lowest;
}
/// <summary>
/// NumStudentsPassed() returns the number of students who scored 50 and over.
/// </summary>
/// <returns></returns>
public int NumStudentsPassed()
{
int numStudents = 0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (scoreArray >= 50)
numStudents++;
}
return numStudents;
}
/// <summary>
/// PercentagePassed() returns the percentage of students passed as a double type
/// </summary>
/// <param name="numPassed"></param>
/// <param name="total"></param>
/// <returns></returns>
public double PercentagePassed()
{
return 100*((double)NumStudentsPassed()/(double)scoreArray.Length);
}
/// <summary>
/// FormatOutput() prints the score to 1 decimal place given a double parameter
/// </summary>
/// <param name="score"></param>
/// <returns></returns>
static double FormatOutput(double score)
{
int tempScore = (int)(10 * score);
double scoreToReturn = (double) tempScore/10;
return scoreToReturn;
}
/// <summary>
/// PrintResults() simply prints the results to the screen
/// </summary>
public void PrintResults()
{
Console.WriteLine("Computing....");
Console.WriteLine("The highest score is: " + HighestScore());
Console.WriteLine("The lowest score is: " + LowestScore());
Console.WriteLine("The average score is: " + FormatOutput(AverageScore()));
Console.WriteLine("The number of Students who have taken the test: " + scoreArray.Length);
Console.WriteLine("The number of Students Passed: " + NumStudentsPassed());
Console.WriteLine("The percentage passed is: " + FormatOutput(PercentagePassed()) + "%");
}
}
}