zoukankan      html  css  js  c++  java
  • C++练习1

    #include <iostream>
    #include
    <cstring>

    using namespace std;

    class NameString{
    private:
    char *str;
    public:
    NameString(
    char *s="...")
    {
    str
    = new char[strlen(s)+1];
    strcpy(str,s);
    // cout<<"构造 NameString OK!"<<endl;
    }

    void print()
    {
    cout
    <<str;
    }

    ~NameString()
    {
    // cout<<"析构 NameString OK!"<<endl;
    delete str;
    }
    };

    class Student{
    private:
    int StudentNO;
    NameString Name;
    int Scores;
    static int total_Scores;
    static int total_Num;
    public:
    Student(
    int a,char *b,int c):StudentNO(a),Name(b),Scores(c)
    {
    total_Scores
    += c;
    total_Num
    ++;
    // cout<<"构造 Student OK!"<<endl;
    }

    void print()
    {
    cout
    <<StudentNO<<'\t';
    Name.print();
    cout
    <<'\t'<<Scores<<endl;
    }

    void average()
    {
    cout
    <<"Average:"<<total_Scores/total_Num<<endl;
    }

    static void total_disp()
    {
    cout
    <<"Total_Scores:"<<total_Scores<<endl;
    cout
    <<"Total_Num:"<<total_Num<<endl;
    }

    };

    int Student::total_Scores = 0;
    int Student::total_Num = 0;

    int main()
    {
    Student st1(
    1,"wen",94);
    Student st2(
    2,"hao",100);
    Student st3(
    3,"lin",100);

    cout
    <<"学号"<<'\t'<<"姓名"<<'\t'<<"成绩"<<endl;
    st1.print();
    st2.print();
    st3.print();

    Student::total_disp();

    st1.average();

    return 0;

    }

  • 相关阅读:
    自动机实验
    11.11评论
    语法分析
    201406114257 张俊毅 词法分析 修改完
    201406114257 张俊毅 词法分析
    做汉堡
    复利计算5.0-结队
    《构建之法》第4章的感悟
    复利计算4.0单元测试
    实验一 命令解释程序的编写
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2049193.html
Copyright © 2011-2022 走看看