Advertisement
khaiwen1111

Practical 4 Part B Q1

Jul 5th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. class Student
  2. {
  3.     private string name;
  4.     public string Name
  5.     {
  6.         get { return name; }
  7.     }
  8.     private double[] testScores;
  9.  
  10.     public Student(string theName, double[] theScores)
  11.     {
  12.         name = theName;
  13.         testScores = theScores;
  14.     }
  15.  
  16.     public double ComputeAverage()
  17.     {
  18.         double total = 0.0;
  19.         foreach (double score in testScores)
  20.             total += score;
  21.         return (total / 4);
  22.     }
  23. }
  24. public class StudentTest1
  25. {
  26.     public static void Main()
  27.     {
  28.         double[] scores = { 90.0, 80.0, 80.0, 90.0 };
  29.  
  30.         Student student;
  31.         student = new Student("Alice Smith", scores);
  32.  
  33.         Console.WriteLine("Average for {0} is {1:F1}", student.Name,
  34.        student.ComputeAverage());
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement