Please help me code the following for my intro class. #include #include #include
ID: 3760057 • Letter: P
Question
Please help me code the following for my intro class.
#include
#include
#include
#include "Student.h"
#include "Course.h"
using namespace std;
/**
* Requires: a reference to an existing Course instance and the name of a file
* with student data
* Modifies: myCourse
* Effects : Attempts to open the passed filename for reading, then creates a new
* Student instance for each student in the file and adds the grades
* following each student's name to that Student instance. Each
* student is added to the passed Course instance. Returns the number
* of students added to the passed Course instance or 0 if, for whatever
* reason, no students were added.
*/
int addStudentsToCourseFromFile(Course &myCourse, const string fileName);
// Read in information about a course's students from a file and print out summary information
// DO NOT MODIFY
int main(int argc, const char * argv[]) {
Course myCourse ("EECS 103");
if (addStudentsToCourseFromFile(myCourse, "data.txt") == 0) {
cout << "ERROR: No students added" << endl;
return 1;
}
cout << myCourse.getName() << endl;
cout << "Course average: " << myCourse.getAverageGrade() << endl;
cout << "Lowest grade in the course: " << myCourse.getLowestGrade() << endl;
cout << "Highest grade in the course: " << myCourse.getHighestGrade() << endl;
cout << "Student summary: " << endl;
myCourse.printStudents();
return 0;
}
int addStudentsToCourseFromFile(Course &myCourse, const string fileName) {
return 0; // <-- Delete this and uncomment (block comments) and
// complete the code below
/*
// Declare a variable for the input file called infile
// YOUR CODE HERE
// Open the passed file name
// YOUR CODE HERE
// Print error message and return if error opening file
if (!infile) {
cout << "ERROR: File not found: " << fileName << endl;
return 0;
}
// Read student names and grades from the input file
string name = "";
while (getline(YOUR CODE HERE, YOUR CODE HERE)) {
// Create a new Student instance with the name read from the file
// YOUR CODE HERE
// Read all of the grades for the current student
int score;
while (YOUR CODE HERE >> score) {
// Add the grade we just read in to the current student
// YOUR CODE HERE
}
// Clear the fail state that results from trying to covert a student
// name into a grade
infile.clear();
// Add the current student to the course
// YOUR CODE HERE
}
// Close the input file
// YOUR CODE HERE
// Return the number of students added to the course
return myCourse.YOUR CODE HERE;
*/
}
------------------------------------------------------
Student.h
http://pastebin.com/BHuZxmiJ
course.h
http://pastebin.com/XZmUT9c8
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
const int MAX_NUM_STUDENTS = 100;
const int STD_STR_LEN1 = 10;
struct course{
String name[ STD_STR_LEN1];
int numStudents = 0;
String course[ STD_STR_LEN1];
}
void readFile(course &info ); // read the file
void getHighestGrade(course & info); // highest grade of student
void getLowestGrade(course &info );// lowest grade of student
void getAverageGrade(course &info ); // average grade of student
int main()
{
readFile( info );
getLowestGrade( info );
getHighestGrade( info );
getAverageGrade( info );
return 0;
}
public String getName(){
return name;
}
public int getNumStudents(){
return MAX_NUM_STUDENTS;
}
//Add Student
private ArrayList<Student> s;
public void addstudent(student b)
{
s.add(b);
}
public static void main(String[] args)
{
Student h = new Student("John", "223");
Student i = new Student("Emily", "emmy65");
Student j = new Student("Sam", "jkok");
s.addStudent(h);
s.addStudent(i);
s.addStudent(j);
}
}
void readFile(course &info )
{
ifstream fin;
int index;
fin.clear();
fin.open( "data" );
for( index = 0; index < STD_STR_LEN1; index++ )
{
fin >> info.Name >>info.gradePercentage1;
}
}
void getHighestGrade(course &info )
{
int index = 0;
double percent1 = 0;
double highGrade1 = 0;
for( index = 0; index < 10; index++ )
{
if( info.gradePercentage < highGrade )
{
highGrade = info.gradePercentage1;
highGrade++;
}
}
cout << "Highest Grade: " << info.Name << highGrade1 << endl << endl;
}
void getLowestGrade(course &info )
{
double lowGrade1;
cout << "Lowest Grade: " << info.Name << lowGrade1 << endl << endl;
}
void getAverageGrade(course &info )
{
int index;
double average1;
double total1;
for( index = 0; index < 10; index++ )
{
total1 += ( info.gradePercentage1/10 );
}
cout << total1 << endl << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.