Class creation and string manipulation
This lab will give you some more practice with writing and using
classes. It will also provide an opportunity to review the string class
in C++. It is based
on an assignment created by Lucia Moura at the
University of Ottawa.
- Topics to be review before you start:
- Creating classes
in C++
- *.cpp and *.h files
- constructors / destructors
- private and public elements
- The string
class
- #include <string>
- string operations (getline, substr, find, length, size)
- reading from a file with fixed length fields
- Download the following files:
- Look over the lab3.cpp file. Notice that it makes use of a class
named student.
- Write both the header(student.h) and the implementation(student.cpp)
for this class student with the following specification:
- long int
number;
// the student's id
- string
name;
// the student's name
-
Student()
// constructor
- virtual
~Student()
// destructor
- long int
getNumber()
// get the name
- void setNumber(long int) // set the name
- string
getName()
// get the number
- void
setName(string)
// set the number
- Complete the method void readStudent(istream& input,
Student&
s) inside lab3.cpp. This method should :
- read a line from the input parameter and store it in a
string
- extract the name and number of the student from this string
- set such name and number for student s
- Use the file students.dat as the input file
- This file has a number of lines, each one storing a student
where the
first
7 digits are the student number and the next 21 the student name:
- 9999999XXXXXXXXXXXXXXXXXXXXX