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

Use getline if need please. Also make sure the code runs, Thank you. For this pr

ID: 3914714 • Letter: U

Question

Use getline if need please. Also make sure the code runs, Thank you.

For this project we will be writing another container class. This one will be built with a linked list constructed using the node-class nodes that I have given you. Now with the first container class that we wrote the order of the items did not matter, and could be changed by the class itself if it was convenient. The second container that we wrote was a sequence. Items stayed in whatever order the programmer had chosen to use in putting them into the container with the internal iterator. But there are also containers where the order is maintained by the container itself. Where there is only a single insert function, and it always puts items into the container at the spot where they would go in an ordered list of those items. Such lists can only be used to store data types and classes that have comparison operators.

So your assignment is to create a class that will have, as private variables, a string for the students name and a pointer to the head of a linked list which is built from the nodes that I have provided. The list will have the following capabilities:

The ability to add an additional course to the list – the course will be inserted to the correct spot alphabetically by the list class itself (not by the application program)

The ability to display all the courses taken on the screen.

The ability to remove a course with a function that takes the name of the course as a parameter

The ability to return the total hours taken

The ability to return the student’s GPA. To do this you pass through the list obtaining the point value of each course by multiplying number_grade * hours and accumulating these “points” into a single sum, which is then divided by the total hours that the studet has taken.

{OVER}

The main that I have written will offer the user a chance to do each of these functions, plus a testing of the copy constructor which is done by making a copy of the list, allowing the user to delete a course from the copy, and then allowing the copy to go out of scope.

Even though you are only testing one of the Big 3 you are expected you are expected to write all three.

There will also be a file-backup of all the data. The program should load the student’s name (which will be the first thing in the file) and list of courses when it starts up and save the altered list to the same file when it is exiting. Again, we will ask for the student’s username to determine the name of this file. If no file exists the program since the student may be in their first semester of college.

course.h--------------------------------

course.cc--------------------------------------------

node.h---------------------------------------------

collegemain.cc---------------------------------------

Explanation / Answer

Answer: See the code below:

1. college.h: header file

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

#ifndef COLLEGE_H_
#define COLLEGE_H_

#include <cstring>
#include "node.h"

using namespace std;
/**
* college class
*/
class College {
private:
   string student_name; //name of the student
   node* head; //head node of student list
public:
   College(); //constructor
   College(const College&); //copy constructor
   virtual ~College(); //destructor
   void load(ifstream&); //loads data from a file
   void set_name(string); //sets name of the student
   string get_name(); //gets name of the student
   void add(course); //adds a course to list
   void display(ostream&); //displays all courses taken
   void remove(string); //removes a given course from the list
   double hours(); //returns total hours taken
   double gpa(); //returns the gpa
   void save(ostream&); //saves data to file
};

#endif /* COLLEGE_H_ */

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

2. college.cpp: source file implementing functions of 'college' class

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

#include "College.h"

//default constructor
College::College() {
   // TODO Auto-generated constructor stub
   student_name="";
   head = NULL;
}

//copy constructor
College::College(const College& c)
{
   student_name = c.student_name;
   head = c.head;
}

//destructor
College::~College() {
   delete head;
}

//sets name of the student
void College::set_name(string name)
{
   student_name = name;
}

//gets name of the student
string College::get_name()
{
   return student_name;
}

//adds a course to list
void College::add(course c)
{
   node* n = new node(c); //creates a new node for the course
   if (head == NULL) //if linked list is empty
   {
       head = n;
   }
   else
   {
       node* curr = head; //current node initialized with head node
       //loop to identify the location in list where course can be added as per alphabetical order
       while(curr != NULL)
       {
           //compare new course with current course
           if (n->data() > curr->data())
               break;
           curr = curr->link();
       }
       //adds course to list
       n->set_link(curr->link()) ;
       curr->set_link(n);
   }
}

//displays all courses taken
void College::display(ostream& out)
{
   node* curr = head; //current node initialized with head node
   while(curr != NULL)
   {
       curr->data().output(out);
       curr->set_link(curr->link());
   }
}

//removes a given course from the list
void College::remove(string coursename)
{
   //loop to locate coursename in list
   node* curr = head; //current node initialized with head node
   node* prev = NULL; //previous node of current node
   while(curr != NULL)
   {
       if(curr->data().get_course_number().compare(coursename)==0)
       {
           break; //stop if match found
       }
       prev = curr;
       curr->set_link(curr->link());
   }
   //removes the course
   prev->set_link(curr->link());
   delete curr;
}

//loads data from a file
void College::load(ifstream& in)
{
   //file format required
}

//saves data to file
void College::save(ostream& out)
{
   //file format required
}

//returns the gpa
double College::gpa()
{
   double final_gpa = 0.0;
   node* curr = head; //current node initialized with head node
   while(curr != NULL)
   {
       final_gpa+=curr->data().get_number_grade()*curr->data().get_hours();
       curr->set_link(curr->link());
   }

   return (final_gpa/hours());
}

//returns total hours taken
double College::hours()
{
   double total_hours = 0.0;
   node* curr = head; //current node initialized with head node
   while(curr != NULL)
   {
       total_hours+=curr->data().get_hours();
       curr->set_link(curr->link());
   }
   return total_hours;
}

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