>即時新聞-熱門

2008年8月27日星期三

vc++ - 多重繼承2

#include<iostream>
using namespace std;
class my_score

private:
int china;
int english;
int math;
public:
void set_china(int china)
{ this->china=china; }
int get_china()
{ return china; }
void set_english(int english)
{ this->english=english; }
int get_english()
{ return english; }
void set_math(int math)
{ this->math=math; }
int get_math()
{ return math; }
};

class my_student : public my_score

private:
int sum;
float avg;
public:
my_student() 

{ int sum=0;
float avg=0.0;

void show_score()

cout << "國文:" << get_china() << endl;
cout << "英文:" << get_english() << endl;
cout << "數學:" << get_math() << endl;

void add1()

sum=get_china()+get_english()+get_math();

cout << "總成績為:" << sum << endl;

void avg1()


avg=(float)(get_china()+get_english()+get_math())/3;

cout << "總平均為:" << avg << endl;

};
void main()


my_student st1;
int s1,s2,s3;


cout << "請輸入國文成績:";
cin >> s1;
cout << "請輸入英文成績:";
cin >> s2;
cout << "請輸入數學成績:";
cin >> s3;

st1.set_china(s1);
st1.set_english(s2);
st1.set_math(s3);
cout << "************************************" << endl;
st1.show_score();
st1.add1();
st1.avg1();

0 评论:

 
妹咕數位學園歡迎網友們來信指教 妹咕信箱