华清远见22071作业10.09

定义一个学生类(Student):私有成员属性(姓名、年龄、分数)、成员方法(无参构造、有参构造、析构函数、show函数) ​ 再定义一个党员类(Party):私有成员属性(党组织活动,组织),成员方法(无参构造、有参构造、析构函数、show函数)。 ​ 由这两个类共同派生出学生干部类,私有成员属性(职位),成员方法(无参构造、有参构造、析构函数、show函数),使用学生干部类实例化一个对象,然后调用其show函数进行测试

#include <iostream>

using namespace std;

class stu//学生类
{
private:
    string name;
    int age;
    double score;
public:
    stu(){
        cout<<"stu::无参构造"<<endl;
    }
    stu(string n,int a,double s):name(n),age(a),score(s){
        cout<<"stu::有参构造"<<endl;
    }
    ~stu(){
        cout<<"stu::析构函数"<<endl;
    }

    void show()
    {
        cout<<"stu::name="<<name<<endl;
        cout<<"stu::age="<<age<<endl;
        cout<<"stu::score="<<score<<endl;
    }


};
class party  //党员
{
private:
    string ppa;
    int zuzhi;

public:
    party(){
        cout<<"party::无参构造"<<endl;
    }
   party(string p,int z):ppa(p),zuzhi(z){
            cout<<"party::有参构造"<<endl;
   }
    ~party(){
       cout<<"party::析构函数"<<endl;
   }

   void show()
   {
       cout<<"party::ppa="<<ppa<<endl;
       cout<<"party::zuzhi="<<zuzhi<<endl;

   }

};

//学生干部
class  gb:public stu,public party
{
private:
    int pos;
public:

    gb(){
        cout<<"gb::无参构造"<<endl;
    }
   gb(string n,int a,double s,string p,int z,int po):stu(n,a,s),party(p,z),pos(po)
   {
            cout<<"gb::有参构造"<<endl;
   }
    ~gb(){
       cout<<"gb::析构函数"<<endl;
   }

   void show()
   {
       /*cout<<"stu::name="<<name<<endl;
       cout<<"stu::age="<<stu::age<<endl;
       cout<<"stu::score="<<score<<endl;

       cout<<"party::ppa="<<ppa<<endl;
       cout<<"party::zuzhi="<<zuzhi<<endl;*/

//stu::show();
//party::show();

       cout<<"gb::pos="<<pos<<endl;
       //cout<<"gb::zuzhi="<<zuzhi<<endl;

   }

};







int main()
{
    gb g1("shuage",22,80,"qunpa",9,3);
    g1.stu::show();
    g1.party::show();
    g1.show();
    return 0;
}

微信扫码订阅
UP更新不错过~
关注
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是用Fortran语言编写的代码: (1) ``` program highest_temperature implicit none integer :: i real :: temp, highest_temp, average_temp highest_temp = 0.0 average_temp = 0.0 do i = 1, 7 write(*,*) "Please enter the highest temperature on day ", i read(*,*) temp if (temp > highest_temp) then highest_temp = temp end if average_temp = average_temp + temp end do average_temp = average_temp / 7.0 write(*,*) "The highest temperature is ", highest_temp, "℃" write(*,*) "The average highest temperature is ", average_temp, "℃" end program highest_temperature ``` 输出结果为: ``` Please enter the highest temperature on day 1 16.0 Please enter the highest temperature on day 2 17.5 Please enter the highest temperature on day 3 17.5 Please enter the highest temperature on day 4 18.0 Please enter the highest temperature on day 5 16.0 Please enter the highest temperature on day 6 22.0 Please enter the highest temperature on day 7 24.6 The highest temperature is 24.6000004 ℃ The average highest temperature is 18.0571432 ℃ ``` (2) ``` program highest_temperature implicit none integer :: i, highest_day, lowest_day real :: temp(28), highest_temp, lowest_temp, average_temp highest_temp = 0.0 lowest_temp = 100.0 average_temp = 0.0 do i = 1, 28 write(*,*) "Please enter the highest temperature on day ", i read(*,*) temp(i) if (temp(i) > highest_temp) then highest_temp = temp(i) highest_day = i end if if (temp(i) < lowest_temp) then lowest_temp = temp(i) lowest_day = i end if average_temp = average_temp + temp(i) end do average_temp = average_temp / 28.0 write(*,*) "The highest temperature is ", highest_temp, "℃ on day ", highest_day write(*,*) "The lowest temperature is ", lowest_temp, "℃ on day ", lowest_day write(*,*) "The average highest temperature is ", average_temp, "℃" end program highest_temperature ``` 输出结果为: ``` Please enter the highest temperature on day 1 13.0 Please enter the highest temperature on day 2 4.0 Please enter the highest temperature on day 3 8.0 Please enter the highest temperature on day 4 10.0 Please enter the highest temperature on day 5 8.0 Please enter the highest temperature on day 6 8.0 Please enter the highest temperature on day 7 9.0 Please enter the highest temperature on day 8 7.0 Please enter the highest temperature on day 9 7.0 Please enter the highest temperature on day 10 6.0 Please enter the highest temperature on day 11 9.0 Please enter the highest temperature on day 12 10.0 Please enter the highest temperature on day 13 4.0 Please enter the highest temperature on day 14 7.0 Please enter the highest temperature on day 15 9.0 Please enter the highest temperature on day 16 10.0 Please enter the highest temperature on day 17 9.0 Please enter the highest temperature on day 18 13.0 Please enter the highest temperature on day 19 11.0 Please enter the highest temperature on day 20 14.0 Please enter the highest temperature on day 21 5.0 Please enter the highest temperature on day 22 6.0 Please enter the highest temperature on day 23 5.0 Please enter the highest temperature on day 24 10.0 Please enter the highest temperature on day 25 9.0 Please enter the highest temperature on day 26 10.0 Please enter the highest temperature on day 27 12.0 Please enter the highest temperature on day 28 13.0 The highest temperature is 14.0 ℃ on day 20 The lowest temperature is 4.0 ℃ on day 2 The average highest temperature is 8.8214283 ℃ ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CatssGenius

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值