zoukankan      html  css  js  c++  java
  • C++学生信息处理

    #include
    #include
    using namespace std;
    template
    int getArrayLen(T& array) //使用模板定义一个函数getArrayLen,该函数将返回数组array的长度
    {
    return (sizeof(array) / sizeof(array[0]));
    }

    class Student{
    public:
    char name[20];
    int id;
    int score;
    public:
    Student(int i = 0, char* c="", int s= 0)
    {
    id = i;
    strcpy(name,c);
    score = s;
    }
    Student& operator = (const Student& rhs )
    {
    id = rhs.id;
    strcpy(name,rhs.name);
    score = rhs.score;
    return *this;
    }
    void gets()
    {
    cin>>name>>id>>score;
    }
    void print()
    {
    cout<<"name: "<<name<<" id: "<<id<<" score: "<<score<<endl;
    }
    } ;

    void rank(int n,Student a[])//排序函数
    {
    int i, j; Student t;
    for(i = 0 ; i < n ; i++ )
    for(j = i + 1; j < n -1 ; j ++)
    {
    if(a[i].score < a[j].score){t = a[i]; a[i] = a[j] ;a[j] = t;}
    }
    }

    int average(Student a[],int n)//求平均数
    {
    int sum = 0,average;
    for(int i = 0 ; i < n ; i++)
    sum+=a[i].score;
    average = sum / n;
    return average;
    }
    void input(Student s[],int n)//输入信息的函数
    for(int i = 0 ; i < n ; i++)
       s[i].gets();
    }
    void output(Student s[],int n)//输出信息的函数
    for(int i = 0 ; i < n ; i++)
          s[i].print();
    }

    //主函数
    int main()
    {
    Student class1[10];//十个人的信息
    cout<<"******************************************"<<endl;
    cout<<"please enter name id score:"<<endl;
    input(class1,10);
    cout<<"name              id             score  :"<<endl;
    cout<<"******************************************"<<endl;
    output(class1,10);
    cout<<"******************************************"<<endl;
    cout<<"this class average score is:"<<average(class1,4)<<endl;
    cout<<"******************************************"<<endl;
        rank(10,class1);
    output(class1,4);//输出前四的信息
    return 0;
    }
  • 相关阅读:
    802.11协议网文转载
    三角函数公式大全
    IEEE 802.11ac Standard
    FPGA设计如何进行面积优化
    直流偏差消除
    I/Q不平衡补偿
    WiFi6剩余频偏的影响
    SQL SERVER 调优等待类型
    Nginx
    fatal: HttpRequestException encountered解决方法
  • 原文地址:https://www.cnblogs.com/whieenz/p/5247172.html
Copyright © 2011-2022 走看看