In: Computer Science
Week 10 - Please write in C++ as simple as possible
RRCC has a schedule of courses that includes:
Subject (like: CSC)
Course Number (like: 119)
Section (like: 802)
Credits (like: 3)
Title
Days (like: MW)
Time (like 8:00am-9:15am)
Instructor
From this schedule information above create a class called RRCC_schedule (with a .cpp file and a .h file). Look at each item above and determine the type of data that will go into the variable. Then create a UML with all the variables and methods (like: the getters and setters, a default constructor, and a constructor that takes all the variables and finally the printValues() ). Once you have the UML then create the three code files for the Schedule.h, the Schedule.cpp file, and the Main file. Then in the main() create three schedule objects with values.
Program Code [C++]
Schedule.h
// RRCC_schedule class
#include <iostream>
using namespace std;
class RRCC_schedule {
private:
// All required data members
string subject;
int courseNumber;
int section;
int credits;
string title;
string days;
string time;
string instructor;
public:
// Constructors
RRCC_schedule();
RRCC_schedule(string, int, int,
int, string, string, string, string);
// Setters & Getters
void setSubject(string);
void setCourseNumber(int);
void setSection(int);
void setCredits(int);
void setTitle(string);
void setDays(string);
void setTime(string);
void setInstructor(string);
string getSubject();
int getCourseNumber();
int getSection();
int getCredits();
string getTitle();
string getDays();
string getTime();
string getInstructor();
void printValues();
};
Schedule.cpp
// Implementation of RRCC_schedule class
#include "Schedule.h"
RRCC_schedule::RRCC_schedule() {
subject = "";
courseNumber = 0;
section = 0;
credits = 0;
title = "";
days = "";
time = "";
instructor = "";
}
RRCC_schedule::RRCC_schedule(string sub, int cn, int sec, int
cred, string t, string d, string tim, string inst) {
this->subject = sub;
this->courseNumber = cn;
this->section = sec;
this->credits = cred;
this->title = t;
this->time = tim;
this->days = d;
this->instructor = inst;
}
void RRCC_schedule::setSubject(string sub) {
this->subject = sub;
}
void RRCC_schedule::setCourseNumber(int cn) {
this->courseNumber = cn;
}
void RRCC_schedule::setSection(int s) {
this->section = s;
}
void RRCC_schedule::setTitle(string ti) {
this->title = ti;
}
void RRCC_schedule::setTime(string t) {
this->time = t;
}
void RRCC_schedule::setDays(string d) {
this->days = d;
}
void RRCC_schedule::setInstructor(string inst) {
this->instructor = inst;
}
string RRCC_schedule::getSubject() {
return subject;
}
int RRCC_schedule::getCourseNumber() {
return courseNumber;
}
int RRCC_schedule::getSection() {
return section;
}
int RRCC_schedule::getCredits() {
return credits;
}
string RRCC_schedule::getTitle() {
return title;
}
string RRCC_schedule::getDays() {
return days;
}
string RRCC_schedule::getTime() {
return time;
}
string RRCC_schedule::getInstructor() {
return instructor;
}
void RRCC_schedule::printValues() {
cout << "Subject: " << subject <<
endl
<< "Course Number: " <<
courseNumber << endl
<< "Section: " <<
section << endl
<< "Credits: " <<
credits << endl
<< "Title: " << title
<< endl
<< "Days: " << days
<< endl
<< "Time: " << time
<< endl
<< "Instructor: " <<
instructor << endl;
}
main.cpp
#include <iostream>
#include "Schedule.h"
int main() {
// Creating 3 schedule objects
RRCC_schedule s1("CSC", 119, 802, 3, "Computer", "MW",
"8:00am-9:15am", "Annie");
RRCC_schedule s2("CSE", 120, 803, 4, "IT", "TF",
"09:30am-11:00am", "John");
RRCC_schedule s3("SCE", 121, 804, 3, "Business", "MF",
"11:15am-12:15am", "Julie");
s1.printValues();
cout << endl;
s2.printValues();
cout << endl;
s3.printValues();
cout << endl;
return 0;
}
UML Diagram
Sample Output:-
----------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!