编写 一个程序, 输入N个学生数据,包括学号,姓名,成绩,要求输出这些学生数据并计算平均分

#include<bits/stdc++.h>
using namespace std;
class Student
{
  private:
        int no;
        char name[10];
        int deg;
        static int sum;
        static int num;
  public:
        void setdata(int n,char na[],int d)
        {
            no=n;
            strcpy(name,na);
            deg=d;
            sum+=d;
            num++;
        }
        static double avg()
        {
            return sum/num;
        }
        void disp()
        {
            cout<<no<<name<<deg<<endl;
        }
};
int Student::sum=0;
int Student::num=0;
int main()
{
    int n;
    cin>>n;
    Student stu1,stu2;
    stu1.setdata(201,"s",55);
    stu2.setdata(203,"sss",88);
    stu1.disp();
    stu2.disp();
    int s = Student::avg();
    cout<<s<<endl;

}
 

全部评论

相关推荐

昨天 11:05
门头沟学院 运营
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务