| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1826 人关注过本帖
标题:求助C语言高手!BT学校居然布置英文作业~
取消只看楼主 加入收藏
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
 问题点数:0 回复次数:5 
求助C语言高手!BT学校居然布置英文作业~
[bold][underline]Week 10 Exercises – [/underline][/bold][bold][underline][font=TimesNewRoman]File Input/Output[/underline][/bold][/font]
[underline]Objectives[/underline][font=Times New Roman]Design and write programs that read and write data to/from files.[/font]
[underline]Tutorial Assessment[/underline]The students are required to do [bold][underline]ALL[/underline][/bold] exercises. [font=TimesNewRoman]All assessed exercises need to be submitted in the Assessment section of this module under ICE. Include comment lines to explain the code in detail (no design document is needed).[/font]
[underline]Deadlines[/underline][font=TimesNewRoman]The deadline for submitting the exercises is: [bold][italic]Thursday 6th December 2007 at 4pm.[/italic][/bold][bold][/bold][/font]
[bold] [/bold]

[align=center][bold][font=Wingdings]F[/font][/bold][bold][underline]Assessed exercises: 1, 2 & 3[/underline][/bold]

[/align]
[font=Times New Roman] [/font]
[underline]Exercise 1 (3 points)[/underline]
[font=TimesNewRoman]Write a file copy program that copies an existing file into another file. The program should ask the user to enter the source file name and destination file name. The file copy should be performed in [italic]binary[/italic] mode. Use [italic]fseek()[/italic]
to move within the source file and [italic]ftell()[/italic]
to determine the size of the file (if needed). Read the data from the source file and write the values read in the destination file in a [italic]loop[/italic]. Read and write data in blocks of [italic]1024 bytes[/italic].[/font]

[font=Times New Roman] [/font]
[underline]Exercise 2 (3 points)[/underline]
[font=TimesNewRoman]The following program reads from a [bold]text file [/bold]containing numeric data stored in columns separated by one blank space. Write the code and compile it on your computer. Create a text file called [bold]myfile.txt [/bold]containing a few columns (3[/font][font=Symbol]?[/font][font=Times New Roman]5 for example) of numeric data (real numbers) and test the program.[/font]
[bold][font=Times New Roman]#include <stdio.h>[/font][/bold]
[bold][font=Times New Roman]int main(void)[/font][/bold]
[bold][font=Times New Roman]{[/font][/bold]
[bold][font=Times New Roman]FILE *fp;[/font][/bold]
[bold][font=Times New Roman]double val;[/font][/bold]
[bold][font=Times New Roman]char ch;[/font][/bold]
[bold][font=Times New Roman] [/font][/bold]
[bold][font=Times New Roman]fp = fopen("myfile.txt","r");[/font][/bold]
[bold][font=Times New Roman]do{[/font][/bold]
[bold][font=Times New Roman]fscanf( fp, "%lf", &val );[/font][/bold]
[bold][font=Times New Roman]ch = getc(fp);[/font][/bold]
[bold][font=Times New Roman]printf(" %lf",val);[/font][/bold]
[bold][font=Times New Roman]if ( ch=='\n' || ch==EOF )[/font][/bold]
[bold][font=Times New Roman]printf("\n");[/font][/bold]
[bold][font=Times New Roman]} while ( ch != EOF );[/font][/bold]
[bold][font=Times New Roman]fclose(fp);[/font][/bold]
[bold][font=Times New Roman]return 0;[/font][/bold]
[bold][font=CourierNewPS-BoldMT]}[/bold][bold][/bold][/font]
[font=TimesNewRoman]Analyse the code and include comment lines explaining how the program achieves its task. Modify the code so that the program additionally creates a new text file where it stores only the integer part (discard the factionary part) of the real numbers stored in [bold]myfile.txt[/bold]. The new file should write data in the same format (3[/font][font=Symbol]?[/font][font=Times New Roman]5 with columns separated by space) as the original file. Include statements to check if the file was opened and closed successfully. Submit only the final, commented code.[/font]
[font=Times New Roman] [/font]
[font=Times New Roman] [/font]
[underline]Exercise 3 (4 points)[/underline]
[font=Times New Roman]Create a text file containing 20 rows of 20 integers separated by spaces. The integers should be in the range 0-9 and separated by spaces. Write a program that reads the contents into a 20[/font][font=Symbol]?[/font][font=TimesNewRoman]20 (two dimensional) array of int[/font]. [font=TimesNewRoman]The program then should use this array to initialize a 20x21 array of char by associating each integer from 0 to 9, with a character from ‘A’ to ‘J’. For example, 0 could be associated with ‘A’, while 9 with ‘J’. The 21st character on each line in the array of char should be the null character ‘\0’, making the array an array of 20 strings. Have the program display the resulting (picture) array of char (printing row-by-row the strings) on [italic]screen[/italic], and also write it in into a [italic]text file[/italic].[/font]
搜索更多相关主题的帖子: C语言 作业 学校 英文 
2007-12-03 15:06
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
得分:0 
唉....我们学金融的根本用不到C语言,但英国来的教务长还是坚持开设这门课,我都无语了,还望高手哥哥姐姐们指点啊~~
2007-12-04 03:03
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
得分:0 
可是我的对C语言一窍不通啊~~~郁闷
2007-12-04 13:26
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
得分:0 
可是我的对C语言一窍不通啊~~~郁闷
2007-12-04 13:27
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
得分:0 
求助啊求助~~
2007-12-04 22:34
只为流浪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-27
收藏
得分:0 
求助啊求助~
2007-12-06 15:20
快速回复:求助C语言高手!BT学校居然布置英文作业~
数据加载中...
 
   



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

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