Laboratory 1
Due at the beginning of class, Wednesday 1/29
Note: In this class, part of your lab and homework grade will reflect programming style. You must have consistent indentation, program prologues and program comments where appropriate. Please review the Style Guide on the notes page for guidelines on comments and indentation.
In today's lab you will be practicing programming objects in C++. In lecture we developed the specification of the Student Class, wrote some client code that used an object of the Student class type and wrote the implementation of some of the functions. Today you will be filling in some of the function implementations and writing some new client code.
The code that was presented in class is available in the directory:
Start the lab as follows:
Print out the lab 1 answer sheet. On this sheet, which is to be handed in, answer the following questions:
1. The Student class had 6 member functions. List them. (include return types and parameter lists):
2. The Student class has 4 data members. List them (include their type).
3. In your own words, briefly describe what the key words public and private indicate.
4. Open the student.cc file in your emacs window. Notice that several of the functions have no code in them. These are called "stubs" and are used to test programs that are in the development process. Which of the functions in the Student class are stubs and which have been implemented?
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?
6. What member functions are invoked for the Student object?
Compiling multiple files.
Type the following to compile the registerStudent program:
Delete the "Make -k" and fill in the command line to read:
From a command tool window, run the program by typing:
Follow the prompts in the program until it finishes, then answer the following question on your answer sheet:
7. What does the program do when you first run it?
Implementing the class functions
Fill in the function stubs in the student.cc file so that they perform as
specified in the pre- and post- conditions. Re-compile the code as above and
run the new register program. Answer the following question on your answer sheet:
8. What does the program do after you have implemented all the class functions?
Modifying the client code
Open the registerStudent.cc file. Make the following changes:
warning: deprecated conversion from string constant to 'char*'You may safely ignore those.
Data Abstraction
You have just been hired to work for the firm "Dilbert Industries" and your
new boss knows just enough computer programming to make things really difficult
for you. He insists that you should store all the names of courses in individual
variables instead of in an array as is given above. Your first assignment is to
rewrite the code for student.h and student.cc so that the course names are stored
in separate variables. It is important that the implementation be such that the
changes are invisible to the client code. That is, registerStudent.cc should run
exactly the same way, with no changes. Here's what you need to do:
What To Turn In.
Be sure that the program prologue for each file contains your name, course, lecture section, date and purpose of the program or a description of the contents of the file (e.g. specification of the Student class).
Reminder.
Be sure to save a copy of each file in your labs directory. It is your responsibility
to keep the copies of all programs written for this course until your
graded assignment is returned.
Home | | Syllabus | | Assignments | | Lecture Notes