编程实现输入班里10名学生的身高,获得身高最高的学生。要求使用对象数组类型的带参方法实现!

作者&投稿:冶虹 (若有异议请与网页底部的电邮联系)
public Students getMaxheight(Students[] stu){
if(stu == null) return null;
if(stu.length == 0) return null;

var maxStudent = str[0]
foreach(var x in stu)
{
maxStudent = maxStudent .Height > x.Height ? maxStudent :x;
}
return maxStudent ;
}

java中怎么创建对象数组?比如我创建了一个学生类Student,怎么用这个类创建一个对象数组,麻烦给个例子~

学生类:
class A{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}


}
//学生类使用方法:
public class test(){
public static void main(String[] args) {
A[] students = new A[2]; //创建2个学生的学生数组
A as= new A();
as.setAge(15);
as.setName("tom");
A as1= new A();
as1.setAge(16);
as1.setName("cat");
A[] a={as,as1}; //动态创建学生数组
for (A st : a) {//遍历数组
System.out.println(st.getName()+";");
}

}

}

运行结果:
tom;
cat;

#include
#include
#include
const int TOTAL=4;
class student
{
private:
char *namept;
int height;
public:
student(char *s, int hght):height(hght)
{
namept=new char[strlen(s)];
strcpy(namept, s);
print();
}
~student()
{
delete [] namept;
}
void print()
{
std::cout<<namept<<" "<<height<<std::endl;
}
friend int tallest(student **l, int n)
{
int top=l[0]->height;
int num=0;
for (int i=1; i< n; ++i)
if (l[i]->height>top)
{
top=l[i]->height;
num=i;
}
return num;
}
};
int main(void)
{
class student* list[TOTAL];
list[0]= new student("John", 180);
list[1]= new student("Adam", 188);
list[2]= new student("Judy", 168);
list[3]= new student("Julia", 175);
int n=tallest(list, TOTAL);
std::cout<<"the tallest one is ";
list[n]->print();
system("pause");
return 0;
}





C++程序设计 学生身高调查
答:cout<<"身高调查"<<endl;loop: cout<<"1 记录信息."<<endl <<"2 浏览信息."<<endl <<"3 查询信息."<<endl <<"4 退出."<<endl <<"请输入序号,按回车确定"<<endl;cin>>choice;if(choice==1){ cout<<"请输入调查总人数: ";cin>>n;while(n--){ cout<<"姓名: ";cin>>a[...

输入15个人身高,分3组,1,4,7···是a,2,5,8··1是b,3,6,9···是...
答:include<stdio.h> int main(){ int i,j,a[3][5];for(i=0; i<15; i++)scanf("%d",&a[i%3][i/3]);for(i=0; i<3; i++)for(j=0; j<5; j++)printf("%d%c",a[i][j],j==4?'\n':' ');return 0;}

身高排在前10名的同学平均身高比全班平均身高
答:要求平均数,则要求出身高总数与10求比值,由10人身高与全班学生平均身高170 cm的差可知每个人的身高,求和即可. 【解析】 ∵10人的总身高是:170×10-4-7-8-2+1-10+15+10+7-2=1700, ∴10名学生的平均身高是 =170, 故答案为:170 ...

用C++编程,输入三位学生的身高(实数)给变量height1、height2和height3...
答:height1=height2;height2=swap;} if(height3<height1){swap=height1;height1=height3;height3=swap;} if(height2>height3){swap=height2;height2=height3;height3=swap;} return 0;} 这种方法是从小到大排序的,交换值可以写在一个分函数中再调用,3个数据用三次交换就可以。

c++:输入n名学生的身高体重,按身高排序输出并计算平均体重和身高
答:av_height变量没有初始化 int av_height,av_weight=0;这句要改为int av_height=0,av_weight=0;

...编写一个程序,输入10位同学的姓名和成绩,并按学生成绩从高到低排序...
答:include<stdio.h>#include<string.h>#define N 10struct student{char name[20];int score;};void main(){struct student stu[N];struct student *p; int i,v,s,temp;char tempname1[20],tempname2[20];for(i=0;i<N;i++){printf("please input %d student name\n",i+1);scanf...

...学号,姓名,四门课的成绩,从键盘输入10个学生的数据记录
答:for(i=0;i<10;i++){ printf("%s %s %d %d %d %d %d %d\n",b[i].name,b[i].num,b[i].a,b[i].a1,b[i].a2,b[i].a3,b[i].a4);} } int main(){ int i,n;char c;printf("依次输入学生信息(姓名,学号,四科成绩\n注意:各项信息用空格分开,输完一个学生后按回车,...

...一个函数datainput,实现从键盘上录入10名学生的
答:某c语言班共有10名学生,试编程完成下列要求,并验证:a.编写一个函数datainput,实现从键盘上录入10名学生的c语言成绩,存入数组a中b.编写一个函数dataso... 某c语言班共有10名学生,试编程完成下列要求,并验证:a.编写一个函数datainput,实现从键盘上录入10名学生的c语言成绩,存入数组a中b.编写一个函数datasort...

...身高、成绩等)并且按身高排序;输出排序后的学生名
答:cout<<"请输入第"<<i+1<<"个学生的信息:"<<endl;pArray[i].Set_stu_inf();pArray[i].average();pArray[i].Sum();} } //+--- //|求取全班最高分和总平均分 //+--- void ComputeHighestAndAverage(){ if(pArray != NULL){ float TempAll = 0.0f;for(unsigned int ...

C语言编程题:有10个学生,每个学生数据包括学号,姓名,3门课的成绩,从键...
答:include(stdio.h)main(){struct student {long number;char name[20];float score[4];}person[10];int i;printf("请输入10名学生的学号、姓名、及三门成绩:");for(i=0;i<10;i++)scanf("%d,%s,%d,%d,%d",&person[i]->number,person[i]->name,&person->score[0],&person->score[...