求把这个c++程序转成普通c语言!最好有malloc
来源:互联网 发布:怎样安装三菱编程软件 编辑:程序博客网 时间:2024/05/21 11:14
你被要求写使用实现考试成绩处理系统结构的程序。
有5名学生。每个学生都有一个学生证和5门课的不同分数。
学生ID存储为8位数字串。
为学生数据最初存储在文本文件“student.txt”,应该由程序读出。
该方案必须:
运用结构语句struct
不使用任何全局变量(global variable)。
使用数组或指针数组,来存储数据,每一个学生。
阅读为每个学生的数据。
打印学生最低的组合标志(ID和总分)。
打印学生最高的组合标志(ID和总分)。
打印学生的所有标记(ID和最高分)的单一最高分。
所有的答案将是独一无二的。
示例:
如果该文件包含student.txt:
11111111 1 2 3 4 5
22222222 95 96 97 98 98
33333333 30 40 50 60 70
44444444 66 69 34 84 51
55555555 90 100 97 98 98
则输出是:
11111111 15
22222222 484
55555555 100
下面是c++版本,现在希望得到c语言版本。最好使用malloc函数和“.”,“->”
#include <iostream>
#include <array>
#include <fstream>
#include <cstring>
using namespace std;
struct Student
{
char id[25];
int m1;
int m2;
int m3;
int m4;
int m5;
};
void CopyRecords(string Fname,Student p[5]);
void Display(Student p[5]);
void getTotal(Student p[5],int totals[5]);
int main()
{
Student p[5];
int totals[5],hmarks[5],total=0,min=0,max=0,high;
// Copy data from file to structure array p
CopyRecords("student.txt",p);
// Display uppercase
cout<<"Data Read in Student structure array is \n\n";
Display(p);
cout<<endl;
// Make Name variable all uppercase
getTotal(p,totals);
min=totals[0];
max=totals[0];
//high=p[0].m1;
int maxindx=0,minindx=0,hindx=0;
for(int i=0;i<5;i++)
{
if(totals[i]>max)
{
max=totals[i];
maxindx=i;
}
if(totals[i]<min)
{
min=totals[i];
minindx=i;
}
}
cout<<"\nStudent with lowest total is " << p[minindx].id<<" "<<totals[minindx]<<endl;
cout<<"\nStudent with highest total is " << p[maxindx].id<<" "<<totals[maxindx]<<endl;
//hmarks[0]=
max=0;
for(int i=0;i<5;i++)
{
max=p[i].m1;
if(p[i].m2>max)
{
max=p[i].m2;
}
if(p[i].m3>max)
{
max=p[i].m3;
}
if(p[i].m4>max)
{
max=p[i].m4;
}
if(p[i].m5>max)
{
max=p[i].m5;
}
hmarks[i]=max;
}
cout<<"\nHighest marks obtained by any student is \n\n";
max=0,maxindx=0;
for(int i=0;i<5;i++)
{
if(hmarks[i]>max)
{
max=hmarks[i];
maxindx=i;
}
}
cout<<"Id: "<
}
void getTotal(Student p[5],int totals[5])
{
int total;
for(int i=0;i<5;i++)
{
totals[i]=0;
totals[i]= p[i].m1 + p[i].m2+ p[i].m3+ p[i].m4+ p[i].m5;
}
}
<p[maxindx].id<<" "<<"Marks: "<<max<<endl;
//system("PAUSE");
return 0;
}
void CopyRecords(string Fname,Student p[5])
{
ifstream f;
f.open(Fname);
for (int i = 0; i < 5; i++)
{
//f.getline(p[i].id, 8, ' ');
f >> p[i].id >> p[i].m1 >> p[i].m2 >> p[i].m3 >> p[i].m4 >> p[i].m5;
}
f.close();
}
void Display(Student p[5])
{
for (int i = 0; i < 5; i++)
{
cout << p[i].id << " " << p[i].m1 << " " << p[i].m2<< " " << p[i].m3<< " " << p[i].m4<< " " << p[i].m5<<endl;
}
// Have all data under variable Name uppercase
有5名学生。每个学生都有一个学生证和5门课的不同分数。
学生ID存储为8位数字串。
为学生数据最初存储在文本文件“student.txt”,应该由程序读出。
该方案必须:
运用结构语句struct
不使用任何全局变量(global variable)。
使用数组或指针数组,来存储数据,每一个学生。
阅读为每个学生的数据。
打印学生最低的组合标志(ID和总分)。
打印学生最高的组合标志(ID和总分)。
打印学生的所有标记(ID和最高分)的单一最高分。
所有的答案将是独一无二的。
示例:
如果该文件包含student.txt:
11111111 1 2 3 4 5
22222222 95 96 97 98 98
33333333 30 40 50 60 70
44444444 66 69 34 84 51
55555555 90 100 97 98 98
则输出是:
11111111 15
22222222 484
55555555 100
下面是c++版本,现在希望得到c语言版本。最好使用malloc函数和“.”,“->”
#include <iostream>
#include <array>
#include <fstream>
#include <cstring>
using namespace std;
struct Student
{
char id[25];
int m1;
int m2;
int m3;
int m4;
int m5;
};
void CopyRecords(string Fname,Student p[5]);
void Display(Student p[5]);
void getTotal(Student p[5],int totals[5]);
int main()
{
Student p[5];
int totals[5],hmarks[5],total=0,min=0,max=0,high;
// Copy data from file to structure array p
CopyRecords("student.txt",p);
// Display uppercase
cout<<"Data Read in Student structure array is \n\n";
Display(p);
cout<<endl;
// Make Name variable all uppercase
getTotal(p,totals);
min=totals[0];
max=totals[0];
//high=p[0].m1;
int maxindx=0,minindx=0,hindx=0;
for(int i=0;i<5;i++)
{
if(totals[i]>max)
{
max=totals[i];
maxindx=i;
}
if(totals[i]<min)
{
min=totals[i];
minindx=i;
}
}
cout<<"\nStudent with lowest total is " << p[minindx].id<<" "<<totals[minindx]<<endl;
cout<<"\nStudent with highest total is " << p[maxindx].id<<" "<<totals[maxindx]<<endl;
//hmarks[0]=
max=0;
for(int i=0;i<5;i++)
{
max=p[i].m1;
if(p[i].m2>max)
{
max=p[i].m2;
}
if(p[i].m3>max)
{
max=p[i].m3;
}
if(p[i].m4>max)
{
max=p[i].m4;
}
if(p[i].m5>max)
{
max=p[i].m5;
}
hmarks[i]=max;
}
cout<<"\nHighest marks obtained by any student is \n\n";
max=0,maxindx=0;
for(int i=0;i<5;i++)
{
if(hmarks[i]>max)
{
max=hmarks[i];
maxindx=i;
}
}
cout<<"Id: "<
}
void getTotal(Student p[5],int totals[5])
{
int total;
for(int i=0;i<5;i++)
{
totals[i]=0;
totals[i]= p[i].m1 + p[i].m2+ p[i].m3+ p[i].m4+ p[i].m5;
}
}
<p[maxindx].id<<" "<<"Marks: "<<max<<endl;
//system("PAUSE");
return 0;
}
void CopyRecords(string Fname,Student p[5])
{
ifstream f;
f.open(Fname);
for (int i = 0; i < 5; i++)
{
//f.getline(p[i].id, 8, ' ');
f >> p[i].id >> p[i].m1 >> p[i].m2 >> p[i].m3 >> p[i].m4 >> p[i].m5;
}
f.close();
}
void Display(Student p[5])
{
for (int i = 0; i < 5; i++)
{
cout << p[i].id << " " << p[i].m1 << " " << p[i].m2<< " " << p[i].m3<< " " << p[i].m4<< " " << p[i].m5<<endl;
}
// Have all data under variable Name uppercase
0 0
- 求把这个c++程序转成普通c语言!最好有malloc
- 如何把c语言转成汇编语言[整理]
- malloc的简单使用-c语言程序
- 历史上最好的C语言程序
- C语言中怎么把Int型转成字符型
- 急求C语言程序!!!
- C语言malloc用法
- C语言malloc\free
- C语言malloc/free
- C语言malloc用法
- c语言中的malloc
- c语言malloc函数
- c语言malloc分配
- C语言 malloc
- c语言malloc函数
- 学习c语言中,有个程序怎么不懂,求帮忙编一个程序
- 两个c语言程序 求解答
- 求N的阶乘C语言程序
- 《王保明老师----Linux开发学习笔记》------讲12:守护进程 -----如何分析和理解下面这个创建守护进程的实例
- Using smem on Android
- 三种东西永远不要放到数据库里
- iOS中的block和retain cycle
- 浏览器报错:Cannot read property 'style' of null
- 求把这个c++程序转成普通c语言!最好有malloc
- NSArray NSMutableArray 的并发遍历 与 反向遍历
- java synchronized关键字详解
- 零碎的知识
- 【Swift】类型推断
- (八)Spark源码理解之DAGScheduler---part2
- OSI模型网络分层
- jquery 循环获取表单下一个元素(回车绑定tab事件)
- SVN中的check out与export的区别