Microsoft Word - Project4-LinkedList.docx CSC136 – Program 4, LinkedList Assignment: Complete and test a template class implementing storage and manipulation of a linked list. Supplied:...

1 answer below »
Instructions in pdf file


Microsoft Word - Project4-LinkedList.docx  CSC136 – Program 4, LinkedList    Assignment: Complete and test a template class implementing storage and manipulation of a  linked list.  Supplied:  You will be provided, as a starting point, with incomplete versions of classes  named LinkedList and Student, as well as a completed LListIter iterator class. You  are also given stest.cpp, a stand‐alone test for the Student class and a partially  complete test program called LLtest.cpp as well as two files containing test data  named exam1 and exam2. Complied and runnable solution executables for both  of these are provided for comparison and are called ssoln and llsoln, respectively.  A makefile is also provided to create the final executables stest and lltest.  Location:  /export/home/public/carelli/csc136/Projects/Project4  Deliverable:  You should turn in the completed classes and test program (see Grading Critera).   Specifically, turn in only LinkedList.h, Student.cpp, and LLtest.cpp   Due:  The program MUST be turned in by the assigned date and time using turnin. Late  submissions will, in fact, be rejected by the script, resulting in a grade of zero.    Overview:  For this assignment you will be given a partially complete implementation of a linked list class in  a file called LinkedList.h. In addition, a file called ListIter.h contains an iterator class, which gets  included, and used, in LinkedList.h. The iterator is complete, so no work needs to be done on it.  The assignment directory also contains a partially complete driver program, called LLtest.cpp,  to test the linked list implementation. A working executable called llsoln produces the output  that the program should produce. There is also an implementation of a class called Student, in  two files, which is used in the test program as well as a makefile for compilation. A stand‐alone  test program for the Student class, together with a working executable called sstest.cpp and  ssoln, respectively, are provided as well.    Student:  The first part of the assignment is to complete the Student class. There is one method,  getAverage() and two operator overloads that need to be completed, as follows:   getAverage() ‐ return the average grade for the student   operator==() ‐ do the students have the same name?   operator+=(Student) ‐ add grades from student supplied as the right‐hand argument to  the left‐hand Student’s existing grades    Incomplete versions of these will be found at the end of the Student.cpp file. Once completed,  the results produced by the compiled stand‐alone Student test program, stest.cpp should agree  with what is produced by the provided solution executable ssoln.  LinkedList:  Write the code needed to implement the LinkedList methods, described below, which are  missing or incomplete. Empty implementations for the incomplete methods are at the end of  the LinkedList.h file as indicated by comments in the file. They are the following:   void add(T) – add an item to the end of the linked list – but only if it doesn’t already  exist in the list ‐ don’t add an entry twice! (hint: look at exists() method)   bool getEntry(T, &T) – find an item that matches the first argument and “return” it in  the second argument, which is passed by reference. Return true if successful, false  otherwise.   bool replace(T, T) ‐ replace an existing item that matches the first argument with the  item supplied in the second argument. Return true if successful, false otherwise.   void  mov2first(T) – move the item matching the given value to the beginning of the list  using only pointer manipulations!   void rotate() – rotate the order of items in the list using only pointer manipulations! The  first item in the list is moved to the last position.      LLtest:  LLtest.cpp, from which the makefile will produce the executable lltest, is a command‐based  driver program. It uses a linked list of Student objects. It provides a list of available commands  that can be executed, including one for loading student data from a file. It will be demonstrated  in class ‐ llsoln is a working version of the program that is also provided for comparison.   As the methods and operators detailed above are completed, different commands will begin to  work. In addition, you will need to complete several of the commands yourself, using the  provided commands as examples.   Part of the job is to examine the code and understand how the objects interact and make use of  defined operators and methods to accomplish the targeted behavior.    Major dependencies are as follows:  Commands:    loadFile:  To read an initial file:       LinkedList add()       To append data from a second file:       LinkedList getEntry(), replace() and Student += operator    Average Grade:   Student getAverage()    In addition to these, you will need to complete the code to implement the following  commands:    Find a Student:  Student ==       You must use a list iterator to search through the students      Note: an example can be found in calcAverage()      Move to top:   LinkedList mov2first()    Rotate list:   LinkedList rotate()    It is recommended that you complete the add() method first (after the Student Class is  complete). This will allow you to load an initial data file. Be sure to test multiple readins to  avoid duplicate entries. As additional methods are completed correctly, the output of LLtest will  begin to match what is provided by LLtestSoln.     Grading Criteria:  1. Turn in only LinkedList.h, Student.cpp, and LLtest.cpp on time using turnin – late  programs will receive a penalty. Very late programs will not be accepted. (10%)  2. Program must compile. (10%)  3. The program must be well commented/documented. (10%)  a. Using the departmental standard for documentation.  b. Include comments within your code to highlight important operations/techniques  c. Note: you only need to add departmental standard documentation for the  functions/methods that you write or modify – don’t worry about the rest.  4. Properly implement the given Student methods/operators. Test with stest.cpp. (15%)  5. Properly implement the LinkedList methods. (35%)  a. The methods given and…  b. The additional methods listed above  c. Follow the directions given   for ex. ‐ only use pointer manipulations in mov2first() and rotate()  6. Properly complete the LLtest code for the missing commands (given above). (20%)  Templates for adhering to the departmental documentation guidelines can be found in  CodeDocTemplate.txt under the Documents link on the course webpage.  Student.h #ifndef STUDENT_H #define STUDENT_H #include  #include  using namespace std; // A class for storing student information class Student { public:   // constructors/destructor   Student(string N= "") :       name(N), numGrades(0), grades(NULL) {};   Student(const Student &);   ~Student();   // get info   string getName() const { return name; }   float getNumGrades() const { return numGrades; }   const float operator[](int) const;   float getAverage() const;   // set info   void clear(); // remove existing info   void setName(string s) { name= s; }   // operators   Student &operator=(const Student &);   Student &operator+=(float);   Student &operator+=(Student);   bool operator==(const Student &); private:   string name;   int numGrades;   float *grades; }; // print out an employee ostream& operator<(ostream &, const student &);  input an employee from a file="" ifstream& operator="">>(ifstream &, Student &); #endif Student.cpp #include  #include  #include  #include  #include "Student.h" using namespace std; // copy constructor Student::Student(const Student& E) {   name= E.name;   numGrades= E.numGrades;   grades= NULL;   if(E.grades) {     grades=new float[numGrades];     for(int i=0; i= 0 && subscript < numgrades );   return grades[ subscript ]; // const reference return="" }=""  get the total grades="" float student::getaverage() const {=""   if(numgrades ="= 0) return 0;"   float total="0;"   for(int i="">< numgrades; i++ )     grades[ i ] =" right.grades[ i ];  // copy array into object"   }=""  return *this;   // enables x =" y = z;" }=""  append element to end of array="" student &student::operator+="(float value) {"   float *temp="new float[numGrades+1];"   for(int i=""><(ostream &os, const student &e) {><><>< e.getname();><>< setprecision(1);><><><><>< " : ";   for(int i=""><><><>< e[i];   }="">< endl;   return os;="" }=""  input a student="" ifstream& operator="">>(ifstream &ifs, Student &E) {   E.clear(); // remove existing information   string name; int num; float value;   ifs >> name >> value;   E.setName(name);   E+= value;   return ifs; } ////////////////////////////////////////// // Complete these two operators ////////////////////////////////////////// // Append grades from existing student to this one Student &Student::operator+=(Student S) { } // same person? bool Student::operator==(const Student &E) { } Stest.cpp #include  #include  #include  #include  #include "Student.h" using namespace std; int main() {    Student E1("chris");    Student E2("sam");    E1+= 70;    E1+= 80;    E1+= 90;    cout <>< endl;>< e1;><><>< endl;    e2+=" 85;"    e2+=" 95;">< endl;><>< endl;>< e2;><><>< endl;><>< endl;><><>< endl;>< endl;><>< endl;    e1+=" E2;">< e1; } desired output for students: e1: chris 80.0 : 70.0 80.0 90.0 average: 80.0 e2: sam 90.0 : 85.0 95.0 average: 90.0 e1 == e2 ? false e1+= e2: chris 84.0 : 70.0 80.0 90.0 85.0 95.0 desired output for linkedlist: ----------------------- l)oad file d)isplay students f)ind an student c)lass average m)ove item to top of list r)otate list q)uit please make a selection: l please enter the name of the data file: exam1 mary 70.0 : 70.0 joe 92.0 : 92.0 chris 65.0 : 65.0 sam 82.0 : 82.0 ----------------------- l)oad file d)isplay students f)ind an student c)lass average m)ove item to top of list r)otate list q)uit please make a selection: c average student grade: 77.2 ----------------------- l)oad file d)isplay students f)ind an student c)lass average m)ove item to top of list r)otate list q)uit please make a selection: l please enter the name of the data file: exam2 mary 80.0 : 70.0 90.0 joe 84.5 : 92.0 77.0 chris 72.0 : 65.0 79.0 sam 77.5 : 82.0 73.0 ----------------------- l)oad file d)isplay students f)ind an student c)lass average m)ove item to top of list r)otate list q)uit please make a selection: q type 'q' again to confirm! q contents of exam 1 data file: mary 70 joe 92 chris 65 sam 82 contents of exam 2: mary 90 joe 77 chris 79 sam 73 }="" desired="" output="" for="" students:="" e1:="" chris="" 80.0="" :="" 70.0="" 80.0="" 90.0="" average:="" 80.0="" e2:="" sam="" 90.0="" :="" 85.0="" 95.0="" average:="" 90.0="" e1="=" e2="" false="" e1+="E2:" chris="" 84.0="" :="" 70.0="" 80.0="" 90.0="" 85.0="" 95.0="" desired="" output="" for="" linkedlist:="" -----------------------="" l)oad="" file="" d)isplay="" students="" f)ind="" an="" student="" c)lass="" average="" m)ove="" item="" to="" top="" of="" list="" r)otate="" list="" q)uit="" please="" make="" a="" selection:="" l="" please="" enter="" the="" name="" of="" the="" data="" file:="" exam1="" mary="" 70.0="" :="" 70.0="" joe="" 92.0="" :="" 92.0="" chris="" 65.0="" :="" 65.0="" sam="" 82.0="" :="" 82.0="" -----------------------="" l)oad="" file="" d)isplay="" students="" f)ind="" an="" student="" c)lass="" average="" m)ove="" item="" to="" top="" of="" list="" r)otate="" list="" q)uit="" please="" make="" a="" selection:="" c="" average="" student="" grade:="" 77.2="" -----------------------="" l)oad="" file="" d)isplay="" students="" f)ind="" an="" student="" c)lass="" average="" m)ove="" item="" to="" top="" of="" list="" r)otate="" list="" q)uit="" please="" make="" a="" selection:="" l="" please="" enter="" the="" name="" of="" the="" data="" file:="" exam2="" mary="" 80.0="" :="" 70.0="" 90.0="" joe="" 84.5="" :="" 92.0="" 77.0="" chris="" 72.0="" :="" 65.0="" 79.0="" sam="" 77.5="" :="" 82.0="" 73.0="" -----------------------="" l)oad="" file="" d)isplay="" students="" f)ind="" an="" student="" c)lass="" average="" m)ove="" item="" to="" top="" of="" list="" r)otate="" list="" q)uit="" please="" make="" a="" selection:="" q="" type="" 'q'="" again="" to="" confirm!="" q="" contents="" of="" exam="" 1="" data="" file:="" mary="" 70="" joe="" 92="" chris="" 65="" sam="" 82="" contents="" of="" exam="" 2:="" mary="" 90="" joe="" 77="" chris="" 79="" sam="">
Answered Same DayApr 29, 2021

Answer To: Microsoft Word - Project4-LinkedList.docx CSC136 – Program 4, LinkedList...

Ria answered on May 01 2021
126 Votes
#include
#include
#include
#include
#include"Student.h"
u
sing namespace std;
//copyconstructor
Student::Student(const Student& E) {
    name = E.name;
    numGrades = E.numGrades;
    grades = NULL;
    if (E.grades) {
        grades = new float[numGrades];
        for (int i = 0; i < numGrades; i++) { grades[i] = E.grades[i]; }
    }
}
//destructor
Student::~Student() {
    delete[] grades;
}
// delete existing information
void Student::clear() {
    name = ""; numGrades = 0;
    if (grades) delete[] grades;
    grades = NULL;
}
// Overloaded subscript operator
// const reference return creates an rvalue
const float Student::operator[](int subscript) const {
    // check for subscript out of range error
    assert(subscript >= 0 && subscript< numGrades );
    return grades[subscript ]; // const reference return
}
// get the total grades
float Student::getAverage() const {
    if (numGrades == 0) return 0;
    float total = 0;
    for (int i = 0; i <...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here