How this can work without these empty constructors ? #include using namespace std; class Lecturer { private: string name; string department; public: // empty constructor Lecturer(){ } Lecturer(string n, string d){ name = n; department = d; } string getName(){ return name; } void setName(string n){ name = n; } void setDepartment(string d){ department=d; } string getDepartment(){ return department; } string toString() { cout<=7 && hour <=11) return true; else { return false; } } //function to display description string toString() { return l.toString() +"\n"+ "Subject: "+subject+ "\n"+"Day: "+weekday+ "\n"+ "Time: " + to_string(hour)+"\n"+ "Online: " + to_string(online); } }; int main(){ // object lecturer Lecturer lecturer1("S.Stouchev", "History"); Lecturer lecturer2("Y.Edreva", "Physics"); //calling cout<
How this can work without these empty constructors ?
#include<iostream>
using namespace std;
class Lecturer {
private:
string name;
string department;
public:
// empty constructor
Lecturer(){
}
Lecturer(string n, string d){
name = n;
department = d;
}
string getName(){
return name;
}
void setName(string n){
name = n;
}
void setDepartment(string d){
department=d;
}
string getDepartment(){
return department;
}
string toString() {
cout<<endl;
return "Name: " + getName()+" Department: " + getDepartment();
}
};
class Lecture {
private:
string subject;
string weekday;
int hour;
bool online;
Lecturer l;
public:
Lecture(){
}
Lecture(string s, string w,int h, bool onl,Lecturer lec) {
subject=s;
weekday=w;
hour=h;
online=onl;
l.setName(lec.getName());
l.setDepartment(lec.getDepartment());
}
// getter subject, setter subject
string getSubject(){
return subject;
}
void setSubject (string s){
subject=s;
}
// getter weekday, setter weekday
string getWeekday(){
return weekday;
}
void setWeekday(string w){
weekday=w;
}
//getter hour, setter hour
int getHour(){
return hour;
}
void setHour(int h){
hour=h;
}
// getter online, setter online
bool getOnline(){
return online;
}
void setOnline(bool onl){
online = onl;
}
//setter for lecturer
void setLecturer(Lecturer l){
l.setName(l.getName());
l.setDepartment(l.getDepartment());
}
//function to check if the lecture starts at 7-11
bool isItMorning() {
if (hour>=7 && hour <=11)
return true;
else {
return false;
}
}
//function to display description
string toString() {
return l.toString() +"\n"+ "Subject: "+subject+ "\n"+"Day: "+weekday+ "\n"+ "Time: " + to_string(hour)+"\n"+ "Online: " + to_string(online);
}
};
int main(){
// object lecturer
Lecturer lecturer1("S.Stouchev", "History");
Lecturer lecturer2("Y.Edreva", "Physics");
//calling
cout<<lecturer1.toString()<<endl;
cout<<lecturer2.toString()<<endl;
//array of Lecture objects
Lecture Lect[3];
Lect[0] = Lecture("History","Monday",13,true,lecturer1);
Lect[1] = Lecture("Physics","Tuesday",7,false,lecturer2);
Lect[2] = Lecture("Cultural Heritage","Monday",10,false,lecturer1);
cout<<endl;
for(int i=0;i<3;i++) {
cout<<Lect[i].toString()<<endl;
}
}
Step by step
Solved in 2 steps