制作成绩表格可以通过多种编程语言和方法实现,下面我将介绍几种常见的方法,包括使用C++、C、Python等语言,并提供一些示例代码。
使用C++
```cpp
include include int main() { int scores[] = {90, 80, 95, 87, 76, 82, 72, 90, 84, 89, 87, 91, 95, 91, 98, 95, 86, 97, 88, 94}; int len = sizeof(scores) / sizeof(scores); int n = len / 4; // 学生数量,因为每个学生的成绩有四门课组成 for (int i = 0; i < n; ++i) { int totalScore = 0; for (int j = 0; j < 4; ++j) { totalScore += scores[i * 4 + j]; } std::cout << std::setw(5) << totalScore; // 设置列宽为5字符,使输出对齐 float averageScore = static_cast std::cout << std::setw(5) << std::round(averageScore); // 四舍五入取整 std::cout << std::endl; } return 0; } ``` 使用C ```csharp using System; class Program { static void Main() { const int N = 10; Student[] students = new Student[N]; for (int i = 0; i < N; i++) { Console.Write("输入学生姓名: "); string name = Console.ReadLine(); Console.Write("输入学生学号: "); int id = int.Parse(Console.ReadLine()); Console.Write("输入数学成绩: "); float math = float.Parse(Console.ReadLine()); Console.Write("输入英语成绩: "); float english = float.Parse(Console.ReadLine()); Console.Write("输入计算机成绩: "); float computer = float.Parse(Console.ReadLine()); students[i] = new Student { Name = name, Id = id, Math = math, English = english, Computer = computer }; } Console.WriteLine("学号\t序号\t数学成绩\t英语成绩\t计算机成绩\t总分\t平均分"); for (int i = 0; i < N; i++) { Student student = students[i]; int totalScore = student.Math + student.English + student.Computer; float averageScore = totalScore / 3; Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", student.Id, i + 1, student.Math, student.English, student.Computer, totalScore, averageScore); } } } class Student { public string Name { get; set; } public int Id { get; set; } public float Math { get; set; } public float English { get; set; } public float Computer { get; set; } } ``` 使用Python