| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 620 人关注过本帖
标题:求把这个c++程序转成普通c语言!最好有malloc
取消只看楼主 加入收藏
francistang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-10-14
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求把这个c++程序转成普通c语言!最好有malloc
你被要求写使用实现考试成绩处理系统结构的程序。
有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

[ 本帖最后由 francistang 于 2015-10-14 06:33 编辑 ]
搜索更多相关主题的帖子: c语言 学生证 文本文件 考试成绩 
2015-10-14 06:27
francistang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-10-14
收藏
得分:0 
顶顶顶
2015-10-14 17:06
快速回复:求把这个c++程序转成普通c语言!最好有malloc
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015451 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved