Question

c++

implement a student class

Determine the final scores, letter grades, and rankings of all students in a course.

All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score.

For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all stud

So, you will take the information for each student in the file and calculate the numeric average, letter grade, and ranking o

Sample Run A sample run of your program should look like below. Note that the users inputs are highlighted in Enter an input

Record Finder Enter the name of a student: Ana Name Ana ID: 1500 Average: 80.00 (B) Name: Ana ID: 2000 Average: 100.00 (A) Do

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Project1.cpp


#include "Student.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
double calc_average(double s1, double s2, double s3, double s4, double s5, double m1, double m2, double f);
void label_rank(vector<Student> &s);
void a_sort(vector<Student> &s);
void n_sort(vector<Student> &s);
double class_avg(vector<Student> &s);
void histogram(vector<Student> &s);
void rec_finder(vector<Student> &s);
int main()
{
    string n;
    int d;
    vector<Student> course;
    double score1, score2, score3, score4, score5, midterm1, midterm2, final, overall_avg;
    ifstream myfile;
    string filepath;
// user enters in file path
    cout << "Enter file name: ";
    getline(cin, filepath);
    cout << endl;
    myfile.open(filepath.c_str());
// if file can't be found an error message is displayed
    if(myfile.fail())
    {
      cout <<" Failed to open file "<< endl;
      exit(1);
    }
    int index = 0;
    int i = 0;
// reads from file and inputs the information from each line into an object
    myfile >> index;
    course.resize(index);
    while(!myfile.eof() && i < index){
        myfile >> n >> d >> score1 >> score2 >> score3 >> score4 >> score5 >> midterm1 >> midterm2 >> final;
        course[i].setName(n);
        course[i].setID(d);
        course[i].setAverage(calc_average(score1, score2, score3, score4, score5, midterm1, midterm2, final));
        i++;
    }
    myfile.close();


    label_rank(course);
    cout << "================" << endl;
    cout << "Course Report: Numerical Average Order" << endl;
    cout << "================" << endl;

// calls function a_sort that sorts students by average
    a_sort(course);
    cout << "================" << endl;
    cout << "Course Report: First Name Order" << endl;
    cout << "================" << endl;

// calls function n_sort that sorts students by first name
    n_sort(course);
    cout << "================" << endl;
    cout << endl;
    cout << "================" << endl;
    cout << "Statistics" << endl;
    cout << "================" << endl;
    cout << "Number of students: " << index << endl;
// calls function class_avg that calculates the class average and ouputs
    cout << "Class Average: " << class_avg(course) << endl;
// calls function histogram that prints out grade distribution
    cout << "Grade Distribution (histogrampy)" << endl;
    histogram(course);
    cout << "================" << endl;
    cout << endl;
    cout << "================" << endl;

// calls function rec_finder that finds a student in a course
    rec_finder(course);

}


// function calculates average for a given student
double calc_average(double s1, double s2, double s3, double s4, double s5, double m1, double m2, double f)
{
    vector<double> s = {s1 , s2, s3, s4, s5};
    double s_total = 0, s_average = 0, end_average = 0;
    sort(s.rbegin(), s.rend());
    s.pop_back();
    for(int i = 0; i < s.size(); i++)
    {
      s_total += s[i];
    }
    s_average = (s_total / s.size()) / 10.0;
    end_average = (s_total * .20) + (m1 * .20) + (m2 * .20) + (f * .40);

    return end_average;
}

// funtion ranks students
void label_rank(vector<Student> &s)
{
    int rank = 2;
    Student avg_Top;
    for (int j = 0; j < s.size() - 1; j++){
      for (int i = j + 1; i < s.size(); i++){
        if (s[j].getAverage() < s[i].getAverage()){
          avg_Top = s[j];
          s[j] = s[i];
          s[i] = avg_Top;
        }
      }
    }
    s[0].setRank(1);
    for (int i = 1; i < s.size(); i++)
    {
      if (s[i].getAverage() < s[i-1].getAverage())
      {
        s[i].setRank(rank);
      }
      else if (s[i].getAverage() == s[i-1].getAverage())
      {
        s[i].setRank(s[i-1].getRank());
      }
      rank++;
    }
}

// funtion sorts students by average
void a_sort(vector<Student> &s)
{
    Student avg_Top;
    for (int j = 0; j < s.size() - 1; j++){
      for (int i = j + 1; i < s.size(); i++){
        if (s[j].getAverage() < s[i].getAverage()){
          avg_Top = s[j];
          s[j] = s[i];
          s[i] = avg_Top;
        }
        else if (s[j].getAverage() == s[i].getAverage()){
          if (s[j].getID() < s[i].getID()){
            avg_Top = s[j];
            s[j] = s[i];
            s[i] = avg_Top;
          }
        }
      }
    }
    for(int a = 0; a < s.size(); a++){
      s[a].print();
    }
}

// fuction sorts sudents by first name
void n_sort(vector<Student> &s)
{
    Student avg_Top;
    for (int j = 0; j < s.size() - 1; j++){
      for (int i = j + 1; i < s.size(); i++){
        if (s[j].getName() > s[i].getName()){
          avg_Top = s[j];
          s[j] = s[i];
          s[i] = avg_Top;
        }
        else if (s[j].getName() == s[i].getName()){
          if (s[j].getID() < s[i].getID()){
            avg_Top = s[j];
            s[j] = s[i];
            s[i] = avg_Top;
          }
        }
      }
    }
    for(int a = 0; a < s.size(); a++){
      s[a].print();
    }
}

// function calculates class average
double class_avg(vector<Student> &s)
{
    double c_total = 0, c_average = 0;
    for(int i = 0; i < s.size(); i++){
      c_total += s[i].getAverage();
    }
    c_average = c_total / s.size();
    return c_average;

}

// function creates histogram
void histogram(vector<Student> &s)
{
    int a_count = 0, b_count = 0, c_count = 0, d_count = 0, f_count = 0;
    for (int i = 0; i < s.size(); i++){
      if(s[i].getGrade() == 'A'){
        a_count++;
      }
      if(s[i].getGrade() == 'B'){
        b_count++;
      }
      if(s[i].getGrade() == 'C'){
        c_count++;
      }
      if(s[i].getGrade() == 'D'){
        d_count++;
      }
      if(s[i].getGrade() == 'D'){
        f_count++;
      }
    }
    cout << "A ";
    for(int i = 0; i < a_count; i++){
      cout << "* ";
    }
    cout << endl;
    cout << "B ";
    for(int i = 0; i < b_count; i++){
      cout << "* ";
    }
    cout << endl;
    cout << "C ";
    for(int i = 0; i < c_count; i++){
      cout << "* ";
    }
    cout << endl;
    cout << "D ";
    for(int i = 0; i < d_count; i++){
      cout << "* ";
    }
    cout << endl;
    cout << "F ";
    for(int i = 0; i < f_count; i++){
      cout << "* ";
    }
    cout << endl;
}

// function allows user to search for a specific student
void rec_finder(vector<Student> &s)
{
     char opt;
     string find_student;
     bool student_found = false;
    do{
      cout << "Record Finder: Enter the name of a student: ";
      cin >> find_student;
      cout << "================" << endl;
      for(int i = 0; i < s.size(); i++){
        if (s[i].getName() == find_student){
          student_found = true;
          s[i].print();
          cout<<endl;
          cout << "================" << endl;
        }

        }
      if(student_found == false){
        cout << "Failed. " << find_student << " is not enrolled in the class." << endl;
      }

      cout << "Do you want to continue? (y/n): ";
      cin >> opt;
      opt = toupper(opt);
      if (opt == 'N'){
        cout << "================" << endl;
        cout << "Done."<< endl;
      }
    }
    while( opt == 'Y');
}


Student.cpp


#include "Student.h"
#include <iostream>
using namespace std;

// default constructor
Student::Student(){
}

// method sets student name
void Student::setName(string name){
this->name = name;

}

// method sets student id
void Student::setID(int id){
this->id = id;

}

// method sets student average
void Student::setAverage(int average){
this->average = average;

if( average >= 90 )
{
    setGrade('A');
}
else if( 90 > average && average >= 80 )
{
    setGrade('B');
}
else if( 80 > average && average >= 70 )
{
    setGrade('C');
}
else if( 70 > average && average >= 60 )
{
    setGrade('D');
}
else if( 60 > average )
{
    setGrade('F');
}
}

// method sets student grade
void Student::setGrade(char grade){
this->grade = grade;

}

// method sets student rank
void Student::setRank(int rank){
this->rank = rank;

}

// method gets student name
string Student::getName() const{
return name;

}

// method gets student id
int Student::getID() const{
return id;

}

// method gets student average
double Student::getAverage() const{
return average;

}

// method gets student grade
char Student::getGrade() const{
return grade;

}

// method gets student rank
int Student::getRank() const{
return rank;

}

// method prints sudent info
void Student::print() const{
cout << name << " " << id << " - " << average << " (" << grade << ") (rank: " << rank << ")" << endl;
}


Student.h

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
using namespace std;
class Student
{
private:
    string name;
    int id;
    double average;
    char grade;
    int rank;
public:
    Student();
    void setName(string name);
    void setID(int id);
    void setAverage(int average);
    void setGrade(char grade);
    void setRank(int rank);
    string getName() const;
    int getID() const;
    double getAverage() const;
    char getGrade() const;
    int getRank() const;
    void print() const;

};
#endif


students.txt

4
Sarah 1000 9.5 9.0 8.5 8.0 8.5 87.0 92.5 86.0
Syle 1001 9.6 9.1 8.6 8.1 8.5 87.1 92.6 86.1
Ronny 1056 9.5 9.0 8.5 8.0 8.5 87.0 92.5 100.0
Ronty 1979 9.5 9.0 8.5 8.0 8.5 87.0 92.5 100.0

Add a comment
Know the answer?
Add Answer to:
c++ implement a student class Determine the final scores, letter grades, and rankings of all students...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a grading program for the following grading policies:- a. There are two quizzes, each graded...

    Write a grading program for the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:- >90 A >=80 and <90 B...

  • In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each gr...

    In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:-...

  • C ++ . In professor Maximillian’s course, each student takes four exams. A student’s letter grade...

    C ++ . In professor Maximillian’s course, each student takes four exams. A student’s letter grade is determined by first calculating her weighted average as follows:                                                 (score1 + score2 + score3 + score4 + max_score) weighted_average = -----------------------------------------------------------------------                                                                                                 5 This counts her maximum score twice as much as each of the other scores. Her letter grade is then a A if weighted average is at least 90, a B if weighted average is at least 80...

  • C++ Write a program to calculate final grade in this class, for the scores given below...

    C++ Write a program to calculate final grade in this class, for the scores given below . Remember to exclude one lowest quiz score out of the 4 while initializing the array. Display final numeric score and letter grade. Use standard include <iostream> Implementation: Use arrays for quizzes, labs, projects and exams. Follow Sample Output for formatting. May use initialization lists for arrays. Weight distribution is as follows: Labs: 15% Projects: 20% Quizzes: 20% Exams: 25% Final Project: 20% Display...

  • Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1...

    Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1 to the Office of Registrar at the end of the semester. Display an introductory paragraph for the user then prompt the user to enter a student record (student ID number and five exam-scores – all on one line). The scores will be in the range of 0-100. The sentinel value of -1 will be used to mark the end of data. The instructor has...

  • using if/switch statements (C++) Write a grading program for a class with the following grading policies:...

    using if/switch statements (C++) Write a grading program for a class with the following grading policies: There are two quizzes, each graded on the basis of 10 points There is one midterm exam and one final exam, each graded on the basis of 100 points The final exam counts for 50% of the grade, the midterm counts for 25% and the two quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores. They should...

  • A student recieves test scores of 62, 83 and 91. The students final exam score is...

    A student recieves test scores of 62, 83 and 91. The students final exam score is 88 and homework score is 76. Each test is worth 20% of the final grade, the final exam is worth 25% of the final grade and homework grade is worth 15% of the final grade. Using weighted average, what is the students numerical grade for the course.

  • Language: C++ Write a program that will allow the instructor to enter the student's names, student...

    Language: C++ Write a program that will allow the instructor to enter the student's names, student ID, and their scores on the various exams and projects. A class has a number of students during a semester. Those students take 4 quizzes, one midterm, and one final project. All quizzes weights add up to 40% of the overall grade. The midterm exam is 25% while the final project 35%. The program will issue a report. The report will show individual grades...

  • Write a program to calculate your final grade in this class. Three(8) assignments have yet to...

    Write a program to calculate your final grade in this class. Three(8) assignments have yet to be graded: Quiz 7, Lab 7 and Final Project. Assume ungraded items receive a grade of 100 points. Remember to drop the lowest two quiz scores. Display final numeric score and letter grade. Implementation: Weight distribution is listed in canvas. Use arrays for quizzes, labs, projects and exams. You are allowed to use initialization lists for arrays. Use at least three (3) programmer defined...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT