




已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西南交通大学 程序设计综合实验 实验地点 实验学期 学生班级 学生学号 学生姓名 任课教师 龚勋 信息科学与技术学院 2012 年 4 月 实验一 实验一 ATM 机用户操作界面 业务逻辑机用户操作界面 业务逻辑 编写编写 实验目的及内容 1 根据 ATM 的工作流程编写用户界面 掌握文本用户菜单的 编写方法 2 根据 ATM 的工作流程编写业务罗杰 掌握搭建一个完整的 应用系统的方法及软件编程思想 实验要求 1 除提示用户输入的数字外 界面上不能响应 出现任何其他 用户输入 2 每个菜单界面独立显示 不要出现多组菜单重叠显示的现象 3 每个业务逻辑可以多次执行 直到用户选择退出业务 实验步骤及核心代码 void main int bExit 0 char in 控制语言的选择 while bExit MainMenu in getch system cls switch in 语言选择 void MainMenu void LanguageMenu int t int cExit 0 char in while cExit if t 1 显示中文功能选择菜单 in getch system cls switch in 中文功能函数的选择 else 同上 只需将中文函数改为英文函数 中文的查询函数 void Query1 printf n printf 此账户有 2f 元 n sum 对 sum 已初始化 system pause system cls 中文的存钱函数 void Deposit1 float p float x printf n printf 输入您要存的数目 scanf f p x system pause system cls 中文的取钱函数 void WithDraw1 float p float y int a 1 printf n printf 输入您要取的数目 while a scanf f if y sum printf n 余额不足 按任意键后重新输入 n else p y a 0 system pause system cls 实验二 进制转换器实验二 进制转换器 实验目的及内容 写一个进制转换器 实现十进制 二进制 十六进制的相互转换 实验要求 1 转换要求包括整数和小数 2 提供清晰 有好的用户界面 3 各种转换可以反复多次执行 直到用户选择 退出 按钮 实验步骤及核心代码 void main void Mainmenu 二进制到十进制和十六进制 void BtoDH int iExit 0 while iExit system cls string s1 s2 s3 s int i len 输入字符串 s s s1 len s1 length for i 0 i len i s3 s1 substr 0 1 截取从 0 到 1 的字符 包括 0 不包括 1s1 s1 substr 1 s1 length 1 if s3 s2 s substr 0 i 截取 0 到 i 的字符 break if s2 length 0 s2 s s1 int in BtoDint s2 把二进制数分离开后 调用整数部分 float dou BtoDdecimal s1 调用二进制小数部分 dou in dou string ss1 ss2 ss1 BtoHint s2 1 ss2 BtoHint s1 0 输出十进制形式和十六进制形式 二进制整数到十进制整数 int BtoDint string s int i ss 0 len l len s length 1 l len for i 0 i len i string ch s substr 0 1 s s substr 1 s length 1 if ch 1 ss pow 2 l l else l return ss 二进制小数到十进制小数 float BtoDdecimal string s float ss 0 0 int i len l len s length 1 l 1 for i 0 i len i string ch s substr 0 1 s s substr 1 s length 1 if ch 1 ss pow 2 i pow 函数返回值为计算 2 的 i 次方 l else l return ss 十六进制到二进制和十进制 void HtoBD int iExit 0 len i string s s1 s3 s2 ss1 ss2 while iExit system cls cout s1 s s1 len s1 length for i 0 i len i s3 s1 substr 0 1 s1 s1 substr 1 s1 length 1 if s3 s2 s substr 0 i break if s2 length 0 s2 s s1 ss1 HtoBint s2 1 ss2 HtoBint s1 0 int in BtoDint ss1 float dou BtoDdecimal ss2 dou in dou 输出二进制形式和十进制形式 string HtoBint string s int in string s1 int len len s length string ret for int i 0 i len i s1 s substr 0 1 s s substr 1 s length 1 if in 1 ret HtoBbit s1 ret else ret HtoBbit s1 return ret 十六进制字符与二进制字符串的互相转换 string HtoBbit string s string ret if s 0 ret 0000 二进制到十六进制 string BtoHint string s int in int len s length int t len 4 len 4 t 4 while len if in 1 s 0 s else s 0 int num s length 4 i string ret for i 0 i num i string temp s substr 0 4 s s substr 4 s length 4 ret BtoHbit temp BtiHbit 函数使二进制字符串与十六进制字符互相转换 与上面相似 略写 return ret 十进制到二进制和十六进制 void DtoBH double num n2 int iExit 0 len n1 string s1 s2 s3 s4 while iExit system cls cout num len n1 int num n2 num n1 s1 DtoBdecimal n2 len s2 DtoBint n1 s3 BtoHint s2 1 s4 BtoHint s1 2 输出二进制形式和十六进制形式 十进制小数到二进制小数 string DtoBdecimal double in int len string ret double p in while len p 2 if p 1 ret 1 p 1 0 else ret 0 return ret 十进制整数到二进制整数 string DtoBint int in if in 0 return 0 string ret int q in remain while q remain q 2 q q 2 if remain ret 1 ret else ret 0 ret return ret 实验三 随机数生成 中奖者实验三 随机数生成 中奖者 实验目的及内容 生成一组均匀分布的伪随机数 根据随机数编写一个抽奖程序 实验要求 1 能够根据用户的输入 控制随机数生成的数目 随机数用动态数 组保存 2 能够根据用过的输入 控制随机数的范围 比如能够生成一组 a b 范围内的随机数 3 由用户输入抽奖者人数 N 4 为每一个人分配一个代号 类似于名字 和一个随机号码 即抽 奖票号 加你控制在 1 N 之间 并将其打印出来 5 由机器摇号 生成一个在 1 N 之间的随机数作为中奖号码 查找 中奖者 并公布中奖者信息 注 可以有多人同时中奖 6 如果没有对应的中奖者 需要将该号码公布出来 然后重新生成 一个中奖号码 知道中奖者存在为止 实验步骤及核心代码 include include include using namespace std static unsigned holdrand 1L void Lottery int n void mysrand unsigned seed int myrand void int llottery int num int n struct PEOPLE char name int number mem 100 void main cout n cout endl cout Information of all endl Lottery n void Lottery int n int i N k int num cout N mysrand unsigned time NULL for i 0 i n i k myrand k k N 1 1 mem i number k for i 0 i n i cout endl i 1 p i his number is 16 int llottery int num int i j 0 cout endl The invalid lottery number is num endl for i 0 i n i if mem i number num cout The invalid is p i his number is mem i number endl j if j 0 return 0 else return 1 实验四 插入排序 快速排序实验四 插入排序 快速排序 实验目的及内容 1 生成一组随机整数 对该组数据进行排序 采用插入排序法 2 生成一组随机整数 对该组数据尽心排序 采用快速排序法 实验要求 1 数组长度由用户输入 2 随机数范围在 100 10000 范围内 3 采用插入排序法和快速排序法进行排序 4 根据用户要求 可以实现增序 降序两种排序 实验步骤及核心代码 1 插入排序 int main 用户定义数组长度 len lottery len void lottery int len int i char ch mysrand unsigned time NULL time 函数返回 1970 年 1 月 1 日 00 00 00 起距函数 调用时相聚的时间 以秒为单位 在的头文件中 if ch 1 swap1 b len 升序 else if ch 2 swap2 b len 降序 for i 0 i len i cout b i endl void mysrand unsigned seed int myrand void 此函数在实验三里有写 h h 10000 100 100 控制随机数范围在 100 10000 之内 return h void swap1 int c int n int i j x k 1 c 0 myrand for j 1 j 0 i c i 1 x 2 快速排序 void main int A 100 n k 用户定义数组长度 int exit 0 char ch while exit for int i 0 i r return int i p int j r 1 int x a p while 1 while i r if i j break Swap Swap 函数为交换 p 与 q 的值 略写 if i j j a p a j a j x QuikUp a p j 1 QuikUp a j 1 r 实验五 模块计时器 常用排序算性能测实验五 模块计时器 常用排序算性能测 试试 实验目的及内容 设计一组计时函数 封装所有计时函数 采用测试性能函数对快速 函数 插入函数 选择排序算法进行性能测试 实验要求 1 计时精确 封装的高精度的计时 API 函数 QueryPerformanceCounter 可以达到微秒级的精度 2 使用简单 只用在待测试的模块前后加上两个宏 BM START 和 BM END 不需要对结果进行计算 也不需要考虑对各个模块结果数据 的维护 3 多组测试 最多可以同时实现 20 个模块的测试 及可以保存 20 组数据 4 结果输出独立 在系统运行结果时 只需要用一个函数就可以把 计时结果保存在一个文本文件里 5 对一组数据进行排序 6 数组长度为 10000 数组应随机产生 7 为了保证测试数据的稳定 每种排序算法运行 10 次 计算总的 时间 实验步骤及核心代码 void main int i int ret BENCHMARK MAX COUNT BENCHMARK MAX COUNT 为模块总数 InitBenchmark BMTimerStart 1 开始计时 for i 0 i 10 i sort quick a 10000 快速排序 实验四有写 略写 sort chr a 10000 插入排序 实验四有写 略写 sort choice a 10000 选择排序 略写 BMTimerEnd 1 结束计时 WriteData 1 Test1 D log txt 将数据填入文件中 void InitBenchmark ResetBenchmarkCounters 对数组 gStats gEnds gCounter 清零 GetClockFrequent 获得机器内部定时时钟频率 void BMTimerStart int iModel LARGE INTEGER litmp QueryPerformanceCounter 提高精度 在头文件 windows h 中 gStarts iModel litmp QuadPart void BMTimerEnd int iModel LARGE INTEGER litmp QueryPerformanceCounter gEnds iModel litmp QuadPart gCounters iModel gEnds iModel gStarts iModel dfFreq 1000000000 void WriteData int TotalCount string sModel string path open the file and move pointer to the end of the file 需要头文件 fstream ofstream pFile path data ios app ios out 1 Header string title s2 string sperator r n r n r n title Model sModel char temp1 100 temp2 100 sprintf temp1 r nIteration Counter 5d r n TotalCount title temp1 2 Times string s double gTotal 0 for int i 0 i BENCHMARK MAX COUNT i 将结果写进文件 if gCounters i 0 continue sprintf temp1 Total d i int len strlen temp1 8 calculate the number of t s temp1 for len 2 len s t sprintf temp2 d ms r n int gCounters i 1000 gTotal gCounters i Calculate the total ticks s temp2 char temp 100 sprintf temp Total d ms r n int gTotal 1000 s temp write entire string at one time s2 sperator title s pFile s2 pFile close void GetClockFrequent QueryPerformanceFrequency dfFreq double litmp QuadPart dfFreq 用于保存时钟频率 为全局变量 已赋初值为 1 void ResetBenchmarkCounters int i for i 0 inext p0 std p2 head if p1 NULL head next p0 p0 next NULL else while atoi p0 ID atoi p1 ID p1 p1 next if atoi p0 ID ID p2 next p0 p0 next p1 else p1 next p0 p0 next NULL return head 添加学生信息 struct student Add stu struct student stu struct student p1 int n 0 exit 0 p1 struct student malloc LEN while exit 输入学号并且判断学号是否是 4 位 不是 4 位则退出 输入学生的信息 stu insert stu p1 查询学生信息 void Inquir stu struct student stu char number 5 struct student p cin number 根据学生学号来查询学生信息 p stu do if strcmp p ID number 输出学号匹配的学生的信息 p p next while p NULL 编辑学生信息 struct student Edit stu struct student stu struct student p char number 5 cin number p stu do if strcmp p ID number 输出学生信息并且提示用户选择修改信息 char in in getch switch in 转换 in 进行选择修改信息 p p next while p NULL SYSTEM return stu 删除学生信息 struct student Delete stu struct student stu int sigh 0 exit 0 struct student p1 p2 string number p1 stu next p2 stu Print stu stu while exit 输入学生学号 if number 0000 提示所有学生信息已经删除并且使结点连接到头结点 else while p1 NULL if strcmp p1 ID number data 0 sigh 1 p2 next p1 next break else p2 p1 p1 p1 next if sigh 提示学生信息已删除并退出 elsecout 没有找到学号为 number data 的学生 请确认学号输入是 否正确 endl 实验七 实验七 文本文件 二进制文件格式的保存读取文本文件 二进制文件格式的保存读取 实验目的及内容 在上个实验的基础上对数据进行保存与读取 实验要求 1 用文本 字符 文件格式进行数据的保存与读取 2 文件的存储路径 提示用户输入 3 存盘成功后或者失败 输出提示信息 4 数据读入后能够修改保存 5 能够修改存盘及数据读取函数 添加二进制文件实现数据的保 存与读取的功能 实验步骤及核心代码 以下几个实验程序代码同上个实验的相关程序代码 struct student insert struct student head struct student std struct student Add stu struct student stu void Inquir stu struct student stu void edit name struct student p void edit score struct student p struct student Edit stu struct student stu void Print stu struct student stu struct student Delete stu struct student stu void Total stu student stu 文本文件保存 void Document Save system cls FILE fp cout filename if fp fopen filename data wt NULL cout cannot open the file next while p NULL fprintf fp s s 2f n p ID p name p score p p next fclose fp if p cout 数据已经成功保存在 filename 中 endl else cout 存盘失败 endl 文本文件读取 void Document Read system cls FILE fp string filename cout filename if fp fopen filename data rt NULL cout cannot open the file ID newnode name insert list newnode 关闭文件 二进制文件保存 void Binary Save if fp fopen filename data wb NULL cout cannot open the file next while p NULL fwrite p sizeof student 1 fp p p next fclose fp if p cout 数据已经成功保存在 filename 中 endl else cout 存盘失败 endl 二进制文件读取 void Binary Read cout filename if fp fopen filename data rb NULL cout cannot open the file endl return student newnode while 1 newnode student malloc LEN fread newnode sizeof student 1 fp if feof fp free newnode break insert list newnode 关闭文件 实验八 系统信息读取 系统操作命令实验八 系统信息读取 系统操作命令 实验目的及内容 和系统交互 读取保存在系统中的区域信息 比如日期格式 货币 符号等 掌握程序休眠 获取当前时间的方法 实验要求 1 输出当前区域设置中的日期格式 2 货币符号 3 千位分隔符 4 小数分隔符 5 日期分隔符 6 时间分隔符 7 时间制式 24 小时 or12 小时 8 使用 sleep 函数 使程序获取当前时间的方法 9 获取当前时间 格式为 星期 月 日 小时 分 秒 年份 实验步骤及核心代码 include include include ifndef TIME TDEFINED typedef long time t define TIME T DEFINED endif void main time t current time sleep 5 time printf s ctime 实验九 判断文件属性 创建文件夹实验九 判断文件属性 创建文件夹 实验目的及内容 通过系统库函数判断文件的各种属性 存在性 只读性等 学习创 建文件夹的方法 通过库函数设计一个密码程序 如同其他 DOS 程 序一样 要求输入密码并禁止回显 实验要求 1 用户输入任意一个文件名 包括路径 如 d test txt 写程 序该文件食肉存在 2 用户输入任意一个文件名 指出该文件的属性 例如不存在则创 建它 3 把以上 3 个功能集成在一个程序 提供一个用户菜单 供用户选 择测试 4 实现从控制台读入密码 并禁止回显 5 在程序中预设一个密码 8 个字符以内 将用户输入与之进行 匹配 6 用户只有 3 次机会 如果用户输入不正确 提醒输入错误 并提 醒剩下的输入次数 7 如果密码正确 则刷屏 进入用户欢迎界面 8 如果三次输入错入 退出程序 实验步骤及核心代码 1 判断文件属性 创建文件夹 判断文件是否存在 void existence system cls char document 20 cout Input the name of a document endl scanf s document if access document 0 0 cout The document exists endl else cout The document does not exist endl system pause 判断文件的属性 void attribute system cls char document 20 cout Input the name of a document endl scanf s document if access document 0 0 cout Existence only endl else if access document 2 0 cout Write permission endl else if access document 4 0 cout Read permission endl elseif access document 6 0 cout Read and write permission endl system pause 如果文件夹不存在则创建一个文件夹 void Create system cls char document 20 cout Input the name of the document endl scanf s document if access document 0 0 cout The document already exists endl else cout The document does not exist Please waite endl if mkdir document 0 cout The document now exist endl elsecout Creat fail endl system pause 2 密码输入 include include include void main char pass 10 123456 char p int t 3 p getpass Enter Password while t 0 if strcmp p pass 0 printf nWelcome n n t 0 else if t 0 return printf Password Incorrect d times left n t p getpass Enter Password 实验实验 10 视窗程序编程基础 重叠对话框 视窗程序编程基础 重叠对话框 实验目的及内容 练习 TC 提供的屏幕操作函数 并且实现美观通用的弹出式对话框进 行消息提示 实验要求 1 掌握 window clrscr textbackground textcolor 等函数功能 及使用方法 实现在屏幕中打开一个小窗口 在窗口中显示两行文 字 要求将屏幕背景设置为白色 窗口背景设置为蓝色 文字颜色 为黄色 2 为使窗口更加没换 为其绘制边框 3 实现一个对话框 为体现对话框的立体感 要求绘制其阴影 将 对话框分为上 下两部分 上部分为标题 下部分为标题栏 居中 显示对话框标题 下部分为信息栏 显示相关消息 可以有多行 要求写一个对话框函数 根据用户的输入的参数 可以显示不同的 对话框 实验步骤及核心代码 include include include static unsigned holdrand 1L void Dialog int x0 int y0 int iWidth int iRow char sTitle char information void mysrand unsigned seed holdrand seed int myrand void return holdrand holdrand 214013L 2531011L 16 void main int buf long i char c char sTitle NOTICE char information 2 This is the first text window program press any key to begin your exploration mysrand unsigned time NULL for i 0 i 600 i printf d myrand buf char malloc 10 40 2 gettext 20 10 70 20 buf printf Do you want to open the small window Y N scanf c if c Y Dialog 20 10 50 2 sTitle information 2 printf Do you want to close the small window Y N scanf c gotoxy 60 30 if c Y puttext 20 10 70 20 buf void Dialog int x0 int y0 int iWidth int iRow char sTitle char information int i j t 0 window 20 10 70 20 textbackground BLACK clrscr textcolor WHITE cprintf r n s sTitle for i 2 i 50 i gotoxy i 3 putch 205 cprintf r n s s n information 0 information 1 for i 2 i 50 i gotoxy i 1 putch 205 gotoxy i 11 putch 205 for j 2 j 11 j gotoxy 1 j putch 186 gotoxy
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年重庆师范大学招聘真题(行政管理岗)
- 七年级上第一次月考数学试卷
- 2024年海南省政协机关所属事业单位招聘真题
- 黔东南中考的数学试卷
- 青海大学专升本数学试卷
- 红细胞的功能
- 2025广西河池市都安瑶族自治县消防救援大队招聘4人笔试模拟试题及答案解析
- 宁波小升初海曙数学试卷
- 全国初中中考数学试卷
- 启东中学初二数学试卷
- 甲状腺癌病例分享
- 文化艺术活动策划与执行方案
- 意识障碍护理评估要点
- 浙江省湖州市2024-2025学年高一下学期期末考试数学试卷
- 2025至2030中国酒店用品行业产业运行态势及投资规划深度研究报告
- 2025年中国热敏标签市场调查研究报告
- 仓库不良品管理制度
- 高纯气体不锈钢管道施工方案
- 干部出国境管理课件
- VR模拟器飞行员训练评估-洞察及研究
- 生产班组考核方案
评论
0/150
提交评论