ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:509.89KB ,
资源ID:9443017      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9443017.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(中南大学 c++课设报告.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

中南大学 c++课设报告.docx

1、中南大学 c+课设报告中南大学面向对象编程(C+)实验报告学生姓名 郁博文 学 院 信息科学与工程学院 专业班级 信息安全1302班 完成时间 2014年6月28日 目 录1.实验内容 22.实验1 32.1 设计思路 32.2 实验过程 33.实验2 33.1 设计思路 33.3 实验过程 34.实验3 34.1 设计思路 34.2 实验过程 35.总结 3面向对象编程(C+)1.实验内容实验1:构建一个类。实验2:编写一个糖果机的系统,能够实现购买糖果、付款、找零等功能。实验3:编写一个程序,能够根据输入的学生信息,自动生成成绩报告。2.实验1:类与对象 2.1 设计思路构建一个学生类,进

2、行初始化,输入学生学号和姓名信息,输出信息。2.2 实验过程3.实验2 :糖果机3.1 设计思路 构建三个类,并且初始化这三个类,构造函数使其实现投币、找零、显示商品等功能,然后设计欢迎界面。欢迎界面会显示商品名称及价格, 用户投币后可以购买商品(可重复投币)。选择所需商品后,自动找零退出。3.3 实验过程4.实验3 :成绩报告4.1 设计思路 构建一个学生类,一个课程类,通过函数,输入学生姓名、学号、课程数目等信息,输出成绩报告。如果未缴纳学费,将不显示成绩报告。4.2 实验过程5.总结实验一是在刚刚接触类和对象时编写的,是个非常简单的程序,但是正是通过这个程序,我开始接触面向对象的编程。实

3、验二是编写一个糖果机,本来应该实现连续购买的功能,但多次调试仍然直接跳过了那段else语句,至今没有找到错误在哪。实验三编写得很艰难,之前没接触过文件方面的内容,所以没有做到直接读取txt文档后输出结果。通过这几次实验,我发现了自身的不足,比如没有很好的书写习惯,考虑问题不周到,对于面相对象的理解不够深入等。但在编程的过程中我体验到了一分耕耘一分收获的喜悦;多次调试后程序成功运行了,那时候的欢乐是我以前无法想象的。果然,学习任何一门课程,只要学得用心,都可以从中体会到学习的快乐。今后我的进步,想必都是从这一点一点敲入编译器的代码中获得的。6.代码附录实验1:类和对象头文件:#includeus

4、ing namespace std;class studentprivate: int num; char name10;public: void setdata() cin num; cin name; void display() cout num endl; cout name endl; ;student student1, student2;源文件:#include001.hint main() cout 请输入两位学生的学号和姓名: endl; student1.setdata(); student2.setdata(); cout 学生的信息: endl; student1.di

5、splay(); student2.display(); return 0;实验2:糖果机头文件:#include #include using namespace std;class moneycounterpublic: moneycounter() :input_money(0.0f) moneycounter() void getgukemoney(); float money_from_buyer(); void clear(); void return_money(float);private: float input_money;class goodsinfopublic: go

6、odsinfo() :name(), price(0.0f), total(0) goodsinfo() void set_goods(string, float, int); string goods_name(); float goods_price(); int goods_number();private: string name; float price; int total;class candymachinepublic: candymachine(); candymachine() void showchoices(); void inputmoney(); bool good

7、sitem(int); void return_allmoney();private: moneycounter moneyctr; goodsinfo v_goods5;void moneycounter:getgukemoney() float money; cout endl 请投入钱币。 money; input_money += money; cout endl 您投入的金额是 input_money 元。 endl; return;float moneycounter:money_from_buyer() return input_money;void moneycounter:c

8、lear() input_money = 0.0f; return;void moneycounter:return_money(float change) cout endl 找零 change 元。 endl;void goodsinfo:set_goods(string n, float p, int num) name = n; price = p; total = num;string goodsinfo:goods_name() return name;float goodsinfo:goods_price() return price;int goodsinfo:goods_nu

9、mber() return total;candymachine:candymachine() v_goods0.set_goods(薯片, 3, 20); v_goods1.set_goods(巧克力, 5, 0); v_goods2.set_goods(口香糖, 1.5, 20); v_goods3.set_goods(牛轧糖, 2, 30); v_goods4.set_goods(水果糖, 2, 28); return;void candymachine:showchoices() cout.precision(2); cout.setf(ios:fixed); cout endl 您投

10、入的金额是 moneyctr.money_from_buyer() 元。 endl; cout endl 请选择商品代码 endl; for (int i = 0; i5; i+) cout i v_goodsi.goods_name() v_goodsi.goods_price() 元 endl; cout 5 退款并且退出 endl; return;void candymachine:inputmoney() cout endl 本机只接受10元、5元、2元、1元和0.5元的纸币和硬币。 0) if (moneyctr.money_from_buyer() = v_goodsselect.

11、goods_price() float change = moneyctr.money_from_buyer() - v_goodsselect.goods_price(); cout endl 您选择的是 v_goodsselect.goods_name() ,请在出口处拿取。 0) moneyctr.return_money(change); return true; else cout endl 您投入的金额不足! endl; else cout endl 您选择的饮料已售完! endl; return false;void candymachine:return_allmoney()

12、cout endl 退款 moneyctr.money_from_buyer() 元。 endl; return;源文件:#include 标头.h#includevoid main() system(COLOR b0); candymachine candy; string buf; bool go_on(true), cash_on(true), got_it(true); cout endl =欢迎光临糖果甜心售货机= endl endl; cout 价目表如下 endl; cout 薯片 3.00元 endl 巧克力 5.00元 endl 口香糖 1.50元 endl 牛轧糖 2.00

13、元 endl 水果糖 2.00元 endl; while (go_on) while (cash_on) candy.inputmoney(); cout endl buf; if (buf = n | buf = no) cash_on = false; candy.showchoices(); cin buf; int select = atoi(buf.c_str(); if (select = 5) candy.return_allmoney(); go_on = false; else got_it = candy.goodsitem(select); if (got_it) go_

14、on = false; cout endl 谢谢光临,欢迎下次再来哦! endl endl;实验3:学生成绩报告头文件:#include#includecourse.h#includeusing namespace std;class Studentpublic: string name; string xuehao; float average; float sum; float zongxuefei; float zong; int choose; Course a5; float xuefei5; Student(); void setdata(); /void sort(); /voi

15、d show();class Courseprivate: string name; int id; int p;public: float xuefen; float money; float mark; void set_data(string, int, float, float); void display();源文件:#include#include#includestudent.h#include#includeusing namespace std;Student:Student() for (int i = 0; i5; i+) ai.mark = 0; xuefeii = 8

16、00; zong = 0; zongxuefei = 0; choose = 0; sum = 0;void Student:setdata() cout name; cout xuehao;void Course:set_data(string n, int i, float x, float m) name = n; id = i; xuefen = x; money = m;void Course:display() cout 课程名称 t 编号 t 学分 t 学费 endl; cout name t t id t xuefen t money endl endl;int main()

17、system(color 0a); int s; int count=0; Course b5; b0.set_data(高数,1,5,400); b1.set_data(英语,2,2,200); b2.set_data(语文,3,2,300); b3.set_data(物理,4,3,400); b4.set_data(电路,5,2,100); star: cout*endl; cout 1 显示课程信息endl; cout 2 录入学生信息endl; cout*endl; int m; coutm; system(cls); switch(m) case 1:for(int i=0;i5;i

18、+) bi.display(); getch(); system(cls); goto star; case 2: for(int i=0;i5;i+) bi.display(); couts; Student *pt=new Students; for(int i=0;is;i+) pti.setdata(); coutendl; int c; do int n; int k; coutk; n=k-1; pti.an=bk-1; coutpti.an.mark; coutendl; pti.sum+=pti.an.mark; cout请缴纳bk-1.money学费pti.xuefein;

19、if(pti.xuefeinbk-1.money)pti.an.mark=0; pti.zong+=pti.an.xuefen; pti.zongxuefei+=pti.an.money; pti.choose+; coutc; while(c=1); pti.average=pti.sum/pti.choose; system(cls); cout学生分数报告如下:endl; cout姓名t学号t高数t英语t语文t物理t电路t总学费t总学分t平均成绩endl; for(int i=0;is;i+) coutpti.nametpti.xuehaot;/tpti.a0.marktpti.a1.marktpti.a2.marktpti.a3.marktpti.a4.marktpti.zongxuefeitpti.zongtpti.averageendl; for(int j=0;j5;j+) if(pti.xuefeij=bj.money)coutpti.aj.markt; else if(pti.xuefeijbj.money) cout未交费t; else cout未选t; coutpti.zongxuefeitpti.zongtpti.average; coutendl; getch(); system(cls); goto star; return 0;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1