codecamp

a c++ program of derived class

#include"iostream"
#include"string"
using namespace std;

class Student
{     
public:
 Student(string no,string name);
 Student();
 void show_infor();
protected:
 string stu_no;
 string stu_name;
};

Student::Student(string no,string name):stu_no(no),stu_name(name)
{
 //Bode intentionally empty
}

Student::Student():stu_no("No number yet"),stu_name("No name yet")
{
 //Body intentionally empty
}

void Student::show_infor()
{
 cout<<"student number    "<<stu_no<<endl;
 cout<<"student name      "<<stu_name<<endl;
}

class English_stu:public Student
{
private:
 string depart;
 double score;
public:
 English_stu(string dep,double sco);
 English_stu();
 void show_infor(Student& stu);
};

English_stu::English_stu(string dep,double sco):depart(dep),score(sco)
{
 //Body intentionally empty
}

English_stu::English_stu():depart("No department yet"),score(0)
{
 //Body intentionally empty
}

void English_stu::show_infor(Student& stu)
{
 cout<<"student department "<<depart<<endl;
 cout<<"student score      "<<score<<endl;
 stu.show_infor();
}

int main()
{
 string x,y;
 cout<<"Please enter the student's name"<<endl;
 cin>>x;
 cout<<"Please enter the student's number"<<endl;
 cin>>y;
 Student stu_1(x,y),stu_2;
 stu_1.show_infor();
 stu_2.show_infor();
 string a;
 double b;
 cout<<"Please enter the English student's depart"<<endl;
 cin>>a;
 cout<<"Please enter the English student's score"<<endl;
 cin>>b;
 English_stu estu_1(a,b),estu_2;
 estu_1.show_infor(stu_1);
 estu_2.show_infor(stu_2);
 return 0;
}

计算器c语言代码
A – EIGHT
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }