COS110 Tutorial 3 -11August2011-MEMO

COS110 Tutorial 3 -11August2011-MEMO - 1 University of...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 University of Pretoria COS110 Tutorial 3 MEMO-MEMO-MEMO Date: 3 August 2011 Time: 50 minutes Marks: 40 Student Surname and Initials:__________________________________________________ Student number:_______________________ Employee number:_____________________ Question 2: (Topic: inline implementaion of classes) [10 marks] Given the following class definition: class GradeBook { public: GradeBook(string name) { courseName = name; } void setCourseName(string name) { courseName = name; } string getCourseName() { return courseName; } void displayMessage() { cout << "Welcome to the Grade Book for " << courseName << "!" << endl; } private: string courseName; }; 2 Questions: a. Rewrite the class definition so that the class interface and implementation are in separate files. You must write all the necessary pre-processor directives for each file. (8 marks) b. Why is it a good practice to separate the class interface from the class implementation? (2 marks) Solution: a. The class public interface in file GradeBook.h (4 marks) #ifndef GRADEBOOK_H #define GRADEBOOK_H #include <string> class GradeBook { public: GradeBook(string name); void setCourseName(string name); string getCourseName(); void displayMessage(); private: string courseName; }; #endif The class implementation in file GradeBook.C (4 marks) #include "GradeBook.h" GradeBook::GradeBook(string name) { courseName = name; } void GradeBook::setCourseName(string name) { courseName = name; } GradeBook::string getCourseName() { return courseName; } void GradeBook::displayMessage() { cout << "Welcome to the Grade Book for " << courseName << "!" << endl; } b. Why is it a good practice to separate the class interface from the class implementation? (2 marks) 3 This type of implementations enables information hiding, i.e. class users only see the interface and the implementation details for the class are hidden from the class users....
View Full Document

This note was uploaded on 02/27/2012 for the course IT 101 taught by Professor Unsure during the Spring '11 term at University of South Africa.

Page1 / 6

COS110 Tutorial 3 -11August2011-MEMO - 1 University of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online