程序设计基础课程设计_第1页
程序设计基础课程设计_第2页
程序设计基础课程设计_第3页
程序设计基础课程设计_第4页
程序设计基础课程设计_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序设计基础课程设计程序设计基础课程设计 实验报告实验报告 班级 1403011 姓名 陈玉洪 学号所选题目 1 1 1 3 1 4 2 1 2 3 3 1 3 3 4 1 5 1 第第 1 1 题题 算法描述 算法描述 设计一个复数类型 输入实部和虚部生成一个复数 可进行两个复数求和 求差 求积运算 源程序 源程序 no1 1 c include int main float a1 a2 b1 b2 a b char c1 scanf f fi while 1 c1 getchar if c1 n break scanf f fi if c1 a a1 a2 b b1 b2 if c1 a a1 a2 b b1 b2 if c1 a a1 a2 b1 b2 b a1 b2 a2 b1 a1 a b1 b printf f fi a b return 0 测试数据 测试数据 第第 1 3 题题 算法描述 算法描述 假定用一个整型数组表示一个长整数 数组的每个元素存储长整数的一位数字 实际的长整数 m 表示 为 m a k 10k 1 a k 1 10k 2 a 2 101 a 1 100 其中 a 0 保存该长整数的位数 实现长整数除普通整数 源程序 源程序 no1 1 c include include int count int x int i for i 0 x 0 x 10 i return i int main int n mun t x i j a 100 b 100 char c printf m for i 1 c getchar n i a i c 0 i a 0 i for j 1 ja 0 x j mun 10 mun a j if mun n 0 b 0 a 0 x 1 for i b 0 i 1 i b i mun n mun n mun mun 10 a i 1 else b 0 a 0 x mun mun 10 a a 0 x for i b 0 i 1 i b i mun n mun mun n mun mun 10 a i 1 printf m n for i b 0 i 0 i printf d 10 d b i i 1 if i 1 printf putchar n return 0 测试数据 测试数据 第第 1 4 题题 算法描述 算法描述 根据输入的数字 N 计算 N 以内 包括 N 数据链并统计数据链末尾数字是 1 的数据个数 例如 N 44 则数字链为 44 32 13 10 1 其规则为 4 4 4 4 32 3 3 2 2 13 1 1 3 3 10 1 1 0 0 1 源程序 源程序 no1 4 c include int fenjie int x int t num 0 for t 0 x 0 x 10 t x 10 num t t return num int main int j x i m count 0 for j 0 j 10 break else printf error input again n if j 5 printf too much error end n if j 10 i m i for m 10 m fenjie m if m 1 count printf d count return 0 测试数据 测试数据 第第 2 1 题题 算法描述 算法描述 用文件保存一段英文文本 1 统计各字母在文本中出现的次数 区分大小写 并按英文字母序输出统计结果 2 查找并替换文本中的某字符串 将替换后的文本存入另一个文 源程序 源程序 no2 1 c include include int main FILE fp fq fw int i j 0 a 1000 0 char c b 100 100 0 e 100 0 d 100 0 fq fopen put txt w fp fopen get txt r fw fopen get txt r if fp NULL fw NULL printf cann t open it else for c fgetc fp EOF a c for i A i z i if a i 0 printf c d n i a i scanf s e scanf s d for i 0 i for j 0 j b i j fgetc fw if b i j b i j n b i j EOF break if b i j EOF break b i j 0 if strcmp b i e 0 fprintf fq s d else fprintf fq s b i fclose fp fclose fq fclose fw return 0 测试数据测试数据 第第 2 3 题题 算法描述 算法描述 现有两个文本文件 file1 txt 和 file2 txt file1 中第一列为姓名 第二列为英语成绩 file2 中第一列为姓 名 第二列为数学成绩 通过程序关联 file2 中与 file1 对应的姓名生成 file3 txt 文件 file3 txt 文件第一 列为姓名 第二列为英语成绩 第三列为数学成绩 第四列为平均成绩 file1 txt file2 txt file3 txt Bob 90 David 80 George 84 Jack 64 Jim 95 George 74 David 82 Paul 70 Jack 70 Bob 86 Bob 90 86 88 David 80 82 81 George 84 74 79 Jack 64 70 67 源程序源程序 no2 3 c include include int main struct chji char name 20 int x struct zongchji char name 20 int y z t chji f1 0 0 f2 0 0 zongchji f3 0 0 0 int n 0 m 0 t min FILE fp fq fw fp fopen file1 txt r fw fopen file3 txt a if fp NULL fw NULL printf cann t open it n for fscanf fp d fscanf fp s f1 name fscanf fp d fq fopen file2 txt r if fq NULL printf cann t open it n for fscanf fq d fscanf fq s f2 name fscanf fq d if strcmp f1 name f2 name 0 f3 t f1 x f2 x 2 f3 y f1 x f3 z f2 x strcpy f3 name f2 name fprintf fw s d d d n f3 name f3 y f3 z f3 t fclose fq fclose fp fclose fw return 0 测试数据测试数据 第第 3 1 题题 算法描述 算法描述 用字符数组保存一个英文句子 1 删除该英文句子的前导空格 后导空格 句中多余空格 单词之间只留一个空格 2 统计句中某单词出现的次数 3 查找并替换某单词 源程序源程序 no3 1 c include include void move char a int i j for i 0 a i 0 i a i a i 1 int main char line 1000 0 word 100 100 0 c mun 2 50 0 change 50 0 int i j n count 0 find 1 for i 0 c getchar n i line i c line i 0 for line 0 if line 0 move line while find find 0 for i 1 line i 0 i if line i if line i 1 j i for line j 0 j line j line j 1 find 1 if line i 0 if line i 1 line i 1 0 printf you want count word n scanf s mun 0 i 0 for j 0 line i 0 j for n 0 line i i n word j n line i i for i 0 i j i if strcmp mun 0 word i 0 count printf s d n mun 0 count printf you want to change n scanf s change printf to scanf s mun 1 for i 0 i j 1 i if strcmp change word i 0 printf s mun 1 else printf s word i return 0 数据测试数据测试 第第 3 3 题题 算法描述 算法描述 文本文件 num1 txt 和 num2 txt 中各有一组用空格分隔的整数 将 num1 txt 和 num2 txt 联合排序 并将结果保存在 num3 txt 中 num1 txt 20 15 25 0 3 100 120 6 14 num2 txt 125 63 1233 2 10 17 133 99 1 num3 txt 0 1 2 3 6 10 14 15 17 20 25 63 99 100 120 125 133 1233 源程序源程序 no3 3 c include int main FILE fp fq fw int a 100 0 b 100 0 i n j t find 1 fp fopen num1 txt r fq fopen num2 txt r fw fopen num3 txt w if fp NULL fq NULL fw NULL printf cann t open it for i 0 fscanf fp d i for fscanf fq d i n i while find find 0 for i 0 ia i 1 find 1 t a i a i a i 1 a i 1 t for j 0 j n j fprintf fw d a j fclose fp fclose fq fclose fw return 0 测试数据测试数据 第第 4 1 题题 算法描述 算法描述 通讯录管理软件 通讯者信息包括 姓名 性别 手机 Email 地址 软件功能 添加 查询 删除 全部输出 源程序源程序 no4 1 c include include int main int i j n m mun t char nam 20 0 line 200 100 0 mn 20 0 FILE fp fp1 fm fp fopen tong txt r fm fopen tong1 txt a if fp NULL fp1 NULL fm NULL printf cann t open it n else printf add 1 delete 2 find 3 output 4 esc 0 n for i 0 fscanf fp s line i EOF i mun i for scanf d if m 1 printf name xingbei phone n scanf s s s printf email scanf s printf dress scanf s mun 5 if m 2 printf delete name scanf s for j 0 j mun j if strcmp line j nam 0 for t 0 t 5 t strcpy line t j mn if m 3 n 10 printf who do you find n printf name scanf s for i 0 i mun i if strcmp line i nam 0 n 5 if n0 printf s line i n if n 0 break if n 10 printf no find n if m 4 printf output n for i 0 i mun i if strcmp line i mn 0 printf s line i if i 1 5 0 putchar n if m 0 break for i 0 i mun i if strcmp line i mn 0 fprintf fm s line i if i 1 5 0 fprintf fm n fclose fp fclose fm return 0 测试数据 测试数据 第第 5 15 1 题题 算法描述 算法描述 程序自动生成一个位于 900 1000 内的随机数 要求用户猜这个数 用户输入一个数后 程序有三 种应答 too big too small you win 源程序 源程序 no5 1 c include include int main int c i 0 j n t num a 100 0 printf please input a start numbe n scanf d srand t for i 0 i900 i printf input a number 0 to 4 scanf d num a n printf please guss the number n for j 0 j 10 j scanf d if cnum printf too big try agai

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论