complete the following code, then separate the header #include <iostream> using
ID: 3546009 • Letter: C
Question
complete the following code, then separate the header
#include <iostream>
using namespace std;
class Teacher{
public:
string Name;
int ID;
public:
Teacher (string te_name, long int te_id) {
Name = te_name;
ID = te_id;
};
string get_name () { return Name ; }
long get_id () {return ID ; }
};
class Section{
int SectionID;
Teacher teacher ;
public:
Section(int sec_id ,string teacher_name,long int teacher_id ){
// initialize all data members
}
void print(){
// print class information :
// section ID
// teacher name
// teacher ID
// Hint (you may need to add get function for teacher class)
}
};
int main () {
Section s1(271,"Ahmed",329481);
Section s2(272,"Moh",329431);
Section s3(273,"Ali",32211);
s1.print();
s2.print();
s3.print();
system ("pause");
return 0 ;
}
Explanation / Answer
#include <iostream>
using namespace std;
class Teacher{
public:
string Name;
int ID;
public:
Teacher(){};
Teacher (string te_name, long int te_id) {
Name = te_name;
ID = te_id;
};
string get_name () { return Name ; }
long get_id () {return ID ; }
};
class Section{
int SectionID;
Teacher teacher ;
public:
Section(int sec_id ,string teacher_name,long int teacher_id ){
SectionID = sec_id;
Teacher teacher1(teacher_name,teacher_id);
teacher=teacher1;
}
void print(){
cout<<" Class information : ";
cout<<"Section ID: "<<SectionID;
cout<<" Teacher name: "<<teacher.get_name();
cout<<" Teacher ID: "<<teacher.get_id();
}
};
int main () {
Section s1(271,"Ahmed",329481);
Section s2(272,"Moh",329431);
Section s3(273,"Ali",32211);
s1.print();
s2.print();
s3.print();
return 0 ;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.