Advertisement
algore87

PG1Lab2

Apr 20th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. ///////////////////////////////
  2. // PG1Lab2 - Exercise 2
  3. // GradeBook.h
  4. // Author:  Alexander Schott
  5. // Date:    20.04.2014
  6. ///////////////////////////////
  7. #include <iostream>
  8. #include <string>
  9.  
  10.  
  11. // GradeBook class definition
  12. class GradeBook{
  13. public:
  14.    GradeBook(std::string course, std::string lecturer);  // constructor initializes courseName and lecturerName
  15.    void setCourseName(std::string);
  16.    std::string getCourseName() const;                    
  17.    void setLecturerName(std::string);                    
  18.    std::string getLecturerName() const;                  
  19.    std::string message() const;                          // returns a string which contains information about a course and its lecturer
  20. private:
  21.    std::string courseName;
  22.    std::string lecturerName;
  23. }; // end class GradeBook
  24.  
  25.  
  26. ///////////////////////////////
  27. // PG1Lab2 - Exercise 2
  28. // GradeBook.cpp
  29. // Author:  Alexander Schott
  30. // Date:    20.04.2014
  31. ///////////////////////////////
  32. #include "GradeBook.h"
  33. using namespace std;
  34.  
  35. // memberdefinition of the class GradeBook
  36. // constructor
  37. GradeBook::GradeBook(string course, string lecturer)
  38. : courseName(course), lecturerName(lecturer){
  39.  
  40. }
  41.  
  42. // setCourseName
  43. void GradeBook::setCourseName(string name){
  44.    this->courseName = name;
  45. }
  46.  
  47. // getCourseName
  48. string GradeBook::getCourseName() const{
  49.    return courseName;
  50. }
  51.  
  52. // setLecturerName
  53. void GradeBook::setLecturerName(string lecturer){
  54.    lecturerName = lecturer;
  55. }
  56.  
  57. // getLecturerName
  58. string GradeBook::getLecturerName() const{
  59.    return lecturerName;
  60. }
  61.  
  62. // message
  63. string GradeBook::message() const{
  64.    return "Gradebook for the lecture: " + courseName + "\n" +
  65.       "Lecture is held by: " + lecturerName + "\n";
  66. }
  67.  
  68.  
  69. ///////////////////////////////
  70. // PG1Lab2 - Exercise 2
  71. // main.cpp
  72. // Author:  Alexander Schott
  73. // Date:    20.04.2014
  74. ///////////////////////////////
  75. #include "GradeBook.h"
  76. using namespace std;
  77.  
  78. // GradeBook class demonstration
  79. int main(){
  80.    GradeBook AlexGB("6.00x - Introduction to Computer Science", "John Guttag");
  81.    GradeBook PeterGB("no courseName", "no lecturerName");
  82.    cout << AlexGB.message();
  83.    PeterGB.setCourseName("UT.9.01x - Effective Thinking Through Mathematics");
  84.    PeterGB.setLecturerName("Michael Starbird");
  85.    cout << PeterGB.message();
  86.    cout << "Alex's Coursenumber: " << AlexGB.getCourseName().substr(0, 4) << endl
  87.       << "Peter's Coursenumber: " << PeterGB.getCourseName().substr(3, 4) << endl;
  88.    return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement