Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program using ArrayList to allow the professor to enter students' names, and four test scores for each student. There should be an option to

Java program using ArrayList to allow the professor to enter students' names, and four test scores for each student. There should be an option to type "C" when student data entry is complete. Next, display each student's name, average score, and letter grade. The output should be sorted by student's last name.


public class schoolgrades {

public static void main(String[] args) {
 // TODO Auto-generated method stub

 //Header file section

 #include

 #define STUDENT 5

 #define GRD 4

 using namespace std;

 //Declare methods

 void getname(char[]);

 void getGRD(char[],double[]);

 char lettergrade(double[],double&);

 void result(char[],double[],char,double);

 //Start main

 int main( )

 {

    //Declare variables

      char name[STUDENT][20],letter[STUDENT],grade;

       double s1[GRD],s2[GRD],s3[GRD];

       double s4[GRD],s0[GRD],avg;

 

          getname(name[0]);

          getGRD(name[0],s0);

          grade=lettergrade(s0,avg);

          result(name[0],s0,grade,avg);

          cin.ignore();

          getname(name[1]);

          getGRD(name[1],s1);

          grade=lettergrade(s1,avg);

          result(name[1],s1,grade,avg);

          cin.ignore();

          getname(name[2]);

          getGRD(name[2],s1);

          grade=lettergrade(s2,avg);

          result(name[2],s2,grade,avg);

          cin.ignore();

          getname(name[3]);

          getGRD(name[3],s3);

          grade=lettergrade(s3,avg);

          result(name[3],s3,grade,avg);

          cin.ignore();

          getname(name[4]);

          getGRD(name[4],s4);

          grade=lettergrade(s4,avg);

          result(name[4],s4,grade,avg);

          cin.ignore();

          system("PAUSE");

          return 0;

    }

 

    //method getname

       void getname(char n[])

       {

          cout<<"Enter student name:";

          cin.getline(n,20);

       }

 

       //method getGRD        void getGRD(char n[],double g[])        {              int i;              for(i=0;i>g[i];                 while(g[i]<0||g[i]>100)              {                 cout<<"Invalid grade\n";                 cout<<"Enter Test score:"<>g[i];           }     }

 }

 //method lettergrade

 char lettergrade(double g[],double& a)

 {

    int i;

    double sum=0;

    char grade;

    for(i=0;i

    sum+=g[i];

    a=sum/GRD;

    switch((int)a/10)

    {

       case10:

       case 9:grade='A';

                   break;

       case 8:grade='B';

                   break;

       case 7:grade='C';

                   break;

 

       case 6:grade='D';

                   break;

      default :grade='E';

    }

       return grade;

    }

 

 //Display result void result(char n[],double g[],char l,double a)

    {

          int i;

          cout<<"Name :"<

          cout<<"Test Scores:";

          for(i=0;i

             cout<

          cout<<"\nAverage:"<

          cout<<"Grade:"<

             system("PAUSE");

}

}

 

Can't figure out the errors in the code It is probably something small but completely unsure.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

=+m a cola-drink-concentrate producer n a movie studio

Answered: 1 week ago