1 学生类
class Student{
private String name;
private String number;
private int score;
//get/set省
public Student(){
}
public Student(String name, String number, int score){
thisname=name;
thisnumber=number;
thisscore=score;
}
}
import javautilArrayList;
import javautilScanner;import comsunorgapachexpathinternalArg;
public class Student {
//两个私有属性
private int no ;
private String name ;
//默认构造函数
public Student(){}
//带参构造函数
public Student(int no,String name){
thisno=no;
thisname=name;
}
//添加学生信息
public void addStudentInfo(ArrayList list){
String flag1="yes";
do{
Student student=new Student();
Scanner in =new Scanner(Systemin);
Systemoutprintln("请输入学生学号:");
studentsetNo(innextInt());
Systemoutprintln("请输入学生姓名:");
studentsetName(innext());
listadd(student);
Systemoutprintln("是否继续添加学生信息(yes/no)");
flag1=innext();
} while(flag1equals("yes"));
}
//读取学生信息
public void showStudentInfo(ArrayList<Student> list){
Systemoutprintln(" 学生no: "+" 学生name: ");
for(Student student:list){
Systemoutprintln(" "+studentgetNo()+" "+studentgetName());
}
}
public int getNo() {
return no;
}
public void setNo(int no) {
thisno = no;
}
public String getName() {
return name;
}
public void setName(String name) {
thisname = name;
}
public static void main(String arg[]) {
ArrayList<Student> studentList= new ArrayList<Student>();
Student student= new Student();
Scanner inn= new Scanner(Systemin);
while(true){
Systemoutprintln("----------------- 欢迎使用学生管理系统------------------");
Systemoutprintln("1输入学生信息");
Systemoutprintln("2显示学生信息");
Systemoutprintln("0退出系统");
Systemoutprintln("请选择");
int nn= innnextInt();
switch (nn) {
case 1:
studentaddStudentInfo(studentList);
break;
case 2:
Systemoutprintln("学生信息如下:");
studentshowStudentInfo(studentList);
break;
case 0:
Systemexit(0);
Systemoutprintln("系统退出!");
break;
default:
break;
}
}
} }
#include "stdioh"
#include <stdlibh>
#define SIZE 10
struct student{
char id[20];
char sex[10];
int age;
int score[3];
float average;
} stud[SIZE];
void input() / 输入学生的信息 /
{
int i;
for(i=0;i<SIZE;i++)
{
printf("第%d个学生的信息:\n",i+1);
scanf("%s%s%d%d%d%d",stud[i]id,stud[i]sex,&stud[i]age,&stud[i]score[0],&stud[i]score[1],&stud[i]score[2]);
stud[i]average=(stud[i]score[0]+stud[i]score[1]+stud[i]score[2])/30;
}
}
void output() / 输出学生的信息 /
{
int i;
printf("\n");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d %d %31f\n",stud[i]id,stud[i]sex,stud[i]age,stud[i]score[0],stud[i]score[1],stud[i]score[2],stud[i]average);
}
void sortput() / 排序输出学生信息 /
{
int i,j;
struct student temp;
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE-i-1;j++)
{
if(stud[j]average<stud[j+1]average)
{
temp=stud[j];
stud[j]=stud[j+1];
stud[j+1]=temp;
}
}
}
printf("\n");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d %d %31f\n",stud[i]id,stud[i]sex,stud[i]age,stud[i]score[0],stud[i]score[1],stud[i]score[2],stud[i]average);
}
void main()
{
input();
output();
sortput();
}
#include<stdioh>
#include<malloch>
struct Student
{
int num; //学号
char name[20]; //姓名
struct Score score;
};
struct Score
{
float politic;
float maths;
float english;
float special;
};
int main()
{
int M,N,i,j;
printf("Please input M:");
scanf("%d",&M);
struct Student stu = NULL;
stu = (struct Student)malloc(sizeof(struct Student)M); //创建一个结构体含有N个数据
for(i = 0; i < M; i++)
{
printf("Please input the No%d student's number:",i+1);
scanf("%d",&stu[i]num);
printf("Please input the No%d student's name:",i+1);
scanf("%s",stu[i]name);
stu[i]scorepolitic = 00; //初始化float 老版本编译器如果不初始化可能会报错
printf("Please input the No%d student' score of",i+1);
scanf("%f",&stu[i]scorepolitic);
stu[i]scoremaths = 00;
scanf("%f",&stu[i]scoremaths);
stu[i]scoreenglish = 00;
scanf("%f",&stu[i]scoreenglish);
stu[i]scorespecial = 00;
scanf("%f",&stu[i]scorespecial);
}
printf("Please input N:");
scanf("%d",&N);
for(i = 0; i < M; i++)
{
if(i+1 == N)
{
peinrf("%d %s %2f %2f %2f %2f\n",stu[i]num,stu[i]name,
stu[i]scorepolitic,
stu[i]scoremaths,
stu[i]scoreenglish,
stu[i]scorespecial);
}
}
free(stu); //释放
return 0;
}
以下是用 Python 语言编写的程序,实现读取学生的学号和英语成绩信息,并输出的功能:
# 定义学生信息类
class Student:
def __init__(self, id, name, score):
selfid = id
selfname = name
selfscore = score
# 定义读取学生信息的函数
def read_student_info():
student_list = []
while True:
id = input("请输入学号:")
if id == "":
break
name = input("请输入姓名:")
score = input("请输入英语成绩:")
student_listappend(Student(id, name, score))
return student_list
# 定义输出学生信息的函数
def print_student_info(student_list):
for student in student_list:
print("学号:" + studentid + " 姓名:" + studentname + " 英语成绩:" + studentscore)
# 主函数
def main():
student_list = read_student_info()
print_student_info(student_list)
# 调用主函数
main()
在运行这段程序之后,程序会提示用户输入学号、姓名和英语成绩,用户可以连续输入多个学生的信息。输入空学号时,程序会停止读取学生信息,并输出所有学生的学号、姓名和英语成绩。
#include<stdioh>
int main()
{
int test[]=;
int i,n;
printf("请输入一个数:");
scanf("%d",&n);
for(i=0;i<sizeof(test);i++)
if(n==test[i])
printf("该数在数组中第%d位",i);
if(i==sizeof(test))
printf("数组中没有输入的数");
return 0;
}
这里有一个类
实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩排序
public class Student {
private int id; //学号
private int mathScore; //数学成绩
private int chinScore; //语文成绩
private int foreScore; //外语成绩
public Student() {
id = 0;
mathScore = 0;
chinScore = 0;
foreScore = 0;
}
public Student(int newId, int newMathScore, int newChinSvore,
int newForeScore) {
id = newId;
mathScore = newMathScore;
chinScore = newChinSvore;
foreScore = newForeScore;
}
public double getAverageScore() { //求平均成绩
double averageScore = ((double) mathScore + chinScore + foreScore) / 3;
return averageScore;
}
public void output(Student student) { //输出对象的内容
Systemoutprintln(" " + studentid + " " + studentmathScore +
" " + studentchinScore + " "
+ studentforeScore + " " +
studentgetAverageScore());
}
public int max(Student a[], int n) { //Student类对象数组的前n项中的成绩最大值的索引
int position = 0;
for (int i = 1; i < n; i++) {
if (a[i]getAverageScore() > a[position]getAverageScore()) { //比较平均成绩
position = i;
}
}
return position;
}
public void selectSort(Student a[]) { //Student类对象数组的选择排序
for (int n = alength; n > 1; n--) {
int i = max(a, n);
Student temp = a[i];
a[i] = a[n - 1];
a[n - 1] = temp;
}
}
}
#include<iostream>#include<cstring>#include<iomanip>#include<fstream>#defineMax 1000usingnamespacestd;classstudent{private: char name[20]; int number; int grade;public: student(char,int,int); charGetName(){returnname;} int GetNo(){returnnumber;} int GetGra(){returngrade;}};student::student(charnames,intnum,intgra){ strcpy(name,names); number=num; grade=gra;}intmain(){ intm; charch[Max],names[20]; intnum,gra; for(inti=0;i<Max;i ){ch[i]='\0';} ifstreammyFile("studenttxt",ios_base::in); if(myFile) { cout<<"已存学生信息:"<<endl; myFileread((char)ch,1000); cout<<ch; } cout<<"请输入需要新建信息的学生人数:"; cin>>m; for(i=0;i<m;i ) { myFileclose(); cout<<"输入第"<<i 1<<"个新建信息学生姓名,学号和成绩:"; cin>>names; cin>>num>>gra; studentstu(names,num,gra); ofstreammyFile1("studenttxt",ios_base::app); myFile1<<"学生:"<<setw(14)<<stuGetName()<<"学号:"<<stuGetNo() <<"成绩:"<<stuGetGra()<<endl; myFile1close(); }} 程序运行示例:
以上就是关于java编写程序 实现定义学生信息类,包括学生的姓名、学号全部的内容,包括:java编写程序 实现定义学生信息类,包括学生的姓名、学号、要求编写一个java程序,输入学生信息,并能保存与显示学生信息。、c语言怎么编写学生信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)