【id:117】【25分】D. OOP学生信息的添加与查询(类和对象)C++

想偷懒在网上偷个输出 结果没找到一个C++的 故传

输入样例:

5
0001 Mike 1990-05-20 98.5
0002 John 1992-05-20 67
0003 Hill 1994-05-20 36.5
0004 Christ 1996-05-02 86.5
0001 Jack 1998-05-20 96

输出样例:

id:0001 name:Jack birthday:1998_5_20 score:96.0
id:0002 name:John birthday:1992_5_20 score:67.0
id:0003 name:Hill birthday:1994_5_20 score:36.5
id:0004 name:Christ birthday:1996_5_2 score:86.5

#include<iostream>
#include<string.h>
#include<iomanip>
using namespace std;

class Stu{
	private:
		string id,name;
		int year,month,date;
		float score;
	public:
		void getS(string a,string b,int c,int d,int e,float f){
			id = a;
			name = b;
			year = c;
			month = d;
			date = e;
			score = f;
		}
		int ifdouble(string a){
			if(a == id){
				return 1;		
			}else{
				return 0;
			}
		}
		void show(){
			cout<<"id:"<<id<<" "<<"name:"<<name<<" "<<"birthday:"<<year<<"_"<<month<<"_"<<date<<" "<<"score:"<<fixed<<setprecision(1)<<score<<endl;
		}
};
int main(){
	int n,i,j;
	int count = 0;
	cin>>n;
	Stu *s = new Stu[n];
	string id,name;
	int year,month,date;
	float score;
	for(i = 0;i < n;i++){
		int flag = 0;
		cin>>id>>name>>year;
		cin.ignore();
		cin>>month;
		cin.ignore();
		cin>>date>>score;
		for(j = 0;j < i;j++){
			flag = s[j].ifdouble(id);
			if(flag){
				count++;
				break;
			}
		}
		if(flag){
			s[j].getS(id,name,year,month,date,score);
		}else{
			s[i].getS(id,name,year,month,date,score);
		}
	}
	for(i = 0;i < n - count;i++){
		s[i].show();
	}
	delete []s;
	return 0;
}

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值