当前位置:网站首页>PTA:7-67 友元很简单2016final
PTA:7-67 友元很简单2016final
2022-06-23 03:47:00 【Sy_Faker】
C++考试正在进行。请设计一个学生类student,学号、本次考试成绩是其私有数据成员,同时有一个求本次考试成绩最高分的学生的友元函数 student* average(student *p,int count)
以上类名和友元函数的形式,均须按照题目要求,不得修改。
输入格式:
输入是 学号([00001,99999])和成绩,以0结束。(不超过100个学生)
输出格式:
输出是最高分学生的 学号 。 提示:如果是并列最高分,需要将并列最高分学生的学号都输出,以一个空格间隔。
输入样例:
在这里给出一组输入。例如:
10001 90
10002 93
0
输出样例:
在这里给出相应的输出。例如:
10002
#include<iostream>
using namespace std;
class student
{
private:
int num;
int score;
public:
student(){
;}
void input(int n,int s)
{
num=n;
score=s;
}
friend student* average(student *p,int count);
};
student* average(student *p,int count)
{
int max=0,temp;
for(int i=0;i<count;i++)
{
temp=p[i].score;
max=temp>max?temp:max;
}
int first=1;
for(int i=0;i<count;i++)
{
if(max==p[i].score)
{
if(first)
{
cout<<p[i].num;
first=0;
}
else
cout<<" "<<p[i].num;
}
}
return p;
}
int main()
{
student p[100];
int n,s,i=0;
cin>>n;
while(n!=0)
{
cin>>s;
p[i++].input(n,s);
cin>>n;
}
average(p,i);
}
边栏推荐
- How to solve the problem that the web page fails to log in after the easycvr service is started?
- Tables de recherche statiques et tables de recherche statiques
- Web page dynamic and static separation based on haproxy
- Code refactoring Guide
- Weekly Postgres world news 2022w02
- svg d3.js生成tree树状图
- How can I realize video call and interactive live broadcast in a small program?
- Ideal car × Oceanbase: when new forces of car building meet new forces of database
- Idea import module
- Svg+js smart home monitoring grid layout
猜你喜欢

Deploying Apache pulsar on kubesphere

理想汽车×OceanBase:当造车新势力遇上数据库新势力

Halcon胶线检测—模板匹配、位姿变换、胶宽,胶连续性检测

HAProxy的编译安装及全局配置段说明

Code refactoring Guide

node+express如何操作cookie

x64dbg 基本使用技巧

Idea import module

粒子动画背景登录页面particles.js

Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
随机推荐
电商如何借助小程序发力
Prince language under insect date category
8 key indicators to measure technology debt in 2022
Pytoch --- pytoch customizes the dataset
Mysql, field problem
Dynamics 365 插件中权限操作
Pta:7-85 data spacing (overload + function template)
What is metadata
在word里,如何让页码从指定页开始编号
SVG+JS智能家居监控网格布局
[tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
PTA:7-69 数据的间距问题
P1363 幻象迷宫(dfs)
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
[tcapulusdb knowledge base] [list table] delete all data sample codes in the list
What is the digital "true" twin? At last someone made it clear!
Flutter怎么实现不同缩放动画效果
Tables de recherche statiques et tables de recherche statiques
Differences between MyISAM and InnoDB of MySQL storage engine
什么是元数据