> 其他 >
定义一个学生类.数据成员有学号,姓名,年龄,英语成绩.计算成绩总分和平均分.要求;f分别
要求用成员函数和友元函数计算
人气:156 ℃ 时间:2020-05-08 17:55:39
解答
public class Student{
String name,id;
int age,english,math,chinese;
Student(int a,int b,int c,int d,String e,String f){
age=a;english=b;math=c;chinese=d;name=e;id=f;
int sum,avearge;
sum= english+math+chinese;
aveager=sum/3;
System.out.println("sum="+sum\n+"avearge="+aveager\n);
System.out.println("姓名"+name);
System.out.println("学号",id);
System.out.println("年龄",age);
}
new Student(90,90,90,90,"1006215900","smallmonker");
}友元函数呢构造函数前没有加public,protected,private修饰,系统默认的,默认的函数就是友元函数,构造函数也是函数。当然有友元函数了。想要个完整的程序这就是完整的java程序呀,不好意思,没注意到你要的是c++程序。你能不能给做一下 用C++不好意思我们学过汇编,学过c学过java,但没学c++,烦人的学校用c好的,这就给你写,不过c语言没有类的概念,但结构体可以解决你的问题。这个程序希望对你有所帮助。#include#includestruct studinf{char name[20];long int id;int age,english,math,chinese;};struct studinf stud={"smallmonker",10062159,20,90,90,90};main(){struct studinf *p;printf("name\t\tid\tage\tenglish\tmath\tchinese\n");for(p=stud;penglish+p->math+p->chinese;ave=sum/3;printf("%s\t\t%ld\t%d\t%d\t%d\t%d\n",p->name,p->id,p->age,p->english,p->math,p->chinese);printf(\nsum);printf(avg\n);}}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版