Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your job is to implement two member functions in student.h: addGrade(grade) and GPA( ) . The addGrade(grade) function simply pushes the given grade into the

Your job is to implement two member functions in "student.h": addGrade(grade) and GPA( ). The addGrade(grade) function simply pushes the given grade into the Grades vector. The GPA( ) function returns the student's GPA based on their grades. Use standard numeric scoring: A => 4, B => 3, C => 2, D => 1, and F or W => 0. Assume no other grades are possible (e.g. let's ignore NR grades, S/U grades, etc.).

A main( ) program is provided that creates student objects and tests the various member functions. The program starts by creating 3 test students: pooja, drago, and sam. Here's the correct output:

pooja (12345): gpa is 2.75 drago (88425): gpa is 0 sam (99999): gpa is 2.2

/*student.h*/ is a todo file

// // student class for keeping track of grades. //

#pragma once

#include #include #include

using namespace std;

class student { private: string Name; int UIN; vector Grades;

public: // // constructor: // student(string name, int uin) { Name = name; UIN = uin; // // Grades vector is automatically created via it's constructor // }

// // addGrade: // // Adds another grade to the Grades vector. // void addGrade(char grade) { // // TODO: push the grade into the Grades vector: // }

// // GPA: // // returns GPA for this student, based on their grades. Returns 0.0 // if the student has no grades. // double GPA() { // // TODO: loop through the Grades vector and compute the GPA. Note // that if the vector is empty, return 0.0. // return -1; }

// // getName // string getName() { return Name; }

// // getUIN // int getUIN() { return UIN; }

};

main.cpp is a read only file

#include #include

#include "student.h"

using namespace std;

// // testcases // // A couple hard-coded test cases to start. // void testcases() { student pooja("pooja", 12345); pooja.addGrade('A'); pooja.addGrade('B'); pooja.addGrade('A'); pooja.addGrade('F');

cout << pooja.getName() << " (" << pooja.getUIN() << "):" << " gpa is " << pooja.GPA() << endl;

student drago("drago", 88425);

cout << drago.getName() << " (" << drago.getUIN() << "):" << " gpa is " << drago.GPA() << endl;

student grow("sam", 99999); grow.addGrade('A'); grow.addGrade('B'); grow.addGrade('A'); grow.addGrade('F'); grow.addGrade('W');

cout << grow.getName() << " (" << grow.getUIN() << "):" << " gpa is " << grow.GPA() << endl;

cout << endl; }

// ############################################################## // // main // int main() { string name; int uin; char grade;

testcases();

cout << "Enter a student's name (one word)> "; cin >> name; cout << "Enter their UIN> "; cin >> uin;

student S(name, uin);

cout << "Now enter 0 or more grades, one at a time" << endl; cout << "grade or #> "; cin >> grade;

while (grade != '#') { S.addGrade(grade);

cout << "grade or #> "; cin >> grade; }

cout << endl;

cout << S.getName() << " (" << S.getUIN() << "):" << " gpa is " << S.GPA() << endl;

cout << endl; return 0; }

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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions