Please show me how to code this using Java : NOTE: Please read steps carefully..
ID: 3759397 • Letter: P
Question
Please show me how to code this using Java :
NOTE: Please read steps carefully.... ALL STEPS 1-6 NEED TO BE INCORPORATED INTO ONE PROGRAM
Create a program to enter grades and calculate averages and letter grades.
1. Need a class which will contain:
Student Name
Student Id
Student Grades (an array of 3 grades)
A constructor that clears the student data (use -1 for unset grades)
Get functions for items a, b, and c, average, and letter grade
Set functions for items a, n, and c
Note that the get and set functions for Student grades need an argument for the grade index.
2. Need another class which will contain:
An Array of Students (1 above)
A count of number of students in use
3. You need to create a menu interface that allows you to:
Add new students
Enter test grades
Display all the students with their names, ids, test grades, average, and letter grade
Exit the program
4. Add comments and use proper indentation.
5. The system should be able to accept a student with no grades, then later add one or more grades, and when all grades are entered, calculate the final average or grade.
6. The system should also be able to display the students in alphabetical order (no matter what order they are entered in)
An example menu might be:
Enter A to Add Students
Enter B to Enter Test Grades
Enter C to Display Results
Enter D to Exit Program
Please select A, B, C, or D:
For item B, you will need to prompt the user to enter the test number and then enter the value for each student for that test (if there is a previous value, you should display it and if the user enters the empty string, not change the value).
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct StudentData
{
string firstname;
string lastname;
int tests[5];
};
int gethighest(const StudentData list[], int listsize);
int getlowest(const StudentData list[], int listsize);
void CalcAverage(const StudentData list[], double Sum[], double Average[], int listsize);
void getGrade(const StudentData list[], double Average[], char Grade[], int listsize);
void printheading();
void PrintResults(const StudentData list[], double Average[], char Grade[], int listsize);
int main()
{
const int NoOfStudents = 200;
StudentData item;
int students;
int listsize;
StudentData list[NoOfStudents];
char Grade[NoOfStudents];
double Sum[NoOfStudents];
double Average[NoOfStudents];
ifstream inFile;
string filename;
cout << "Programmer Name: Jane Hanger"
<< endl;
cout << "Lab CRN: 11145 "
<< endl;
cout << "Enter the file name of student data: ";
cin >> filename;
cout << endl;
inFile.open(filename.c_str());
if (!inFile)
{
cout << "Missing File ";
system ("pause");
return 1;
}
int test;
students = 0;
inFile >> list[students].firstname >> list[students].lastname;
while (inFile)
{
for(test = 0; test < 5; test++)
{
inFile >> list[students].tests[test];
}
students++;
inFile >> list[students].firstname >> list[students].lastname;
}
students = students + 1;
CalcAverage(list, Sum, Average, students);
getGrade(list, Average, Grade, students);
printheading();
PrintResults(list, Average, Grade, students);
cout << "The program is complete. " << endl;
inFile.close();
system ("pause");
return 0;
}
void CalcAverage(const StudentData list[], double Sum[], double Average[], int listsize)
{
int row, col, test;
double lowest, highest;
highest = static_cast<double>(gethighest(list, listsize));
lowest = static_cast<double>(getlowest(list, listsize));
for (int row = 0; row < listsize; row++)
{
Sum[row] = 0.0;
for(test = 0; test < 5; test++)
{
Sum[row] = Sum[row] + static_cast<double>(list[row].tests[test]);
if(list[row].tests[test] == lowest)
Sum[row] = Sum[row] - lowest;
if(list[row].tests [test] == highest)
Sum[row] = Sum[row] + highest;
}
Average[row] = (Sum[row] / 5);
}
}
int gethighest(const StudentData list[], int listsize)
{
int row, col;
int highest;
for (row = 0; row < listsize; row++)
{
highest = list[row].tests[0];
for (col = 1; col < 5; col++)
{
if(highest < list[row].tests[col])
highest = list[row].tests[col];
}
}
return highest;
}
int getlowest(const StudentData list[], int listsize)
{
int row, col;
int lowest;
for (row = 0; row < listsize; row++)
{
lowest = list[row].tests[0];
for (col = 0; col < 5; col++)
{
if(lowest > list[row].tests[col])
lowest = list[row].tests[col];
}
}
return lowest;
}
void getGrade(const StudentData list[], double Average[], char Grade[], int listsize)
{
int row;
for (int row =0; row < listsize; row++)
{
if(Average[row] >= 90)
Grade[row] = 'A';
else if (Average[row] >= 80)
Grade[row] = 'B';
else if (Average[row] >= 70)
Grade[row] = 'C';
else if (Average[row] >= 60)
Grade[row] = 'D';
else
Grade[row] = 'F';
}
}
void printheading()
{
cout << "-*-*-*-*-*-*-*-*-*-*-*-*Classroom Results*-*-*-*"
<< "-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl;
cout << "------------------------------------------------"
<< "---------------------------------" << endl;
cout << " Student Test1 Test2 Test3 Test4 Test5"
<< " Average Grade" << endl;
cout << "------------------------------------------------"
<< "--------------------------------- " << endl;
}
void PrintResults(const StudentData list[], double Average[], char Grade[], int listsize)
{
int row, col;
double SumAverage = 0.0;
double ClassAverage;
int Excellent = 0,
Satisfactory = 0,
Failing = 0;
int looper ;
for ( looper = 0; looper < listsize - 1; looper++)
{
cout << list[looper].lastname << " , " << list[looper].firstname;
for(int test = 0; test < 5; test++)
{
cout << " " << list[looper].tests[test] << " ";
}
cout << Average[looper] << " "
<< Grade[looper] << endl;
if (Grade[looper] == 'A')
Excellent++;
else if (Grade[looper] == 'B' || Grade[looper] == 'C')
Satisfactory++;
else if (Grade[looper] == 'D' || Grade[looper] == 'F')
Failing++;
}
cout << "The number of students in the class: "
<< listsize - 1 << endl;
for(row = 0; row < listsize - 1; row++)
{
SumAverage = SumAverage + Average[row];
}
ClassAverage = SumAverage / (listsize - 1);
cout << "Class Average = " << static_cast<int>(ClassAverage) << endl;
cout << "Number of Students in each Category: "
<< "Excellent: " << Excellent << " "
<< "Satisfactory: " << Satisfactory << " "
<< "Failing: " << Failing << " ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.