题目内容

已知在文件IN54.DAT中存有100个产品销售记录,每个产品销售记录由产品代码dm(字符型4位)、产品名称mc(字符型10位)、单价dj(整型)、数量sl(整型)、金je(长整型)几部分组成。其中,金额=单价×数量可计算得出。函数ReadDat()的功能是读取这100个销售记录并存入数组sell中。请编制函数SortDat(),其功能要求:按金额从大到小进行排列,若金额相同,则按产品名称从小到大进行排列,最终排列结果仍存入结构数组sell中,最后调用函数WriteDat()把结果输出到文件 OUT54.DAT中。 注意:部分源程序已给出。 请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。 试题程序: #include<stdio.h> #include<mem.h> #include<string.h> #include<conio.h> #include<stdlib.h> #define MAX 100 typedef struct char dm[5]; char mc[11]; int dj; int sl; 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("IN54.DAT","r"); for(i=0;i<100;i++) fgets(str,80,fp); memcpy(sell[i].dm, str,4); memcpy(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].sl=atoi(ch); sell[i].je=(long)sell[i].dj*sell[i].sl; fclose(fp); void WriteDat() FILE *fp; int i; fP=fopen("OUT54.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].sl, sell[i].je); fclose(fp);

查看答案
更多问题

The residents, all of whose homes had been damaged by the flood, were given help by the government. The italicized part in the sentence is______.

A. a parenthesis
B. an appositive clause
C. a non-restrictive attributive clause
D. an adverbial clause

Which of the following details about the changing rooms is NOT correct

A. There is a charge for the use of the locker.
B. Showers are installed in the changing rooms.
C. Lockers are located in the changing rooms.
D. Lockers are used to store personal belongings.

Why isn’t Neal coming to the party

A. He is going a brad.
B. He is going home.
C. He has to work.
D. He is training for a triathlon.

According to the club’s rules, members can play______.

A. for 30 minutes only
B. for one hour only
C. within the booked time only
D. longer than the booked time

答案查题题库