有10个学生,每个学生的数据包括学号,姓名,三门课的成绩,从文件中读取学生数据,要求输出每位学生的 C语言:有10个学生,每个学生的数据包括学号,姓名,3门功课...

作者&投稿:俎欢 (若有异议请与网页底部的电邮联系)

模拟数据如下:

001|张三|85.5|79.0|92.0
002|李四|58.0|99.0|78.5
003|王五|88.0|51.0|63.0
004|孙六|84.0|88.0|92.0
005|杜七|52.0|51.0|43.0
006|刘八|96.0|100.0|99.0
007|钱九|61.0|77.0|79.5
008|周十|59.5|60.0|62.0
009|吴邪|88.0|92.0|75.0
010|郑州|78.0|91.0|99.0
import java.math.BigDecimal;

/**
 * 学生类
 */
public class Student {

    /**
     * 学号
     */
    private String code;

    /**
     * 姓名
     */
    private String name;

    /**
     * 语文
     */
    private double chinese;

    /**
     * 数学
     */
    private double math;

    /**
     * 英语
     */
    private double english;

    /**
     * 总分
     */
    private double total;

    /**
     * 平均分
     */
    private double average;

    public Student() {
    }

    public Student(String code, String name, double chinese, double math, double english) {
        this.code = code;
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public Student(String[] properties) {
        this(properties[0], properties[1],
                new BigDecimal(properties[2]).doubleValue(),
                new BigDecimal(properties[3]).doubleValue(),
                new BigDecimal(properties[4]).doubleValue());
    }

    public double calculateTotal() {
        this.total = this.chinese + this.math + this.english;
        return this.total;
    }

    public double calculateAverage() {
        average = (this.chinese + this.math + this.english) / 3;
        average = BigDecimal.valueOf(average).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return average;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getChinese() {
        return chinese;
    }

    public void setChinese(double chinese) {
        this.chinese = chinese;
    }

    public double getMath() {
        return math;
    }

    public void setMath(double math) {
        this.math = math;
    }

    public double getEnglish() {
        return english;
    }

    public void setEnglish(double english) {
        this.english = english;
    }

    public double getTotal() {
        return total;
    }

    public void setTotal(double total) {
        this.total = total;
    }

    public double getAverage() {
        return average;
    }

    public void setAverage(double average) {
        this.average = average;
    }
}
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {

    /**
     * 根据实际情况修改路径,我是MAC系统
     */
    private static final String DATA_INPUT_FILE = "/Users/liuchongguang/Downloads/scores.txt";

    /**
     * 根据实际情况修改路径,我是MAC系统
     */
    private static final String DATA_OUTPUT_FILE = "/Users/liuchongguang/Downloads/scores_result.txt";

    private static List<Student> loadStudents(String filePath) {
        List<Student> students = new ArrayList<Student>();
        InputStream is = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            is = new FileInputStream(new File(filePath));
            isr = new InputStreamReader(is, "UTF-8");
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                String[] properties = line.split("\\|");
                students.add(new Student(properties));
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                br.close();
                isr.close();
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return students;
    }

    private static void saveStudents(String filePath, List<Student> students, Map<String, Map<Double, List<Student>>> totalStudents,
                                     Map<String, Map<Double, List<Student>>> chineseStudents, Map<String, Map<Double, List<Student>>> mathStudents,
                                     Map<String, Map<Double, List<Student>>> englishStudents) {
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            File file = new File(filePath);
            if (!file.exists()) {
                file.createNewFile();// 不存在则创建
            }
            fw = new FileWriter(file, false);
            bw = new BufferedWriter(fw);
            for (Student student : students) {
                bw.write("[学号:" + student.getCode() + "," + student.getName() + "] 语文:"
                        + student.getChinese() + ",数学:" + student.getMath() + ",英语:" + student.getEnglish() +
                        "      总分:" + student.getTotal() + ",平均分:" + student.getAverage() + "
");
            }
            bw.write("
");
            saveStudents(bw, chineseStudents, "语文");
            saveStudents(bw, mathStudents, "数学");
            saveStudents(bw, englishStudents, "英语");
            saveStudents(bw, totalStudents, "总分");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bw.close();
                fw.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static void saveStudents(BufferedWriter bw, Map<String, Map<Double, List<Student>>> map, String language) throws Exception {
        bw.write("==============================" + language + "成绩统计==============================
");
        Map<Double, List<Student>> highMap = map.get("high");
        Double score = (Double) highMap.keySet().toArray()[0];
        List<Student> students1 = highMap.get(score);
        bw.write(language + "成绩最高分:" + score + ",获得者:");
        for (Student s : students1) {
            bw.write("[学号:" + s.getCode() + "," + s.getName() + "] ");
        }
        bw.write("
");
        Map<Double, List<Student>> lowMap = map.get("low");
        score = (Double) lowMap.keySet().toArray()[0];
        students1 = lowMap.get(score);
        bw.write(language + "成绩最低分:" + score + ",获得者:");
        for (Student s : students1) {
            bw.write("[学号:" + s.getCode() + "," + s.getName() + "] ");
        }
        bw.write("
");
        bw.write("
");
    }

    private static void calculate(List<Student> students, Map<String, Map<Double, List<Student>>> totalStudents,
                                  Map<String, Map<Double, List<Student>>> chineseStudents,
                                  Map<String, Map<Double, List<Student>>> mathStudents,
                                  Map<String, Map<Double, List<Student>>> englishStudents) {
        for (Student student : students) {
            student.calculateTotal();
            student.calculateAverage();
            compare(totalStudents, student.getTotal(), student);
            compare(chineseStudents, student.getChinese(), student);
            compare(mathStudents, student.getMath(), student);
            compare(englishStudents, student.getEnglish(), student);
        }
    }

    private static void compare(Map<String, Map<Double, List<Student>>> map, double score, Student student) {
        if (map.keySet().size() == 0) {
            HashMap<Double, List<Student>> highMap = new HashMap<Double, List<Student>>();
            HashMap<Double, List<Student>> lowMap = new HashMap<Double, List<Student>>();
            List<Student> students = new ArrayList<Student>();
            students.add(student);
            highMap.put(score, students);
            lowMap.put(score, students);
            map.put("high", highMap);
            map.put("low", lowMap);
        } else {
            Map<Double, List<Student>> highMap = map.get("high");
            Double key = (Double) highMap.keySet().toArray()[0];
            if (key == score) {
                List<Student> students = highMap.get(key);
                students.add(student);
            } else if (key < score) {
                highMap.clear();
                highMap = new HashMap<Double, List<Student>>();
                List<Student> students = new ArrayList<Student>();
                students.add(student);
                highMap.put(score, students);
                map.put("high", highMap);
            }

            Map<Double, List<Student>> lowMap = map.get("low");
            key = (Double) lowMap.keySet().toArray()[0];
            if (key == score) {
                List<Student> students = lowMap.get(key);
                students.add(student);
            } else if (key > score) {
                lowMap.clear();
                lowMap = new HashMap<Double, List<Student>>();
                List<Student> students = new ArrayList<Student>();
                students.add(student);
                lowMap.put(score, students);
                map.put("low", lowMap);
            }
        }
    }

    public static void main(String[] args) {
        //从文件中读取学生数据
        List<Student> students = loadStudents(DATA_INPUT_FILE);
        //总分最高分和最低分
        Map<String, Map<Double, List<Student>>> totalStudents = new HashMap<String, Map<Double, List<Student>>>();
        //语文最高分和最低分
        Map<String, Map<Double, List<Student>>> chineseStudents = new HashMap<String, Map<Double, List<Student>>>();
        //数学最高分和最低分
        Map<String, Map<Double, List<Student>>> mathStudents = new HashMap<String, Map<Double, List<Student>>>();
        //英语最高分和最低分
        Map<String, Map<Double, List<Student>>> englishStudents = new HashMap<String, Map<Double, List<Student>>>();

        //计算结果
        calculate(students, totalStudents, chineseStudents, mathStudents, englishStudents);

        //保存结果至文件
        saveStudents(DATA_OUTPUT_FILE, students, totalStudents, chineseStudents, mathStudents, englishStudents);
    }
}



有10个学生,每个学生数据包括学号,姓名、3门课程的成绩,从键盘输入10个学生的数据,要求输出学生3门课总~

#include "stdio.h"
#include
#define SIZE 10

struct student{
char id[20];
char name[20];
int score[3];
float average;
} stud[SIZE];

void input() /* 输入学生的信息 */
{
int i;

for(i=0;i<SIZE;i++)
{
printf("第%d个学生的信息:
",i+1);
scanf("%s%s%d%d%d",stud[i].id,stud[i].name,&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])/3.0;
}
}


void output() /* 输出学生的信息 */
{
int i;

printf("
");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d %3.1f
",stud[i].id,stud[i].name,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("
%s %s %d %d %d %3.1f
",stud[0].id,stud[0].name,stud[0].score[0],stud[0].score[1],stud[0].score[2],stud[0].average);
}

void main()
{
input();
output();
sortput();
}

#include
struct Student
{
char name[100];//名字
char num[100];//学号
double class1;//第一门课成绩
double class2;//第二门课成绩
double class3;//第三门课成绩
};
int main()
{
Student student[100];
for (int i = 0; i < 10; i++)//输入学生信息
{
gets(student[i].name);
getchar();//清空键盘缓冲区
gets(student[i].num);
getchar();
scanf("%lf%lf%lf",&student[i].class1,&student[i].class2,&student[i].class3);
}
for (int j = 0; j < 10; j++)//输出学生信息
{
printf("%s
%s
%lf
",student[j].name,student[j].num,(student[j].class1+student[j].class2+student[j].class3)/3.0);
}
return 0;
}

有十个学生,每个学生的数据包括学号,姓名,成绩。从键盘中输入十个学生...
答:写了一个比你需要的功能还完善的程序,在附件里,下面是运行截图:你用我的程序的时候把 #define N 1000 改为#define N 10 就可以了

有十个学生。每个学生包括学号,姓名,和三门成绩。从键盘输入十个学生的...
答:if(n<10)p1=(struct student*)malloc(len);scanf("%d,%s,%d,%d,%d",&p1->num,&p1->name,&p1->score[1],&p1->score[2],&p1->score[3]);} p2->next=null;return(head);} void main(){ struct student *p,*p3;int max=0;int i;int sum=0;p=creat(); /// while(p->ne...

C++结构体的运用
答:/ (1)职工数据包括:职工号、职工姓名、性别、年龄、工资、地址。为其定义一个结构体变量,对该变量,从键盘输入所需的具体数据,然后通过printf函数显示出来。(2)有10个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入10个学生数据,要求输出每个学生3门课程总平均成绩。/ define MAX...

C语言实验题 求大神指点
答:// 注意:你所指的最高学分,是指总成绩还是单科?下面我是按单科最高学分来求的。#include<stdio.h>#define STU_NUMBER 2 // 假设只有2个学生(你可以把2改为10)#define SCORE_NUMBER 4struct StudentInfo{int stu_id;char name[10];float score[4];float average;float score_sum;};// ...

.有10名学生的数据(包括学号、姓名、和三门课程的成绩即,数学、语言...
答:大致可以这样写 include<stdio.h> include<stdlib.h> struct student{ char num[10],name[10];int cn,eng,math;}; //设置一个学生信息的结构体 main(){ int i,j;FILE *fp; //设置文件指针 struct student stu[10],temp;if((fp=fopen("c:\\data.txt","w"))==NULL) //...

有10个学生,每个学生数据包括学号,姓名,专业,班级,三门课成绩?_百度知 ...
答:要求最高者的成绩并按各种排序输出,如果是文档类型可以通过筛选的形式排列。所以一般来说是选择成绩那一个筛选以后其他会自动排好。

二、实验题目: 有10个学生,每个学生的数据包括学号,姓名,及三门课成绩...
答:include <stdio.h> define N 30 struct student { int n;char name[10];int s;};void main( ){ struct student st[N];int i, k, max;for( i=0; i<N; i++)scanf(“%d %s %d”, &st[i].n, st[i].name, &st[i].s);。。。

C语言实现:某班有10个学生,每个学生包姓名和三门成绩,编写程序,从键盘...
答:include <stdio.h> include <string.h> struct student { char name[100];int a[3];} std[10];int main(){ int i, j;student s;for ( i = 0; i < 10; i++){ scanf("%s %d %d %d",std[i].name, &std[i].a[0], &std[i].a[1], &std[i].a[2]);} for (i =...

C++,从键盘输入10个学生的信息包括学号,姓名,成绩要求按每个学生的...
答:include"stdio.h"#include#defineSIZE10structstudent{charid[20];charname[20];intscore[3];floataverage;}stud[SIZE];voidinput()/*输入学生的信息*/{inti;for(i=0;i<SIZE;i++){printf("第%d个学生的信息:\n",i+1);scanf("%s%s%d%d%d",stud[i].id,stud[i].name,&stud[i].score...

...编写一个成绩统计程序,有10个学生(每个学生包括学号、姓名、数学...
答:using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 解决百度知道问题_学生成绩录入问题 { class Program { static void Main(string[] args){ Console.WriteLine("请输入学生的信息:");Observa...