1 / 12

上机实验 9 : 结构和文件程序设计

上机实验 9 : 结构和文件程序设计. 1 . 【9.5】【9. 三 ⑷ 】 《 查找最贵的书和最便宜的书 》 编写程序,从键盘输入 n(n<10) 本书的名称和定价 并存入结构数组中,从中查找定价最高和最低的书 的名称和定价,并输出。 ( filename: cp91.c ) 【 输入输出样例 】 ( 带下划线部分为输入 ) Input n: 3 Input the name,price of the 1 book: C 21.5 Input the name,price of the 2 book: VB 18.5

Download Presentation

上机实验 9 : 结构和文件程序设计

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 上机实验9:结构和文件程序设计 1.【9.5】【9.三⑷】《查找最贵的书和最便宜的书》 编写程序,从键盘输入n(n<10)本书的名称和定价 并存入结构数组中,从中查找定价最高和最低的书 的名称和定价,并输出。 ( filename: cp91.c ) 【输入输出样例】(带下划线部分为输入) Input n:3 Input the name,price of the 1 book:C 21.5 Input the name,price of the 2 book:VB 18.5 Input the name,price of the 3 book:Delphi 25.0 The book with the max price:Delphi,price is:25.0 The book with the min price:VB,price is:18.5

  2. 2.【9.2】【9.三⑴】 ( filename: cp92.c ) 《一个时间过n秒后的时间》 编程,用结构类型表示时间内容(时间以时、分、 秒表示),以h:m:s 的格式输入一个时间数值,再输 入一个秒数n,以h:m:s 的格式输出该时间再过n 秒后 的时间值(超过24 点就从0点开始计时)。 【输入输出样例1】 11:59:40 30 12:0:10 【输入输出样例2】 23:58:40 130 0:0:50

  3. 3. 《算绩点和排名次》 ( filename: cp93.c ) 从键盘依次输入n 和n 个学生的学号、姓名以及4 门课程的成绩,计算每个学生的总分和平均成绩绩 点,按总分排出名次,相同的总分名次也相同,然 后按名次顺序(名次相同的按学号)输出这n个学生包 括名次、总分和平均绩点在内的全部信息,每个学 生一行。要求和说明如下:

  4. ⑵成绩绩点的计算规则: ⑴ 存放学生信息的 结构体类型为: struct student { /* 学号,4位数字字符*/ char num[5]; /* 姓名,少于16个字符 */ char name[16]; /* 4门课程的成绩*/ int score[4]; /* 总成绩*/ int ts; /* 成绩绩点*/ float sgpa; };

  5. ⑶ 每个学生一行的输出内容与格式: 名次学号姓名成绩成绩成绩成绩总分绩点 (%2d%4s%-15s%3d%3d%3d%3d%3d%4.2f ) 其中表示空格。 【输入样例】 5 0901 Mickey 90 91 77 80 0902 Donald 96 71 72 63 0903 Tom 100 64 74 86 0904 Simba 87 88 81 83 0905 Jerry 98 80 65 81

  6. 【输出样例】(表示空格) 1 0904 Simba 87 88 81 83 339 3.42 2 0901 Mickey 90 91 77 80 338 3.42 3 0903 Tom 100 64 74 86 324 2.88 3 0905 Jerry 98 80 65 81 324 2.88 5 0902 Donald 96 71 72 63 302 2.33

  7. 3.2【12.5】【12.三⑷】(此题自行练习,不计入作业)3.2【12.5】【12.三⑷】(此题自行练习,不计入作业) 《比较两个文本文件的内容》 编程,比较两个文本文件 f1.txt 和 f2.txt 内容是否 相同,输出两个文件中第一次出现不同字符内容的 行号和列值。如果两个文件完全相同,则输出: Two files are the same.。 【输入样例1】 f1.txt 内容: abcdefg hijklmno pqrstuvwxyz 【输出样例1】 line number=3,leter position=10 f2.txt 内容: abcdefg hijklmno pqrstuvwx*yz

  8. f2.txt 内容: abcdefg hijklmno123 pqrstuvwx*yz 【输入样例2】 f1.txt 内容: abcdefg hijklmno pqrstuvwxyz 【输出样例2】 line number=2,leter position=9 【输入样例3】 f1.txt 内容: abcdefg 【输出样例3】 Two files are the same. f2.txt 内容: abcdefg

  9. 4.《文本文件中的正整数是否为同构数》 当前目录下的文本文件filein.txt中存有不多于20个 用空格间隔的正整数。请编程,先从该文件中依次读 入这些数,然后判断其是否为同构数,并按如下举例 格式显示在屏幕上,并写入到文本文件fileout.txt中。 所谓同构数是其平方数的尾数等于该数自身的正整 数,例如:25×25=625。 【输入样例】 fielin.txt 文件的内容为: 25 11 125 9376

  10. 【输出样例】 ( filename: cp94.c ) 屏幕显示和 fielout.txt 文件的内容均为: 25: yes,25*25=625 11: no,11*11=121 125: no,125*125=15625 9376: yes,9376*9376=87909376 提示: 设已定义:int n, a[100]; FILE *fp;,从已用fp以 读方式打开的文本文件中读取未知个数的整数可用 下列语句,完成后,n为读取整数的个数: for(n=0; fscanf(fp,"%d", &a[n])!=EOF; n++);

  11. 5.《统计文本文件中各英文字母的个数》 编程,统计当前目录下文本文件 f5.txt 中各英文字 母的个数,统计时不区分大小写,然后对至少有一 个的字母,按字母顺序依次输出其个数,每个字母 的输出样式为:大写的该字母=个数,各字母间用空 格隔开。如果该文件中没有英文字母,则输出none。 【输入样例】 ( filename: cp95.c ) f5.txt 文件的内容为: Gain new knowledge by reviewing old. 【输出样例】 A=1 B=1 D=2 E=5 G=3 I=3 K=1 L=2 N=4 O=2 R=1 V=1 W=3 Y=1

  12. 结 束

More Related