CSCI 132 Data Structures--Spring 2014

    Home | | Syllabus | | Assignments | | Lecture Notes

    Laboratory 1 Solutions

    Solution to student.h code:

    //*******************************************************
    //SPECIFICATION FILE (student.h)
    //This file gives the specification for the Student class
    //using separate variables to store each course name.
    //Author: Brenda Student
    //Class: CSCI132
    //Section: 1
    //Date Created: 1/20/14
    //*******************************************************
    
    typedef char string9[10];
    
    class Student
    {
    public:
      void AddCourse(/*in*/ string9 courseName);
      //Precondition:
      //	courseName is a string of less than 10 characters
      //	There are less than 6 courses in the course list already.
      //Postcondition:
      //	The string, courseName, is added to the courselist.
      
      void ListCourses(void) const;
      //Precondition:
      //	A Student object has been initialized.
      //Postcondition:
      //	The courses in the course list are printed to the monitor.
      //    Courses are printed in the form: "Course 1: csci262"
      //	One course is on each line.
      //    One blank line is printed after the list of courses.
      
      void ListInfo(void) const;
      //Precondition:
      //	A Student object has been initialized.
      //Postcondition:
      //    The function prints out the student's name and
      //	  graduation date, one each line.
      //    The student's name is printed in the form: 
      //      "Name: Jane Doe"
      //    The gradduation date is printed in the form:
      //      "Graduation Date: 2006"
      //    One blank line is printed after the information list.
      
      void SetGradDate(/*in*/ int year);
      //Precondition:
      //	year is an integer representing a date.
      //Postcondition:
      //	The graduation date for the student object is set to year.
      
      Student();
      //Precondition:
      //	None.
      //Postcondition:
      //	Initializes the Student's number of courses to 0,
      //	Initializes the Student's graduation date to 0,
      //	Initializes the Student's name to "John Doe"
      
      Student(/*in*/ char name[],/*in*/ int year);
        //Precondition:
      //	name[ ] is an array of characters, less than 30 long, 
      //	containing the student's name.
      //	year is an integer representing the student's graduation date.
      //Postcondition:
      //	Initializes the Student's number of courses to 0,
      //	Initializes the Student's graduation date to year,
      //	Initializes the Student's name to the string contained in name.
        
    private:
      char studentName[30];      //Student's name.
      string9 course1;           //One of student's courses
      string9 course2;           //One of student's courses
      string9 course3;           //One of student's courses
      string9 course4;           //One of student's courses
      string9 course5;           //One of student's courses
      string9 course6;           //One of student's courses
      int numCourses;            //Number of courses student is enrolled in.
      int gradDate;              //Graduation date of the student.
    };
    
    
    

    Home | | Syllabus | | Assignments | | Lecture Notes