rickyiou2005-08-18 16:38:24
using System;

namespace Assignment1_secondExample
{
///
/// 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
///

public class TermTest
{
private double[] scoreArray;

///
/// Constructor that takes in an array of double scores
///

///
public TermTest(double[] scoreArray)
{
this.scoreArray = scoreArray;
}

///
/// AverageScore() returns the average score of the scoreArray
///

///
public double AverageScore()
{
double sum = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
sum += scoreArray[i];
}
return (sum/scoreArray.Length);
}

///
/// HighestScore() returns the highest of the scoreArray
///

///
public double HighestScore()
{
double highest = 0.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (highest < scoreArray[i])
highest = scoreArray[i];
}
return highest;
}

///
/// LowestScore() returns the lowest score of the scoreArray
///

///
public double LowestScore()
{
double lowest = 100.0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (lowest > scoreArray[i])
lowest = scoreArray[i];
}
return lowest;
}

///
/// NumStudentsPassed() returns the number of students who scored 50 and over.
///

///
public int NumStudentsPassed()
{
int numStudents = 0;
for (int i = 0; i < scoreArray.Length; i++)
{
if (scoreArray[i] >= 50)
numStudents++;
}
return numStudents;
}

///
/// PercentagePassed() returns the percentage of students passed as a double type
///

///
///
///
public double PercentagePassed()
{
return 100*((double)NumStudentsPassed()/(double)scoreArray.Length);
}

///
/// FormatOutput() prints the score to 1 decimal place given a double parameter
///

///
///
static double FormatOutput(double score)
{
int tempScore = (int)(10 * score);
double scoreToReturn = (double) tempScore/10;
return scoreToReturn;
}

///
/// PrintResults() simply prints the results to the screen
///

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()) + "%");
}
}
}

怎么做成表格
CutOnce2005-08-18 16:49:12
什么表格?
waste-=2005-08-18 17:08:33
CutOnce, U even help him, to w
单身老猫2005-08-19 04:05:47
是不是作业交不出来了?