Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++:Can you please help with this assignment? In this exercise, you are helping

ID: 3667129 • Letter: C

Question

C++:Can you please help with this assignment? In this exercise, you are helping the school to create a Records system. The scenario (required classes) is briefly described as follows: 1. Course class should have constant data members in its private section. Please also introduce necessary public functions to read/write them. a. Course name b. Credit 2. Record class consists an array(s), vector(s), or map (map info can be found at: http://www.cplusplus.com/reference/map/map/) as container(s) to store Course pointer that student enrolls and its score (to simplify the lab exercise, please randomly generate an integer (range 0~100) as the score when the course is added.) Below are the needed methods for the class. a. void addCourse(Course* c) adds a course pointer c to its array/vector/map. (Don’t forget a score is associated with the course) (HINT: if you use vector, you may need 2 dimensional one). b. void dropCourse(Course* c) deletes the course and score from the container. Please note that no course and score should be deleted if this course is not available in the container. c. double computecGPA() computes the cumulate GPA of all courses d. double computeProgramGPA() computes the GPA of all the courses offered by student’s major (could be CSCI or MATH) e. double computeAverage() computes the numerical average of all the courses that student takes. f. char convertToLetter(int score) converts numerical score into A (90~100), B (80~89), C (70~79), D (60~69), or F (<60).

Explanation / Answer

Course.h

class Course
{
public:
   Course();
   ~Course();
   void setCourseName(char* name){ courseName = name; }
   void setCredits(int cred){ credits = cred; }
   char* getCourseName(){ return courseName; }
   int getCredits(){ return credits; }
private:
   char* courseName;
   int credits;

};

Record.h

#include "Course.h"
#include<algorithm>
#include<map>
class Record
{
public:
   Record();
   ~Record();
   void addCourse(Course* c);
   void dropCourse(Course* c);
   double computeCGPA();
   double computeProgramGPA();
   double computeAverage();
   char convertToLetter(int score);
private:
   std::map<Course*, int> courses;

};

Record.cpp

#include "Record.h"

Record::Record()
{
}


Record::~Record()
{
}

void Record::addCourse(Course* c)
{
   //generating random score
   int score = rand() % 100 + 1;
   courses[c] = score;
}

void Record::dropCourse(Course* c)
{
   if (courses.find(c) != courses.end())
   {
       courses.erase(c);
   }
}

double Record::computeCGPA()
{
   int totalCredits = 0;
   int totalGrades = 0;
   //typedef std::map<Course*, int>::iterator it;
   for (std::map<Course*, int>::iterator it = courses.begin(); it != courses.end(); it++)
   {
       totalCredits += it->first->getCredits();
       int score = it->second;
       int grade = 0;
       if (convertToLetter(score) == 'A')
       {
           grade = 4;
       }
       else if (convertToLetter(score) == 'B')
       {
           grade = 3;
       }
       else if (convertToLetter(score) == 'C')
       {
           grade = 2;
       }
       else if (convertToLetter(score) == 'D')
       {
           grade = 1;
       }
       else
       {
           grade = 1;
       }
       totalGrades += it->first->getCredits()*grade;
   }

   double cgpa = totalGrades / (double)totalCredits;
   return cgpa;
}

double Record::computeProgramGPA()
{
   //np details are provided for this please comment on the answer with details if you need help with this.
   return 0;
}

double Record::computeAverage()
{
   int total = 0;
   int count = 0;
   //iterating over the map
   for (std::map<Course*, int>::iterator it = courses.begin(); it != courses.end(); it++)
   {
       //it->second gives the value for a key value pair in map
       total += it->second;
       count++;
   }
   double average = total / (double)count;
   return average;
}

char Record::convertToLetter(int score)
{
   if (score >= 90 && score <= 100)
   {
       return 'A';
   }
   else if (score >= 80 && score <= 89)
   {
       return 'B';
   }
   else if (score >= 70 && score <= 79)
   {
       return 'C';
   }
   else if (score >= 60 && score <= 69)
   {
       return 'D';
   }
   else
   {
       return 'F';
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote