18计科实验五

  1. 建立一个Student类实现如下功能:查找考试成绩不及格的学生及其学号,并统计这些学生的总人数。
  1. 类的定义要求如下:

私有数据成员

  1. Int num ——存储学生的编号,学生编号最小为1
  2. String name——存储学生姓名
  3. Float score——存储学生考试成绩
  4. Int count——统计符合条件的总人数
  1. 共有函数成员
  1. Void input()——输入学生成绩
  2. Void search()——查找不及格的学生人数并存入count变量
  3. Void print()——输出不及格总人数和不及格学生的编号、姓名、成绩
    #include<iostream>
    using namespace std;
    const int SIZE = 3;		//录入信息个数
    class student{
    	private:
    		int num;
    		string name;
    		float score;
    		static int count;
    	public:
    		void input();
    		static void search(student stu[]);
    		static void print();		
    };
    int student::count = 0;		//记录不及格学生人数
    student *ptr[SIZE];	//外部变量,储存不及格
    void student::input(){
       cout<<"please input num:"<<endl;
       cin>>this->num;
       cout<<"please input name:"<<endl;
       cin>>this->name;
       cout<<"please input score:"<<endl;
       cin>>this->score; 	
    }
    void student::search(student stu[]){
    	int j=0;
        for(int i=0;i<SIZE;i++)
    	{
    		if(stu[i].score<60)
    		{
    			count++;
    			ptr[j] = &stu[i];
    			j++;
    		}
    	}	
    }
    void student::print(){
    cout<<"不及格人数"<<count<<endl;
    for (int i = 0; i < count; i++)
    		{
    		  cout << "编号:" << ptr[i]->num << " 成绩:" << ptr[i]->score << " 名字:" << ptr[i]->name << endl;
    		}
    	
    }
    
    int main(){
    	student stu[SIZE];
    	int i;
    	for(i=0;i<SIZE;i++)
    	{
    		stu[i].input();
    	}
    	student::search(stu);
    	student::print();
    	return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值