0

Hey all. I have worked with a project to create a basic student database/registration system for the past 4-5 projects... slowly adding more functionality or using different containers and classes etc.

For this next project, i am to use the code from a website online which contains all the nescessary code for an AVL tree. With using this, i created a new class in my code, called StudentGrade.

The idea is to read in from a text file, with multiple students, insert the data into a linked list of the student data (name, ID, DOB, gender) and a list of their classes taken.

There is multiple files with this project, so it may look like a right pain the butt, but please give it a try, i would REALLY appreciate the help and advice on this one.

If you have any questions about the way in which the program should work, then please post and i will get back to you asap.

Thanks a ton

Attachments
#ifndef H_340
#define H_340

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

#include <cstdlib>
#include <climits>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <functional>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <stdexcept>
using namespace std;
#endif
// <plaintext>
#ifndef AVL_H
#define AVL_H

#include <cstddef>
#include <cstdlib>
#include "Comparable.h"
#include <iostream>
#include "StudentGrade.h"


// Indices into a subtree array
//     NOTE: I would place this inside the AvlNode class but 
//           when I do, g++ complains when I use dir_t. Even
//           when I prefix it with AvlNode:: or AvlNode<KeyType>::
//           (If you can get this working please let me know)
//
enum  dir_t { LEFT = 0, RIGHT = 1 };

// AvlNode -- Class to implement an AVL Tree
//
template <class KeyType>
class AvlNode {
public:
      // Max number of subtrees per node
   enum  { MAX_SUBTREES = 2 };

      // Return the opposite direction of the given index
   static  dir_t
   Opposite(dir_t dir) { 
     return dir_t(1 - int(dir));
   }

   // ----- Constructors and destructors: 

   AvlNode(Comparable<KeyType>  * item=NULL);
   virtual ~AvlNode(void);

   // ----- Query attributes:

      // Get this node's data
   Comparable<KeyType> *
   Data() const { return  myData; }

      // Get this node's key field
   KeyType
   Key() const { return  myData->Key(); }

      // Query the balance factor, it will be a value between -1 .. 1
      // where:
      //     -1 => left subtree is taller than right subtree
      //      0 => left and right subtree are equal in height
      //      1 => right subtree is taller than left subtree
   short
   Bal(void) const { return  myBal; }

      // Get the item at the top of the left/right subtree of this
      // item (the result may be NULL if there is no such item).
      //
   AvlNode *
   Subtree(dir_t dir) const { return  mySubtree[dir]; }

   // ----- Search/Insert/Delete
   //
   //   NOTE: These are all static functions instead of member functions
   //         because most of them need to modify the given tree root
   //         pointer. If these were instance member functions than
   //         that would correspond to having to modify the 'this'
   //         pointer, which is not allowed in C++. Most of the 
   //         functions that are static and which take an AVL tree
   //         pointer as a parameter are static for this reason.
   
      // Look for the given key, return NULL if not found,
      // otherwise return the item's address.
   static Comparable<KeyType> *
   Search(KeyType key, AvlNode<KeyType> * root, cmp_t cmp=EQ_CMP);

      // Insert the given key, return NULL if it was inserted,
      // otherwise return the existing item with the same key.
   static Comparable<KeyType> *
   Insert(Comparable<KeyType> * item, AvlNode<KeyType> * & root);

      // Delete the given key from the tree. Return the corresponding
      // node, or return NULL if it was not found.
   static Comparable<KeyType> *
   Delete(KeyType key, AvlNode<KeyType> * & root, cmp_t cmp=EQ_CMP);

   // Verification 

      // Return the height of this tree
   int
   Height() const;

      // Verify this tree is a valid AVL tree, return TRUE if it is,
      // return FALSE otherwise
   int
   Check() const;

      // If you want to provide your own allocation scheme than simply
      // #define the preprocessor manifest constant named CUSTOM_ALLOCATE
      // and make sure you provide and link with your own overloaded
      // versions of operators "new" and "delete" for this class.
#ifdef CUSTOM_ALLOCATE
   void *
   operator  new(size_t);

   void
   operator  delete(void *);
#endif  /* CUSTOM_ALLOCATE */


private:

   // ----- Private data

   Comparable<KeyType> * myData;  // Data field
   AvlNode<KeyType>    * mySubtree[MAX_SUBTREES];   // Pointers to subtrees
   short      myBal;   // Balance factor

      // Reset all subtrees to null and clear the balance factor
   void
   Reset(void) {
      myBal = 0 ;
      mySubtree[LEFT] = mySubtree[RIGHT] = NULL ;
   }

   // ----- Routines that do the *real* insertion/deletion

      // Insert the given key into the given tree. Return the node if
      // it already exists. Otherwise return NULL to indicate that
      // the key was successfully inserted.  Upon return, the "change"
      // parameter will be '1' if the tree height changed as a result
      // of the insertion (otherwise "change" will be 0).
   static Comparable<KeyType> *
   Insert(Comparable<KeyType> * item,
             AvlNode<KeyType> * & root,
             int & change);

      // Delete the given key from the given tree. Return NULL if the
      // key is not found in the tree. Otherwise return a pointer to the
      // node that was removed from the tree.  Upon return, the "change"
      // parameter will be '1' if the tree height changed as a result
      // of the deletion (otherwise "change" will be 0).
   static Comparable<KeyType> *
   Delete(KeyType key,
             AvlNode<KeyType> * & root,
             int & change,
             cmp_t cmp=EQ_CMP);

   // Routines for rebalancing and rotating subtrees

      // Perform an XX rotation for the given direction 'X'.
      // Return 1 if the tree height changes due to rotation,
      // otherwise return 0.
   static int
   RotateOnce(AvlNode<KeyType> * & root, dir_t dir);

      // Perform an XY rotation for the given direction 'X'
      // Return 1 if the tree height changes due to rotation,
      // otherwise return 0.
   static int
   RotateTwice(AvlNode<KeyType> * & root, dir_t dir);

      // Rebalance a (sub)tree if it has become imbalanced
   static int
   ReBalance(AvlNode<KeyType> * & root);

      // Perform a comparison of the given key against the given
      // item using the given criteria (min, max, or equivalence
      // comparison). Returns:
      //   EQ_CMP if the keys are equivalent
      //   MIN_CMP if this key is less than the item's key
      //   MAX_CMP if this key is greater than item's key
   cmp_t
   Compare(KeyType key, cmp_t cmp=EQ_CMP) const;

private:
      // Disallow copying and assignment
   AvlNode(const AvlNode<KeyType> &);
   AvlNode & operator=(const AvlNode<KeyType> &);

};


   // Class AvlTree is a simple container object to "house" an AvlNode
   // that represents the root-node of and AvlTree. Most of the member
   // functions simply delegate to the root AvlNode.
template <class KeyType>
class AvlTree {
private:
      // Disallow copying and assingment
   AvlTree(const AvlTree<KeyType> &);
   AvlTree & operator=(const AvlTree<KeyType> &);

      // Member data
   AvlNode<KeyType> * myRoot;   // The root of the tree

public:
      // Constructor and destructor
   AvlTree() : myRoot(NULL) {};
   ~AvlTree() { if (myRoot)  delete myRoot; }

      // Dump the tree to the given output stream
   void
   DumpTree(ostream & os) const;

      // See if the tree is empty
   int
   IsEmpty() const {
      return  (myRoot == NULL);
   }

      // Search, Insert, Delete, and Check
   Comparable<KeyType> *
   Search(KeyType key, cmp_t cmp=EQ_CMP) {
      return  AvlNode<KeyType>::Search(key, myRoot, cmp);
   }

   Comparable<KeyType> *
   Insert(Comparable<KeyType> * item) {
      return  AvlNode<KeyType>::Insert(item, myRoot);
   }

   Comparable<KeyType> *
   Delete(KeyType key, cmp_t cmp=EQ_CMP) {
      return  AvlNode<KeyType>::Delete(key, myRoot, cmp);
   }

   int
   Check() const {
      return  (myRoot) ? myRoot->Check() : 1;
   }
};

// ---------------------------------------------------------------- Definitions

   // Return the minumum of two numbers
inline static int
MIN(int a, int b) {
   return  (a < b) ? a : b;
}

   // Return the maximum of two numbers
inline static int
MAX(int a, int b) {
   return  (a > b) ? a : b;
}

   // Use mnemonic constants for valid balance-factor values
enum balance_t { LEFT_HEAVY = -1, BALANCED = 0, RIGHT_HEAVY = 1 };

   // Use mnemonic constants for indicating a change in height
enum height_effect_t { HEIGHT_NOCHANGE = 0, HEIGHT_CHANGE = 1 };

   // Return true if the tree is too heavy on the left side
inline static int
LEFT_IMBALANCE(short bal) {
   return (bal < LEFT_HEAVY);
}

   // Return true if the tree is too heavy on the right side
inline static int
RIGHT_IMBALANCE(short bal) {
   return (bal > RIGHT_HEAVY);
}

// ----------------------------------------------- Constructors and Destructors

template <class KeyType>
AvlNode<KeyType>::AvlNode(Comparable<KeyType> * item)
   : myData(item), myBal(0)
{
   Reset();
}

template <class KeyType>
AvlNode<KeyType>::~AvlNode(void) {
   if (mySubtree[LEFT])  delete  mySubtree[LEFT];
   if (mySubtree[RIGHT]) delete  mySubtree[RIGHT];
}

// ------------------------------------------------- Rotating and Re-Balancing

template <class KeyType>
int
AvlNode<KeyType>::RotateOnce(AvlNode<KeyType> * & root, dir_t dir)
{
   dir_t  otherDir = Opposite(dir);
   AvlNode<KeyType> * oldRoot = root;

      // See if otherDir subtree is balanced. If it is, then this
      // rotation will *not* change the overall tree height.
      // Otherwise, this rotation will shorten the tree height.
   int  heightChange = (root->mySubtree[otherDir]->myBal == 0)
                          ? HEIGHT_NOCHANGE
                          : HEIGHT_CHANGE;

      // assign new root
   root = oldRoot->mySubtree[otherDir];

      // new-root exchanges it's "dir" mySubtree for it's parent
   oldRoot->mySubtree[otherDir] = root->mySubtree[dir];
   root->mySubtree[dir] = oldRoot;

      // update balances
   oldRoot->myBal = -((dir == LEFT) ? --(root->myBal) : ++(root->myBal));

   return  heightChange;
}

template <class KeyType>
int
AvlNode<KeyType>::RotateTwice(AvlNode<KeyType> * & root, dir_t dir)
{
   dir_t  otherDir = Opposite(dir);
   AvlNode<KeyType> * oldRoot = root;
   AvlNode<KeyType> * oldOtherDirSubtree = root->mySubtree[otherDir];

      // assign new root
   root = oldRoot->mySubtree[otherDir]->mySubtree[dir];

      // new-root exchanges it's "dir" mySubtree for it's grandparent
   oldRoot->mySubtree[otherDir] = root->mySubtree[dir];
   root->mySubtree[dir] = oldRoot;

      // new-roo
// <plaintext>
#ifndef COMPARABLE_H
#define COMPARABLE_H

#include <iostream>

// cmp_t is an enumeration type indicating the result of a
// comparison.
//     NOTE: I would place this inside the Comparable class but 
//           when I do, g++ complains when I use cmp_t. Even
//           when I prefix it with Comparable:: or Comparable<KeyType>::
//           (If you can get this working please let me know)
//
enum  cmp_t {
   MIN_CMP = -1,   // less than
   EQ_CMP  = 0,    // equal to
   MAX_CMP = 1     // greater than
};

// Class "Comparable" corresponds to an arbitrary comparable element
// with a keyfield that has an ordering relation. The template parameter
// KeyType is the "type" of the keyfield
//
template <class KeyType>
class Comparable {
private:
   KeyType  myKey;

public:
   Comparable(KeyType  key) : myKey(key) {};

   // Use default copy-ctor, assignment, & destructor

      // Compare this item against the given key & return the result
   cmp_t Compare(KeyType  key) const {
      return (key == myKey) ? EQ_CMP
                            : ((key < myKey) ? MIN_CMP : MAX_CMP);
   }

     // Get the key-field of an item
   KeyType Key() const { return  myKey; }

     // Print on output stream
   ostream &
   Print(ostream & os) const { 
      os << myKey;
      return  os;
   }
};

template <class KeyType>
inline ostream & operator<<(ostream & os, Comparable<KeyType> item) {
   return  item.Print(os);
}

#endif  /* COMPARABLE_H */
#include "courseInfo.h"

/****************************************************************
   FUNCTION:   courseInfo()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the constructor for the CourseInfo class
****************************************************************/
CourseInfo::CourseInfo()
{
}

/****************************************************************
   FUNCTION:   ~CourseInfo()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the destructor for the CourseInfo class
****************************************************************/
CourseInfo::~CourseInfo()
{
}

/****************************************************************
   FUNCTION:   getCourseID() const
   ARGUMENTS:  none
   RETURNS:    string courseID
   NOTES:      this function returns the courseID for the student
****************************************************************/
string CourseInfo::getCourseID() const
{
	return courseID;
}

/****************************************************************
   FUNCTION:   setCourseID(const string &x)
   ARGUMENTS:  const string &x
   RETURNS:    none
   NOTES:      this function sets the courseID for the student
****************************************************************/
void CourseInfo::setCourseID(string x)
{
	courseID = x;
}

/****************************************************************
   FUNCTION:   setYearTaken(const string &x)
   ARGUMENTS:  const string &x - the new YearTaken
   RETURNS:    none
   NOTES:      this function sets the students YearTaken for a course
****************************************************************/
void CourseInfo::setYearTaken(string x)
{
	yearTaken = x;
}

/****************************************************************
   FUNCTION:   getYearTaken() const
   ARGUMENTS:  none
   RETURNS:    string yearTaken
   NOTES:      this returns the students YearTaken for a certain class
****************************************************************/
string CourseInfo::getYearTaken() const
{
	return yearTaken;
}

/****************************************************************
   FUNCTION:   setSemesterTaken(const string &x)
   ARGUMENTS:  const string &x - the semesterTaken value
   RETURNS:    none
   NOTES:      this function sets the students semester taken for
               a specific course
****************************************************************/
void CourseInfo::setSemesterTaken(string x)
{
	semesterTaken = x;
}

/****************************************************************
   FUNCTION:   getSemesterTaken() const
   ARGUMENTS:  none
   RETURNS:    string semesterTaken - returns the semester taken
   NOTES:      this function gets the students semester taken
****************************************************************/
string CourseInfo::getSemesterTaken() const
{
	return semesterTaken;
}

/****************************************************************
   FUNCTION:   setGrade(const string &x)
   ARGUMENTS:  const string &x
   RETURNS:    none
   NOTES:      this functions sets the grade for a certain class
****************************************************************/     
void CourseInfo::setGrade(string x)
{
	grade = x;
}
      
/****************************************************************
   FUNCTION:   getGrade() const
   ARGUMENTS:  none
   RETURNS:    string grade
   NOTES:      this function returns the grade of the student in 
                a specific class
****************************************************************/
string CourseInfo::getGrade() const
{
	return grade;
}

/****************************************************************
   FUNCTION:   operator==()
   ARGUMENTS:  CourseInfo object
   RETURNS:    bool t/f
   NOTES:      this overloads the equal to operator
****************************************************************/
bool CourseInfo::operator==(const CourseInfo & right) const
{
	return (courseID == right.getCourseID() &&
	 semesterTaken == right.semesterTaken && yearTaken == 
	 right.yearTaken); //
}
#ifndef COURSEINFO_H
#define COURSEINFO_H

#include "340.h"

class CourseInfo {
	public:
      CourseInfo();
      virtual ~CourseInfo();
      void setCourseID(string x);
      string getCourseID() const;
      void setYearTaken(string x);
      string getYearTaken() const;
      void setSemesterTaken(string x);
      string getSemesterTaken() const;
      void setGrade(string x);
      string getGrade() const;
      bool operator==(const CourseInfo &right) const;
      
    private:
      string courseID;
      string yearTaken;
      string semesterTaken;
      string grade;
      int count;
      
};


#endif //COURSEINFO_H
#include "Person.h"
#include "courseInfo.h"
#include "Student.h"
#include "Registration.h"
#include "Avl.h"

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
//create Student object and declare variables to be used in creating student
Student s1;
//bool empty;
string file;
fstream inFile;

Registration registrationSystem;

string classID,
	   year,
	   semester,
	   answer = "Y";

registrationSystem.loadInfoFromFile();
cout << "Student who have taken CSCI333 in the Fall of 2006" << endl;
registrationSystem.printScoreList("CSCI333", "2006", "Fall");
/*
while (answer == "Y" || answer == "y")
{
	cout << "Please enter classID: ";
	cin >> classID;
	cout << "\nPlease enter year: ";
	cin >> year;
	cout << "\nPlease enter semster: ";
	cin >> semester;
	cout << "Students who have taken " << classID << " in the " << semester << " of " << year << endl;
	registrationSystem.printScoreList(classID, year, semester);
	cout << "Would you like to search for another class? (Y/N):";
	cin >> answer;
}
*/
cout << "***  END OF PROGRAM OUTPUT  ***" << endl;

return 0;
}//end main
#ifndef LINKEDSTACK_H
#define LINKEDSTACK_H

#include "340.h"
#include "SinglyLinkedList.h"

template <class T>
class linkedStack: public SinglyLinkedList<T>
{
public:
	linkedStack() {};
	virtual ~linkedStack() {};
	bool isEmptyStack();
	bool isFullStack();
	void push(const T& newItem);
	nodeSLL<T> * top();
	void pop();

protected:
	int count;
};

/****************************************************************
   FUNCTION:   isEmptyStack()
   ARGUMENTS:  none
   RETURNS:    bool - if true'false empty
   NOTES:      returns true if empty false if full
****************************************************************/ 
template <class T>
bool linkedStack<T>::isEmptyStack() 
{
	return SinglyLinkedList<T>::isEmpty();
}

/****************************************************************
   FUNCTION:   isFullStack()
   ARGUMENTS:  none
   RETURNS:    bool - true/false
   NOTES:      returns true if full
****************************************************************/ 
template <class T>
bool linkedStack<T>::isFullStack()
{
     if (count < 10) return false;
     else return true;
}

/****************************************************************
   FUNCTION:   push()
   ARGUMENTS:  newElment
   RETURNS:    none
   NOTES:      this adds a new element to the list
****************************************************************/ 
template <class T>
void linkedStack<T>::push(const T& newElement)
{
    if (isFullStack() == false)
       { 
       SinglyLinkedList<T>::addToHead(newElement);
	     count++; 
        }
    else 
         cout << "Stack Overflow...\n";
}

/****************************************************************
   FUNCTION:   top()
   ARGUMENTS:  none
   RETURNS:    nodeSLL<T> *
   NOTES:      returns the node at head of list
****************************************************************/ 
template <class T>
nodeSLL<T> * linkedStack<T>::top() 
{
	return SinglyLinkedList<T>::getHead();
}

/****************************************************************
   FUNCTION:   pop()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      removes the top node in the head position of list
****************************************************************/ 
template <class T>
void linkedStack<T>::pop()
{
    if (isEmptyStack() == false)
       { CourseInfo temp = top()->info;
         SinglyLinkedList<T>::deleteNode(temp);
	     count--;
      }
    else cout << "Stack Underflow...\n";
}

#endif // END IF LINKEDSTACK.H
#include "Person.h"

/****************************************************************
   FUNCTION:   Person()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the Person() constructor
****************************************************************/
Person::Person()
{
}

/****************************************************************
   FUNCTION:   ~Person()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the Person destructor
****************************************************************/      
Person::~Person()
{
}

/****************************************************************
   FUNCTION:   setFirstName(const string &x)
   ARGUMENTS:  const string &x - the first name of student
   RETURNS:    none
   NOTES:      this function sets the students first name
****************************************************************/
void Person::setFirstName(string &x)
{
     firstName = x;
}

/****************************************************************
   FUNCTION:   getFirstname() const
   ARGUMENTS:  none
   RETURNS:    string firstName
   NOTES:      this function returns the students first name
****************************************************************/
string Person::getFirstName() const 
{
     return firstName;
}

/****************************************************************
   FUNCTION:   setLastName(const string &x)
   ARGUMENTS:  const string &x - the students last name
   RETURNS:    none
   NOTES:      this function sets the students last name
****************************************************************/
void Person::setLastName(string &x) 
{
     lastName = x;
}

/****************************************************************
   FUNCTION:   getLastName() const
   ARGUMENTS:  none
   RETURNS:    string lastName
   NOTES:      this function returns the students last name
****************************************************************/
string Person::getLastName() const 
{
     return lastName;
}

/****************************************************************
   FUNCTION:   setSSN(const string &x)
   ARGUMENTS:  const string &x
   RETURNS:    none
   NOTES:      this function sets the students SSN
****************************************************************/
void Person::setSSN(string &x) 
{
     SSN = x;
}

/****************************************************************
   FUNCTION:   getSSN() const
   ARGUMENTS:  none
   RETURNS:    string SSN
   NOTES:      this function returns the students SSN
****************************************************************/
string Person::getSSN() const 
{
       return SSN;
}

/****************************************************************
   FUNCTION:   setDOB(const string &x)
   ARGUMENTS:  const string &x - the students DOB
   RETURNS:    none
   NOTES:      this function sets the students DOB
****************************************************************/
void Person::setDOB(string &x) 
{
     DOB = x;
}

/****************************************************************
   FUNCTION:   getDOB() const
   ARGUMENTS:  none
   RETURNS:    string DOB
   NOTES:      this function returns the students DOB
****************************************************************/
string Person::getDOB() const 
{
       return DOB;
}

/****************************************************************
   FUNCTION:   setGender(const string &x)
   ARGUMENTS:  const string &x - the students gender
   RETURNS:    none
   NOTES:      this function sets the student gender
****************************************************************/
void Person::setGender(string &x) 
{
     gender = x;
}

/****************************************************************
   FUNCTION:   getGender() const
   ARGUMENTS:  none
   RETURNS:    string gender 
   NOTES:      this function returns the students gender
****************************************************************/
string Person::getGender() const 
{
       return gender;
}
#ifndef PERSON_H
#define PERSON_H

#include "340.h"

class Person {
	public:
      Person();
      virtual ~Person();
      void setFirstName(string &x);
      string getFirstName() const;
      void setLastName(string &x);
      string getLastName() const;
      void setSSN(string &x);
      string getSSN() const;
      void setDOB(string &x);
      string getDOB() const;
      void setGender(string &x);
      string getGender() const;
      
    private:
      string firstName;
      string lastName;
      string SSN;
      string DOB;
      string gender;
};

#endif //PERSON_H
#ifndef REGISTRATION_H
#define REGISTRATION_H

#include "340.h"
#include "SinglyLinkedList.h"
#include "BST.h"
#include "Avl.h"
#include "Registration.h"
#include "StudentGrade.h"

struct course
{
	string ZID;
	string grade;
	string firstName;
	string lastName;
};


class Registration
{
public:
	Registration() { };
	virtual ~Registration() { };
	void loadInfoFromFile();
	void printScoreList(string courseID, string yearTaken, string semesterTaken);
protected:
	list<Student> students;
};

void Registration::loadInfoFromFile()
{
	fstream inFile;
	string file;
	Student s1;

	cout << endl << "Enter file name for student data: ";
	cin >> file;

	inFile.open(file.c_str());

	if(!inFile)
    {
		cout << "Can't open " << file << ", program terminated." << endl;
	}

	string firstName, lastName, SSN, DOB, gender, 
		   ZID, courseID, year, semester, grade;

	while (inFile)
	{
	inFile >> firstName;
	s1.setFirstName(firstName);
	inFile >> lastName;
	s1.setLastName(lastName);
	inFile >> SSN;
	s1.setSSN(SSN);
	inFile >> DOB;
	s1.setDOB(DOB);
	inFile >> gender;
	s1.setGender(gender);
	inFile >> ZID;
	s1.setZID(ZID);
	//start class read
	inFile >> courseID;
	
	while (inFile && courseID != "$")
	{
		inFile >> year;
		inFile >> semester;
		inFile >> grade;
		 
		CourseInfo courses;
		courses.setCourseID(courseID);
		courses.setYearTaken(year);
		courses.setSemesterTaken(semester);
		courses.setGrade(grade);
	
		s1.addCourse(s1.getZID(), courses);
		inFile >> courseID;
	}
	students.push_front(s1);
	s1.clearCourseList();
}

inFile.close();
}

void Registration::printScoreList(string courseID, string yearTaken, string semesterTaken)
{
	/*
	You can insert a new item into the AVL tree using the following steps:
   1. Create a StudentGrade object from the name, z-id, and grade your search has found:
      StudentGrade gradeFound(..., ..., ...);
      (This StudentGrade object can be used repeatedly and over.)
   2. Dynamically create a Comparable object to contain your StudentGrade object:
      Comparable<StudentGrade>* newItem = new Comparable<StudentGrade>(gradeFound);
   3. Insert the Comparable object into the AVL tree:
      gradeTree.Insert(newItem);
You can print a listing of the AVL tree by calling the DumpTree() method:
   gradeTree.DumpTree(cout);

   */
   AvlTree<StudentGrade> gradeTree;
   StudentGrade data;
   list<Student>::iterator i;
   for(i = students.begin(); i != students.end(); ++i) 
   {
		data.setGrade((*i).checkCourseTaken(courseID, yearTaken, semesterTaken));
		if (data.getGrade() != "failed")
		{  
			data.setFirstName((*i).getFirstName());
			data.setLastName((*i).getLastName());
			data.setZID((*i).getZID());
			Comparable<StudentGrade>* newItem = new Comparable<StudentGrade>(data);
			gradeTree.Insert(newItem);
		}
   }
   //gradeTree.DumpTree(cout);
//   Comparable<StudentGrade>* newItem = new Comparable<StudentGrade>(grade);
    /*
    StudentGrade data;
	list<Student>::iterator i;
	for(i = students.begin(); i != students.end(); ++i) 
	{
		//cout << "in for statement" << endl;
		data.setGrade((*i).checkCourseTaken(courseID, yearTaken, semesterTaken));
		if (data.getGrade() != "failed")
		{
            
			data.setFirstName((*i).getFirstName());
			data.setLastName((*i).getLastName());
			data.setZID((*i).getZID());
			gradeTree.Insert(data);
		}
		//cout << "after function call" << endl;
	}
	gradeTree.DumpTree(cout);
*/
}

#endif //REGISTRATION.H
#include "Student.h"


/****************************************************************
   FUNCTION:   Student()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the Student class constructor
****************************************************************/
Student::Student()
{
	count = 0;
}

/****************************************************************
   FUNCTION:   ~Student()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this is the destructor for the Student class
****************************************************************/   
Student::~Student()
{
}

/****************************************************************
   FUNCTION:   incrementCount()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      This function increments count so that the number
               of classes added are counted on entry
****************************************************************/
void Student::incrementCount()
{
	count = count + 1;
}

/****************************************************************
   FUNCTION:   getZID()
   ARGUMENTS:  none
   RETURNS:    ZID - returns the students ZID number
   NOTES:      This function simply returns the students ZID#
****************************************************************/
string Student::getZID() const
{
     return ZID;
}

/****************************************************************
   FUNCTION:   setZID(const string &x)
   ARGUMENTS:  string x
   RETURNS:    none
   NOTES:      this function sets the students ZID with the value
               passed to it.
****************************************************************/
void Student::setZID(string &x)
{
     ZID = x;
}

/****************************************************************
   FUNCTION:   getCount() const
   ARGUMENTS:  none
   RETURNS:    int count
   NOTES:      this function returns the count of the number of 
               classes added to the students registration etc
****************************************************************/
int Student::getCount() const
{
	return count;
}

/****************************************************************
   FUNCTION:   infoPrint()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this prints the students information, including the
               basic information, aswell as class information
****************************************************************/
void Student::infoPrint()
{		
	cout << getFirstName() << " " << getLastName() << " "
		 << getSSN() << " " << getDOB() << " " << getGender() 
		 << " " << getZID() << endl;  
	
	nodeSLL<CourseInfo> * next = courseList.getHead();

	while (next != NULL)
	{
		cout << next->info.getCourseID() << " "
		     << next->info.getYearTaken() << " "
		     << next->info.getSemesterTaken() << " " 
		     << next->info.getGrade() << endl;
		next = next->next;
	}
}

void Student::loadInfoFromFile(fstream& inFile)
{
	string firstName, lastName, SSN, DOB, gender, 
		   ZID, courseID, year, semester, grade;

	inFile >> firstName;
	setFirstName(firstName);
	inFile >> lastName;
	setLastName(lastName);
	inFile >> SSN;
	setSSN(SSN);
	inFile >> DOB;
	setDOB(DOB);
	inFile >> gender;
	setGender(gender);
	inFile >> ZID;
	setZID(ZID);

	//start class read
	inFile >> courseID;
	
	while (inFile)
	{
	inFile >> year;
	inFile >> semester;
	inFile >> grade;
		 
	CourseInfo courses;
	courses.setCourseID(courseID);
	courses.setYearTaken(year);
	courses.setSemesterTaken(semester);
	courses.setGrade(grade);
	
	addCourse(getZID(), courses);
	inFile >> courseID;
	}
  }

/****************************************************************
   FUNCTION:   addCourse()
   ARGUMENTS:  none
   RETURNS:    none
   NOTES:      this adds a course to the front of the list
****************************************************************/
void Student::addCourse(string ZID, const CourseInfo& c1)
{
	courseList.addToHead(c1);
}

/****************************************************************
   FUNCTION:   deleteCourse()
   ARGUMENTS:  const CourseInfo& delCourse
   RETURNS:    none
   NOTES:      this functions deletes a course from the list
****************************************************************/
void Student::deleteCourse(const CourseInfo& delCourse)
  {
  // Call the deleteNode() method for the linked list of courses
  courseList.deleteNode(delCourse);
  }

/****************************************************************
   FUNCTION:   checkCourseTaken()
   ARGUMENTS:  string zid, CourseInfo c1
   RETURNS:    CourseInfo
   NOTES:      this function checks if a course was taken
****************************************************************/
CourseInfo Student::checkCourseTaken(string ZID, CourseInfo c1)
{
	courseList.checkCourseTaken(c1);
	return c1;
}

/****************************************************************
   FUNCTION:   checkCourseTaken()
   ARGUMENTS:  string courseId, string year, string semester
   RETURNS:    string grade
   NOTES:      this function checks if a course was taken
****************************************************************/
string Student::checkCourseTaken(string courseID, string year, string semester)
{
	CourseInfo temp;
	temp.setCourseID(courseID);
	temp.setYearTaken(year);
	temp.setSemesterTaken(semester);

	nodeSLL<CourseInfo> * next = courseList.getHead();

	while (next != NULL)
	{
		if (next->info == temp)
			return next->info.getGrade();
		next = next->next;
	}
	return "failed";
}

void Student::clearCourseList()
{
	courseList.clear();
}
#ifndef STUDENT_H
#define STUDENT_H

#include "Person.h"
#include "courseInfo.h"
#include "LinkedStack.h"
#include "340.h"

class Student : public Person {
    public:
      Student();
      virtual ~Student(); 
      string getZID() const;
      void setZID(string &x);    
      void incrementCount();
      int getCount() const;
      void infoPrint(); 
      void loadInfoFromFile(fstream& inFile);
      SinglyLinkedList<CourseInfo> courseList;
      void addCourse(string, const CourseInfo &);
      void deleteCourse(const CourseInfo&);
      CourseInfo checkCourseTaken(string, CourseInfo);
	  string checkCourseTaken(string, string, string);
      void clearCourseList();

    private:
      string ZID;
      int count;
};

#endif //STUDENT_H
#ifndef STUDENTGRADE_H
#define STUDENTGRADE_H

#include "340.h"

class StudentGrade
{
public:
	StudentGrade() { firstName = lastName = zid = grade = "";};
	virtual ~StudentGrade() { };
	void setFirstName(string x) {firstName = x;}
	string getFirstName() const {return firstName;}
	void setLastName(string x) {lastName = x;}
	string getLastName() const {return lastName;}
	void setZID(string x) {zid = x;}
	string getZID() const {return zid;}
	void setGrade(string x) {grade = x;};
	string getGrade() const {return grade;}
	bool operator==(const StudentGrade &right) const;
	bool operator<(const StudentGrade &right) const;
	void operator<<(const StudentGrade &right) const;
	
protected:
	string firstName,
		   lastName,	
		   zid,
		   grade;
};

bool StudentGrade::operator==(const StudentGrade & right) const
{
     return (firstName == right.firstName && lastName == right.lastName && zid == right.zid && grade == right.grade);
}

bool StudentGrade::operator<(const StudentGrade & right) const
{
	if (grade < right.grade)
		return true;
	else if (grade > right.grade)
		return false;
   else if (grade == right.grade)
   {
	   if (zid < right.zid)
		   return true;
	   else if (zid > right.zid)
		   return false;
	}
	return "NULL";
}

void StudentGrade::operator<<(const StudentGrade & right) const
{
	cout << right.firstName << " " << right.lastName << " " << right.zid << " " << grade;
}

#endif //STUDENTGRADE.H
John Smith   123456789 04/10/89 M z111190
CSCI340 2008 Fall   B
CSCI231 2008 Fall   B
$
Linda Ray    333222333 03/20/88 F z112030
CSCI210 2008 Fall   B
CSCI340 2008 Fall   B
$
Rene Hanson  222333111 01/01/81 F z220039
CSCI240 2007 Spring A
CSCI340 2008 Fall   A
CSCI210 2008 Spring B
$
Henry Treftz 928234857 05/22/87 M z485830
CSCI240 2006 Fall   A
CSCI241 2007 Spring B
CSCI360 2007 Summer C
CSCI340 2007 Fall   B
$
Scott Harris 123234857 08/14/88 M z592349
CSCI240 2007 Spring A
CSCI241 2007 Summer A
CSCI340 2008 Fall   A
$
Michael Schreiber 092184834 10/02/88 M z834749
CSCI205 2006 Fall   A
CSCI240 2007 Spring A
CSCI241 2007 Summer A
CSCI340 2008 Fall   A
$
3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by Vincenttalent
0

Someone might actually look at your code if you post it as a single zip file. Edit your previous post if possible.

0

It would not compile until I made the following change:
In StudentGrade.h, in the StudentGrade class, change the declaration of operator<< to this (making StudentGrade const): friend ostream& operator<< (ostream &out, const StudentGrade &right); And of course change the definition of operator<< in the code to match.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.