Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////
- // PG1Lab2 - Exercise 2
- // GradeBook.h
- // Author: Alexander Schott
- // Date: 20.04.2014
- ///////////////////////////////
- #include <iostream>
- #include <string>
- // GradeBook class definition
- class GradeBook{
- public:
- GradeBook(std::string course, std::string lecturer); // constructor initializes courseName and lecturerName
- void setCourseName(std::string);
- std::string getCourseName() const;
- void setLecturerName(std::string);
- std::string getLecturerName() const;
- std::string message() const; // returns a string which contains information about a course and its lecturer
- private:
- std::string courseName;
- std::string lecturerName;
- }; // end class GradeBook
- ///////////////////////////////
- // PG1Lab2 - Exercise 2
- // GradeBook.cpp
- // Author: Alexander Schott
- // Date: 20.04.2014
- ///////////////////////////////
- #include "GradeBook.h"
- using namespace std;
- // memberdefinition of the class GradeBook
- // constructor
- GradeBook::GradeBook(string course, string lecturer)
- : courseName(course), lecturerName(lecturer){
- }
- // setCourseName
- void GradeBook::setCourseName(string name){
- this->courseName = name;
- }
- // getCourseName
- string GradeBook::getCourseName() const{
- return courseName;
- }
- // setLecturerName
- void GradeBook::setLecturerName(string lecturer){
- lecturerName = lecturer;
- }
- // getLecturerName
- string GradeBook::getLecturerName() const{
- return lecturerName;
- }
- // message
- string GradeBook::message() const{
- return "Gradebook for the lecture: " + courseName + "\n" +
- "Lecture is held by: " + lecturerName + "\n";
- }
- ///////////////////////////////
- // PG1Lab2 - Exercise 2
- // main.cpp
- // Author: Alexander Schott
- // Date: 20.04.2014
- ///////////////////////////////
- #include "GradeBook.h"
- using namespace std;
- // GradeBook class demonstration
- int main(){
- GradeBook AlexGB("6.00x - Introduction to Computer Science", "John Guttag");
- GradeBook PeterGB("no courseName", "no lecturerName");
- cout << AlexGB.message();
- PeterGB.setCourseName("UT.9.01x - Effective Thinking Through Mathematics");
- PeterGB.setLecturerName("Michael Starbird");
- cout << PeterGB.message();
- cout << "Alex's Coursenumber: " << AlexGB.getCourseName().substr(0, 4) << endl
- << "Peter's Coursenumber: " << PeterGB.getCourseName().substr(3, 4) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement