CSCI 132 Data Structures--Spring 2014

    Home | | Syllabus | | Assignments | | Lecture Notes

    Laboratory 1 Solutions

    Answers to questions:

    1. This class had 6 member functions. List them. (include return types and parameter lists):

      void AddCourse( string9 courseName);

      void ListCourses(void) const;

      void ListInfo(void) const;

      void SetGradDate( int year);

      Student();

      Student(char name[], int year);

    2. This class has 4 data members. List them (include their type).

      char studentName[30];

      string9 courses[6];

      int numCourses;

      int gradDate;

    3. In your own words, briefly describe what the key words public and private indicate.

      Public indicates the the member function or variable is accessible by the client code (which is the code that uses the specified class data type)

      private indicates that the member function or variable is not accessible by the client code.

    4) Which of the functions in the Student class are stubs and which have been implemented?

    Stubs:

      Student::Student(char name[], int year)

      void Student::ListInfo(void) const

      void Student::ListCourses(void) const

    Implemented:

      Student::Student( )

      void Student::AddCourse( string9 courseName)

      void Student::SetGradDate( int year)

    5. Open the registerStudent.cc file in your emacs window. What is the name of the object of type Student that is created in this client code?

      newStudent

    6. What member functions are invoked for the Student object?

      Student( )

      SetGradDate( newYear )

      AddCourse( newYear )

      ListInfo( )

      ListCourses( )


    7. What does the program do when you first run it?

      It asks for and reads in the graduation year.

      It asks for and reads in a course name.

      It does nothing else.

     

    8. What does the program do after you have implemented all the class functions?

      It asks for and reads in the graduation year

      It asks for and reads in a course name

      It prints out the student's name (John Doe) and graduation year.

      It prints out the course name that was entered.

    Solutions to programs:

    registerStudent.cc: The client code.

    student1.cc: Implementing the Student class with a course array.

    student.h: Specifying the Student class with individual course variables.

    student.cc: Implementing the Student class with individual course variables.


    Home | | Syllabus | | Assignments | | Lecture Notes