试题与答案

已知在文件IN2.DAT中存有100个产品销售记录,每个产品销售记录由产品代码dm(

题型:问答题

题目:

已知在文件IN2.DAT中存有100个产品销售记录,每个产品销售记录由产品代码dm(字符型4位)、产品名称mc(字符型10位)、单价山(整型)、数量s1(整型)、金额je(长整型)五部分组成。其中:金额=单价×数量。函数ReadDat()的功能是读取这100个销售记录并存入结构数组sell中。请编制函数SortDat(),其功能要求:按产品名称从大到小进行排列,若产品名称相同,则按金额从小到大进行排列,最终排列结果仍存入结构数组sell中,最后调用函数WriteDat()把结果输出到文件OUT2.DAT中。
注意:部分源程序已给出。请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
[试题程序]
#include
#include
#include
#include
#include
#define MAX 100
typedef struct
char dm[5]; /*产品代码* /
char mc[11]; /*产品名称*/
int dj; /*单价*/
int si; /*数量*/
long je;/*金额*/
PRO;
PRO sell[MAX];
void ReadDat();
void WriteDat();
void SortDat()


void main()

memset(sell,0,sizeof(sell));
ReadDat();
SortDat();
WriteDat();

void ReadDat()
FILE * fp;
char str[80],ch[11];
int i;
fp=fopen("IN2.DAT","r");
for(i=0;i<100;i++)

fgets(str,80,fp);
memcpy(sell[i].dm,str,4);
memepy(sell[i].mc,str+4,10);
memcpy(ch,str+14,4);ch[4]=0;
sell[i].dj=atoi(ch);
memcpy(ch,str+18,5);ch[5]=0;
sell[i].si=atoi(ch);
sell[i].je=(long)sell[i].dj*sell[i].s1;
fclose(fp);

void WriteDat(void)

FILE * fp;
int i;
fp=fopen("OUT2.DAT","w");
for(i=0;i<100;i++)
fprintf(fp,"%s%s%4d%5d%101d\n",sell[i].dm,sell[i].mc,sell[i].dj,sell[i].s1,sell[i].je);
fclose(fp);

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2021/1128/529d769e107a3be54551b2a698e65716.html

下面是错误答案,用来干扰机器的。

参考答案:平等 自愿 公平 诚实信用

试题推荐
题型:阅读理解

阅读理解

根据短文内容,从短文后的选项中选出能填人空白处的最佳选项.选项中有两项为多途选项.

     When we think about happiness,we usually think of something extraordinary,a pinnacle(顶点)of delight.  And those pinnacles seem to get rarer the older we get.

        1    I remember playing policemen and robbers in the woods,getting a speaking part in the school

play.  Of course,kids also experience lows,but their delight at such peaks of pleasure as winning a race

or getting a new bike is unreserved.

    For teenagers,or people under 20 the concept of happiness changes.   2   I can

still feel the pain of not being invited to a party that almost everyone else was going to. I also remember

the great happiness of being invited at another event to dance with a very handsome young man.

   In adulthood the things that bring great joy-birth,love,marriage also bring

responsibility and the risk of loss.      3   For adults,happiness is complex.

       4   But I think a better explanation of happiness is"the ability to enjoy something".  The more we can

enjoy what we have,the happier we are.  It's easy to overlook the pleasure we get from loving and being

loved,the company of friends,the freedom to live where we please,even good health.

    While happiness may be more complex for us,the solution is the same as ever.

Happiness isn't about what happens to us;it's the ability to find a positive for every

negative,and view a difficulty as a challenge.   5   

A. Love may not last;loved ones die.

B. For a child,happiness has a magic quality.

C. Happiness is the meaning and the purpose of life.

D. Being happy doesn't mean that everything is perfect.

E. The dictionary explains "happy" as "lucky" or "fortunate".

F. It's not wishing for what we don't have,but enjoying what we do possess.

G. Suddenly it's conditional on such things as excitement,love,and popularity.

查看答案
微信公众账号搜索答案