isbn is 9780521670159 Design and implement a class that allo

isbn is 9780521670159

Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grade, the highest grade, and the lowest grade. Write a program to test your class implementation. Modify Exercise 1 so that the class can keep track of multiple courses. Write a program to test your implementation. Rewrite Exercise 1 using an ArrayList. Write a program to test your implementation and compare its performance to that of the array implementation in Exercise 1 using the Timing class. Design and implement a class that uses an array to mimic the behavior of the ArrayList class. Include as many methods from the ArrayList class as possible. Write a program to test your implementation.

Solution

Hi,

I\'m giving you the answers for the first 3 questions mentioned above. As per Chegg policy i have to answer first 3 questions only. The following are the two programs which gives average, minimum grade and maximum grade for 3 courses. Program1 is written using \"Array\" and Program2 is written using \"ArrayList\". Both programs have a timer class which shows you the time elapsed.

Program1: //Using normal Array

using System.IO;
using System;
using System.Diagnostics;

class Grade
{
public string course;
public double[] grades;
  
public Grade(string c){
course = c;
grades = new double[10];
}
  
public void setCourse(string c){ course=c;}
public string getCourse(){ return course; }
  
public double findMinGrade(){
double min=grades[0];
int len=grades.Length;
  
for(int i=1;i<len;i++)
if(min>grades[i])
min=grades[i];
  
return min;
}
  
public double findMaxGrade(){
double max=grades[0];
int len=grades.Length;
  
for(int i=1;i<len;i++)
if(max<grades[i])
max=grades[i];
  
return max;
}
  
public double findAvgGrade(){
double sum=0;
double len=grades.Length;
  
for(int i=0;i<len;i++)
sum=sum+grades[i];
  
return sum/len;
  
}
  
}
class Program
{
static void Main()
{
  
Stopwatch stopwatch = new Stopwatch();

// Begin timer
stopwatch.Start();

  
  
Grade[] b=new Grade[3];
  
b[0]=new Grade(\"Computer\");
b[1]=new Grade(\"Electronics\");
b[2]=new Grade(\"Biotech\");

  
for(int a=10,d=5,c=7,i=0;i<10;a+=10,d+=5,c+=7,i++) {
b[0].grades[i]=a;
b[1].grades[i]=d;
b[2].grades[i]=c;
}
  
for(int i=0;i<3;i++){
Console.WriteLine(\"************************\");
Console.WriteLine(\"Course: {0}\", b[i].getCourse());
Console.WriteLine(\"Min Grade:{0}\", b[i].findMinGrade());
Console.WriteLine(\"Max Grade: {0}\", b[i].findMaxGrade());
  
Console.WriteLine(\"Average Grade: {0}\", b[i].findAvgGrade());
Console.WriteLine(\"************************\");
}
  
// Stop timer
stopwatch.Stop();

//result.
Console.WriteLine(\"Time elapsed: {0}\", stopwatch.Elapsed);
}

}

Output:

************************                                                                                                                                

Course: Computer                                                                                                                                        

Min Grade:10                                                                                                                                            

Max Grade: 100                                                                                                                                          

Average Grade: 55                                                                                                                                       

************************                                                                                                                                

************************                                                                                                                                

Course: Electronics                                                                                                                                     

Min Grade:5                                                                                                                                             

Max Grade: 50                                                                                                                                           

Average Grade: 27.5                                                                                                                                     

************************                                                                                                                                

************************                                                                                                                                

Course: Biotech                                                                                                                                         

Min Grade:7                                                                                                                                             

Max Grade: 70                                                                                                                                           

Average Grade: 38.5                                                                                                                                     

************************                                                                                                                                

Time elapsed: 00:00:00.0119044

Program2: //Using ArrayList

using System.IO;
using System;
using System.Diagnostics;
using System.Collections;

class Grade
{
public string course;
public ArrayList grades;
  
public Grade(string c){
course = c;
grades = new ArrayList();
}
  
public void setCourse(string c){ course=c;}
public string getCourse(){ return course; }
  
public int findMinGrade(){
grades.Sort();
int o=(int)grades[0];
return o;
  
}
  
public int findMaxGrade(){
grades.Sort();
int o=(int) grades[0];
return o;
}
  
public double findAvgGrade(){
int sum=0;
double len=grades.Count;
  
foreach (int i in grades )
sum=sum+i;
  
return sum/len;
  
}
  
}
class Program
{
static void Main()
{
  
Stopwatch stopwatch = new Stopwatch();

// Begin timer
stopwatch.Start();

  
  
Grade[] b=new Grade[3];
  
b[0]=new Grade(\"Computer\");
b[1]=new Grade(\"Electronics\");
b[2]=new Grade(\"Biotech\");

  
for(int a=10,d=5,c=7,i=0;i<10;a+=10,d+=5,c+=7,i++) {
b[0].grades.Add(a);
b[1].grades.Add(d);
b[2].grades.Add(c);
}
  
for(int i=0;i<3;i++){
Console.WriteLine(\"************************\");
Console.WriteLine(\"Course: {0}\", b[i].getCourse());
Console.WriteLine(\"Min Grade:{0}\", b[i].findMinGrade());
Console.WriteLine(\"Max Grade: {0}\", b[i].findMaxGrade());
  
Console.WriteLine(\"Average Grade: {0}\", b[i].findAvgGrade());
Console.WriteLine(\"************************\");
}
  
// Stop timer
stopwatch.Stop();

//result.
Console.WriteLine(\"Time elapsed: {0}\", stopwatch.Elapsed);
}

}

Output:

************************                                                                                                                                

Course: Computer                                                                                                                                        

Min Grade:10                                                                                                                                            

Max Grade: 10                                                                                                                                           

Average Grade: 55                                                                                                                                       

************************                                                                                                                                

************************                                                                                                                                

Course: Electronics                                                                                                                                     

Min Grade:5                                                                                                                                             

Max Grade: 5                                                                                                                                            

Average Grade: 27.5                                                                                                                                     

************************                                                                                                                                

************************                                                                                                                                

Course: Biotech                                                                                                                                         

Min Grade:7                                                                                                                                             

Max Grade: 7                                                                                                                                            

Average Grade: 38.5                                                                                                                                     

************************                                                                                                                                

Time elapsed: 00:00:00.0113880

isbn is 9780521670159 Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grad
isbn is 9780521670159 Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grad
isbn is 9780521670159 Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grad
isbn is 9780521670159 Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grad
isbn is 9780521670159 Design and implement a class that allows a teacher to track the grades in a single course. Include methods that calculate the average grad

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site