CS
210 – Fundamentals of Programming I
Spring 2007 – In-class
Exercise for 4/4/07 & 4/5/07
Name(s):
(10 points) Complete this exercise in pairs. The purpose of this exercise is to work with the overloaded I/O operators. It is an implementation of Project 1 using a Student class object as covered in lecture. In this version, student data is stored in a Student class object. There are no written questions.
Assignment
0. Create a new project, then download files inclass23.cpp, student.h, and student.cpp from the course webpage under today's date and add it to your project. The Student class is incomplete, so this program will not compile. It is missing the code for operator>> and operator<<.
1. Complete this program by doing the following:
In student.h, add prototypes for operator>> and operator<< as friend functions as indicated in the comments.
In student.cpp, add the function definitions for operator>> and operator<< at the end of the file where indicated by the comments.
operator>> must read data from an input stream in the following format:
name score1 score2 ... scoren negative#
It should behave similarly to getline() with respect to leading and trailing newlines. I.e., it should assume that the first character in the stream is part of the name (so the caller is responsible for getting rid of any leading newlines), but it should remove the trailing newline after the negative number (so that the caller does not have to do so between successive calls to this operator).
operator<< must output data in the format expected by operator>> above. It should not output a trailing newline after the negative number. As with all uses of operator<<, the caller is responsible for deciding if a newline should be placed after the object is output.
Build and test your program until you are confident that it computes the correct result. When you have completed this exercise, print out and turn in copies of student.h and student.cpp.
04/03/07