Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this one part I am not sure how to do vi) Display a menu a) Display final grades b) Display course grades c)

I have this one part I am not sure how to do

vi) Display a menu

a) Display final grades

b) Display course grades

c) Semester Average

d) Exit

(20 points) When option a is selected, for each different course, compute the averages (exams, homeworks and quizzes); using the percentages given before (60%, 30% and 10%), compute the final grade, and use a table format to display final grades, indicating with (minus) the smallest grade and +(plus) the highest grade. For example COURSE No. FINAL GRADE NOTE CS1337 89.0 - CS2305 100.0 + PHY1305 99.0

(10 points) When option b is selected, you first ask for the course prefix and number (i.e. CS1337), if the course prefix is not found, your program should display a message indicating

Otherwise, using the table format below, display all the information about the course. For example, say that class prefix and number CS1337 was entered:

COURSE No. GRADE TYPE

CS1337 98.5 EXAM

CS1337 100.0 HW

CS1337 99.0 QUIZ

(5 points) When option c is selected, the program will compute the semester average as the sum of the final grades, divided by the number of courses taken, a display a message like: THIS SEMESTER YOU AVERAGE WAS 97.9/100!

Here is the code I have so far

1. course.h:

--------------------------------------------------------------

/* * course.h * * course class declaration */

#ifndef COURSE_H_ #define COURSE_H_

#include

using namespace std;

enum TYPE{EXAM,HW,QUIZ,FINAL}; //enum type for task type

class course { private: char* courseName; //To store class prefix and number TYPE task; //Enum type to represent EXAM, HW, QUIZ or FINAL double grade; // A double value from 0 to 100 public: course(); //constructor virtual ~course(); //destructor

//accessors and mutators char* getCourseName() const; void setCourseName(char* courseName); double getGrade() const; void setGrade(double grade); TYPE getTask() const; void setTask(TYPE task); };

#endif /* COURSE_H_ */

-------------------------------------------------------------------

2. course.cpp:

-------------------------------------------------------------------

/* * course.cpp * Implementation of course class */

#include "course.h"

course::course() { // TODO Auto-generated constructor stub courseName=NULL; task=EXAM; grade=-1; }

char* course::getCourseName() const { return courseName; }

void course::setCourseName(char* courseName) { this->courseName = courseName; }

double course::getGrade() const { return grade; }

void course::setGrade(double grade) { this->grade = grade; }

TYPE course::getTask() const { return task; }

void course::setTask(TYPE task) { this->task = task; }

course::~course() {

delete this;

}

------------------------------------------------------------

3. node.h:

------------------------------------------------------------

/* * node.h * * node class declaration */

#ifndef NODE_H_ #define NODE_H_

#include "course.h"

class node: public course { private: node* prev; //link to previous node node* next; //link to next node public: node(); virtual ~node();

//accessors and mutators node* getNext(); void setNext(node* next); node* getPrev(); void setPrev(node* prev); };

#endif /* NODE_H_ */

-----------------------------------------------------------

4. node.cpp:

-------------------------------------------------------------------

/* * node.cpp * * implementation of node class */

#include "node.h"

node::node():course() { // TODO Auto-generated constructor stub prev=NULL; next=NULL; }

node* node::getNext() { return next; }

void node::setNext(node* next) { this->next = next; }

node* node::getPrev() { return prev; }

void node::setPrev(node* prev) { this->prev = prev; }

node::~node() { // TODO Auto-generated destructor stub delete this; }

----------------------------------------------------------------

5. grades.h:

-------------------------------------------------------------

/* * grades.h * * declaration of grades class representing a doubly linked list of grades */

#ifndef GRADES_H_ #define GRADES_H_

#include "node.h"

class grades { node* head; //head node of doubly linked list of grades node* tail; //tail node of doubly linked list of grades public: grades(); //constructor virtual ~grades(); //destructor

//utility methods bool isEmpty(); //tells whether list is empty void append(node*); //append a node to the tail of the list void remove(node*); //remove a node from the list node* findNode(node*); //find a node in the list };

#endif /* GRADES_H_ */

-------------------------------------------------------------------

6. grades.cpp:

------------------------------------------------------------------

/* * grades.cpp * * implementation of grades class */

#include "grades.h"

//constructor grades::grades() { // TODO Auto-generated constructor stub head=NULL; tail=NULL; }

//destructor grades::~grades() { // TODO Auto-generated destructor stub delete this; }

//returns whether list empty bool grades::isEmpty() { return (head==NULL); }

//appends a node to the tail of the list void grades::append(node* n) { if(isEmpty()) { head=node; tail=node; } else { n->setPrev(tail); tail->setNext(n); tail=n; } }

//removes a node containing a given grade from the list void grades::remove(node* n) { node* nodeToRemove=findNode(n); if(nodeToRemove!=NULL) { node* prevToNodeToRemove=nodeToRemove->getPrev(); //previous node of nodeToRemove node* nextToNodeToRemove=nodeToRemove->getNext(); //next node of nodeToRemove

//updates pointers to detach nodeToRemove from list nextToNodeToRemove->setPrev(prevToNodeToRemove); //prevToNodeToRemove becomes the previous node of nextToNodeToRemove prevToNodeToRemove->setNext(nextToNodeToRemove); //nextToNodeToRemove becomes the next node of prevToNodeToRemove

//deletes the node delete nodeToRemove; } else cerr<<"Error deleting node!"< }

//returns a node if it exists in the list node* grades::findNode(node* n) { node* curr=head; //search will start from head node node* foundNode=NULL; //pointer to found node while(curr!=NULL) { if(curr->getGrade()==n->getGrade()) { foundNode=n; break; } curr=curr->getNext(); } return foundNode; }

-----------------------------------------------------------------

7. main funciton:

---------------------------------------------------------------------

#include #include #include #include "grades.h"

using namespace std;

//reads grades from file and loads them into linked list void readAndLoadGrades(string gradeFileName,grades gradeList) { ifstream infile(gradeFileName.c_str());

//check if file exists or open if(!infile) { cerr<<"Error opening file!"< return; }

//reads file line by line string line; while(getline(infile,line)) { //check whether line contains any data if(line.empty()) continue;

istringstream iss(line); //string stream to read data from line int task; string course; double grade; iss>>task; //reads task iss>>course; //reads course name iss>>grade; //reads grade

//create a new node to store course information node* newNode=new node; const char* crse=course.c_str(); newNode->setCourseName((char*)crse); newNode->setGrade(grade); //sets TYPE switch(task) { case 0: newNode->setTask(EXAM); break; case 1: newNode->setTask(HW); break; case 2: newNode->setTask(QUIZ); break; case 3: newNode->setTask(FINAL); break; }

//appends the node to gradeList; gradeList.append(newNode); } }

//main function to read and load grades from grade.txt int main() { string gradesFilePath="./src/grades.txt"; //modify this as per path on your system grades gradeList; readAndLoadGrades(gradesFilePath,gradeList); return 0; }

---------------------------------------------------------

8. grades.txt:

------------------------------------------------------------

0 CS1337 89 1 CS2305 95 1 CS1337 100 2 PHY1305 67

Here is also the rest of the assignment I have finished for your information

(5 points) Define a base class with the following data members, including constructor, destructor (to release dynamically allocated memory) and accessors and mutators: o char * courseName; // To store class prefix and number o TYPE task:// Enum type to represent EXAM, HW, QUIZ or FINAL o double grade; // A double value from 0 to 100

ii) (5 points) Derive a class from i) and call it node, adding the data members, accessors and mutators needed to be used as a node in a doubly linked list.

iii) (15 points) Implement a doubly linked list, and name it grades, using the class in ii). Include (at least) the following operation: o Append, remove, find node: o Any other method needed

iv) (25 points) Read the input file grades.txt and store this information in the linked list grades. v) (10 points) Define another doubly linked list, and name it courses. Each node in this linked list represent one course. This list is used to collect all the final grades; therefore the task data member is always set to FINAL.

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

Students also viewed these Databases questions

Question

Data has to be consistent and reliable.

Answered: 1 week ago