课程论文.docx
《课程论文.docx》由会员分享,可在线阅读,更多相关《课程论文.docx(33页珍藏版)》请在冰点文库上搜索。
![课程论文.docx](https://file1.bingdoc.com/fileroot1/2023-7/20/34177919-4b58-4538-8437-7d05f1a51b53/34177919-4b58-4538-8437-7d05f1a51b531.gif)
课程论文
西北农林科技大学信息工程学院面向对象编程实习报告(或论文)
题目:
超市进销管理系统
学号
2010012752
姓名
侯伟明
专业班级
电子商务101班
指导教师
聂艳明
实践日期
2010.2.20-2010.3.2
目录
一、综合训练目的与要求1
二、综合训练任务1
三、总体设计1
四、详细设计说明2
五、调试与测试4
六、实习日志10
七、实习总结10
八、附录:
核心代码清单10
一、综合训练目的与要求
根据c++面向对象编程思想,写一个超市进销管理系统,能实现超市管理的基本功能:
添加商品,修改商品信息,删除商品信息,统计商品的一系列功能,并能把添加的信息存盘。
二、综合训练任务
用C++写一个小型超市进销管理系统,能够实现商品管理的基本功能,并把文件里的信息读入内存或者把信息写入文件,主要是学会用STL内的顺序容器list和为容器定义的自己的迭代器iterator;
设计一商场商品信息管理系统,功能包括:
(1).文件操作:
可打开、保存、关闭数据文件。
(2).输入商品信息数据:
数据包括商品编号、商品名、商品类别、商品数量,商品价格等。
(3).编辑数据:
可添加、删除、修改数据。
(4).计算:
自动预计该商品的利润;
(5).查询:
可按商品编号、商品名或类别查询;
(6).浏览:
可浏览输入、查询或修改后的数据。
三、总体设计
(1)总体思路
总体是运用面向对象的编程思想,创建一个商品类,然后用一个容器以及为容积定义的迭代器,实现对商品信息的各种操作,代码包含一个类(Goods),菜单的选择用switch语句,ifstreamin("Good.txt");和ofstreamout("Good.txt")语句实现对文件数据的读出和写入,定义函数Goodssearch(stringname,list*Goodslist)Goodssearch(stringid,list*Goodslist)Goodssearch(stringcount,list*Goodslist)函数来实现信息检索及查找商品的操作,voidwrite(list*Goodslist)函数实现信息写入文件操作,voidGoods:
:
change(stringcout1)实现对商品信息的修改,istream&operator>>(istream&is,Goods&goods)和ostream&operator<<(ostream&os,Goodsgoods)实现输入输出流的重载,用容器提供的erase()函数删除指定位置的元素,有find(b,e,search_value)函数实现查找;
(2).系统结构图
四、详细设计说明
(1).代码包含一个Goods类,
商品类UML图示
代码包含一个Doods.h文件和一个operator.h文件以及Goods.cpp和main.cpp文件;
Goods.h文件中
classGoods
{
public:
Goods();
Goods(string_name,string_id,string_count,float_buy,float_sale,int_amount,float_sum);
~Goods();
voidInput();
voidShow();
voidSave();
stringgetname();
stringgetid();
stringgetcount();
voidchange(stringcout1);
boolDefine(charc);
friendistream&operator>>(istream&is,Goods&goods);
friendostream&operator<<(ostream&os,Goodsgoods);
private:
stringname;
stringid;
stringcount;
floatbuy;//进货价;
floatsale;//卖出价;
intamount;//数量;
floatsum;//利润;
};
#endif//GOODS_H
(2)operator.h文件中
voidcreat(list*Goodslist)
Goodssearch(stringname,list*Goodslist)
Goodssearch1(stringid,list*Goodslist)
voidwrite(list*Goodslist)
voidwelcom()
intMenu()
intmenu()
(3)Goods.cpp文件中(类的成员函数的定义)
类的初始化(构造函数):
Goods:
:
Goods()
{
//ctor
}
Goods:
:
Goods(string_name,string_id,string_count,float_buy,float_sale,int_amount,float_sum)
istream&operator>>(istream&is,Goods&goods)
ostream&operator<<(ostream&os,Goodsgoods)
stringGoods:
:
getname()
stringGoods:
:
getcount()
voidGoods:
:
Show()
voidGoods:
:
Input()
(4)main.cpp文件
intmain()
然后就是菜单的选择主要是通过switch()语句实现的;
五、调试与测试
(1).主界面
(2).菜单
(3).显示商品信息
(4).添加商品信息
5.查找选择菜单
1按商品名查找;
2按商品编号查找:
6.删除商品信息
7.商品信息修改界面
3修改后的商品信息
六、实习日志
2.20今天是实习的第一天,主要是认真的看了一下题目,大体为系统要实现的功能做了构思;
2.21今天是实习的第二天主要接着昨天的构思把系统要实现的功能细节化了一下,为代码所要的数据结构一类的做了具体的构造;
2.22今天把前两天的工作具体的落实了一下,在网上查阅了相关的资料写了计划实施书,把系统的功能都具体落实了一下;
2.23今天更具计划实施书把代码所要的结构大体设计了一下,更具面向对象的编程思想把类构造出来;
2.24今天主要是写代码,把主菜单设计出来,然后根据菜单的提示,把类的各个成员函数开始具体化;
2.27;今天还是写代码,写类的成员函数的,把各个函数一律开始实现;
2.28今天主要的工作还是编码,把前两天写好的各个函数组合起来;
2.29今天主要是调试代码,把写好的代码要实现的功能逐一实现,测试代吗;
3.1今天主要是完善代码,完善实验报告,并再次调试代码;
3.2今天是实习的最后一天,早晨大家都把这十天里做的东西认真的再次调试一边,下午开始做收尾工作,以及答辩。
七、实习总结
通过这次两个礼拜的实习我获益匪浅,首先,我通过这次实习发现自己在编程方面基础还比较薄弱,以后的学习中必须加强练习,那里的提高自己的编程能力;
其次,通过这次实习我的编程能力还是得到了一定的提高,在老师的指导下,同学们的帮助下,我对编程也有了自己的理解,程序设计过程有如解决一实际问题,从解决实际问题的角度,我们可以这样来看:
首先要了解这个问题的基本要求,即输入、输出、完成从输入到输出的要求是什么;
再次,从问题的要害入手,从前到后的解决问题的每个方面,即从输入开始入手,着重考虑如何从输入导出输出,在这个过程中,可确定所需的变量、类、命令、函数,然后确定处理过程--算法。
可得最后结论。
还学会了所有的容器都提供erase()函数,来删除指定位置的元素,erase有两个版本。
对list的运用有了一定得了解如:
Lists将元素按顺序储存在链表中.与向量(vectors)相比,它允许快速的插入和删除,但是随机访问却比较慢.assign()给list赋值,back()返回最后一个元素,begin()返回指向第一个元素的迭代器,clear()删除所有元素,empty()如果list是空的则返回true,end()返回末尾的迭代器,erase()删除一个元素,front()返回第一个元素,get_allocator()返回list的配置器,insert()插入一个元素到list中,max_size()返回list能容纳的最大元素数量,merge()合并两个list,pop_back()删除最后一个元素,pop_front()删除第一个元素,push_back()在list的末尾添加一个元素,push_front()在list的头部添加一个元素,rbegin()返回指向第一个元素的逆向迭代器,remove()从list删除元素,remove_if()按指定条件删除元素,rend()指向list末尾的逆向迭代器,resize()改变list的大小,reverse()把list的元素倒转,size()返回list中的元素个数,sort()给list排序,splice()合并两个list,swap()交换两个list,unique()删除list中重复的元素
通过此次的课程设计,我基本上了解并掌握数面向对象的编程的设计方法,具备了初步的独立分析和设计能力和初步掌握软件开发过程的问题分析、系统设计、程序编码、测试等基本方法和技能。
同时在和同学的交流中也发现了很多不同的算法,以及各种新颖的想法。
这大大拓宽了自己在编程方面的思路,为以后在编程学习中积累了一些经验。
八、附录:
核心代码清单
<1>Goods.h
#ifndefGOODS_H
#defineGOODS_H
#include
#include
#include
#include
#include
#include
usingnamespacestd;
classGoods
{
public:
Goods();
Goods(string_name,string_id,string_count,float_buy,float_sale,int_amount,float_sum);
~Goods();
voidInput();
voidShow();
voidSave();
stringgetname();
stringgetid();
stringgetcount();
voidchange(stringcout1);
doubleSell(intnum);//出售商品,减少本商品的存量同时返回出售商品的总价,失败返回-1
doubleBuy(intnum);//购买商品,减少本商品的存量同时返回购买商品的总价
boolDefine(charc);
friendistream&operator>>(istream&is,Goods&goods);
friendostream&operator<<(ostream&os,Goodsgoods);
private:
stringname;
stringid;
stringcount;
floatbuy;//进货价;
floatsale;//卖出价;
intamount;//数量;
floatsum;//利润;
floataccount;
};
#endif//GOODS_H
<2>operator.h
#ifndefOPERATE_H_INCLUDED
#defineOPERATE_H_INCLUDED
#include"Goods.h"
#include"dos.h"
#include
#include
#include
voidcreat(list*Goodslist)
{
Goodsgoods;
list:
:
iteratorit;
ifstreamin("Good.txt");
assert(in);
while(in>>goods)
{
Goodslist->push_back(goods);
}
in.close();
}
Goodssearch(stringname,list*Goodslist)
{
list:
:
iteratorit;
Goodsgoods("oooo","qqqq","ni",23,23,23,23);
for(it=Goodslist->begin();it!
=Goodslist->end();++it)
{
if(name==it->getname())
{
goods=(*it);
it=Goodslist->erase(it);
break;
}
}
returngoods;
}
Goodssearch1(stringid,list*Goodslist)
{
list:
:
iteratorit;
Goodsgoods;
for(it=Goodslist->begin();it!
=Goodslist->end();++it)
{
if(id==it->getid())
{
goods=(*it);
it=Goodslist->erase(it);
break;
}
}
returngoods;
}
Goodssearch2(stringcount,list*Goodslist)
{
list:
:
iteratorit;
Goodsgoods("oooo","qqqq","ni",23,23,23,23);
for(it=Goodslist->begin();it!
=Goodslist->end();++it)
{
if(count==it->getcount())
{
goods=(*it);
it=Goodslist->erase(it);
break;
}
}
returngoods;
}
voidwrite(list*Goodslist)
{
list:
:
iteratorit;
//Goodsgoods;
ofstreamout("Good.txt");
assert(out);
it=Goodslist->begin();
while(it!
=Goodslist->end())
{
out<front();
it++;
Goodslist->pop_front();
}
out.close();
}
voidwelcom()
{
charch;
system("cls");
cout<<"\n";
time_tt=time(0);
chartmp[64];
strftime(tmp,sizeof(tmp),"\t\t%Y/%m/%d%X%A本年第%j天%z",localtime(&t));
puts(tmp);
cout<<"\t\t*****************************************************\n"<cout<<"\t\t*☆☆§☆☆☆☆☆§☆☆☆☆☆☆§☆☆☆☆☆☆☆§☆☆*\n"<cout<<"\t\t* ↓ ↓ ↓ ↓*\n"<cout<<"\t\t* ☆★☆ ☆★☆ ☆★☆ ☆★☆*\n"<cout<<"\t\t**\n"<cout<<"\t\t* 感 谢 使 用 *\n"<cout<<"\t\t**\n"<cout<<"\t\t*☆★☆ ☆★☆ ☆★☆ ☆★☆*\n"<cout<<"\t\t* ↓ ↓ ↓ ↓*\n"<cout<<"\t\t*☆☆§☆☆☆☆☆§☆☆☆☆☆☆§☆☆☆☆☆☆☆§☆☆*\n"<cout<<"\t\t****************************************************"<cout<<"\n";
ch=getch();
}
intMenu()
{
intch=0;
cout<<"\n";
cout<<"\n";
time_tt=time(0);
chartmp[64];
strftime(tmp,sizeof(tmp),"\t\t%Y/%m/%d%X%A本年第%j天%z",localtime(&t));
puts(tmp);
cout<<"\t\t════╤════════════════╗\n"<cout<<"\t\t1增加超市商品(addition)\n"<cout<<"\t\t2显示超市商品(display)\n"<cout<<"\t\t3查找统计商品(search)\n"<cout<<"\t\t4删除超市商品(delete)\n"<cout<<"\t\t5修改超市商品(modify)\n"<cout<<"\t\t0安全退出系统(exit)\n"<cout<<"\t\t╚═══╧════════════════╝\n"<cout<<"\t\t请选择操作:
";
cin>>ch;
system("cls");
returnch;
}
intmenu()
{
inth=0;
cout<<"\n";
cout<<"\n";
time_tt=time(0);
chartmp[64];
strftime(tmp,sizeof(tmp),"\t\t%Y/%m/%d%X%A本年第%j天%z",localtime(&t));
puts(tmp);
cout<<"\t\t════╤════════════════╗\n"<cout<<"\t\t1修改商品名(name)\n"<cout<<"\t\t2修改编号(id)\n"<cout<<"\t\t3修改商品类别(count)\n"<cout<<"\t\t0安全退出系统(exit)\n"<cout<<"\t\t╚═══╧════════════════╝\n"<cout<<"\t\t请选择操作:
"<cin>>h;
returnh;
}
#endif//OPERATE_H_INCLUDED
<3>Goods.cpp
#include"Goods.h"
Goods:
:
Goods()
{
//ctor
}
Goods:
:
Goods(string_name,string_id,string_count,float_buy,float_sale,int_amount,float_sum)
{
name=_name;
id=_id;
count=_count;
buy=_buy;
sale=_sale;
amount=_amount;
sum=_sum;
}
istream&operator>>(istream&is,Goods&goods)
{
returnis>>goods.name>>goods.id>>goods.count>>goods.buy>>goods.sale>>goods.amount;
}
ostream&operator<<(ostream&os,Goodsgoods)
{
returnos<}
stringGoods:
:
getname()
{
returnname;
}
stringGoods:
:
getid()
{
returnid;
}
stringGoods:
:
getcount()
{
returncount;
}
Goods:
:
~Goods()
{
//dtor
}
voidGoods:
:
Show()
{
sum=(sale-buy)*amount;
cout<<"商品名称:
"<cout<<"商品编号:
"<cout<<"商品类别:
"<cout<<"商品进价:
"<cout<<"商品售价:
"<cout<<"商品数量:
"<cout<<"预计利润:
"<cout<<"\n"<}
voidGoods:
:
Input()
{
cout<<"商品名称:
";
cin>>name;
cout<<"商品编号:
";
cin>>id;
cout<<"商品类别:
";
cin>>count;
cout<<"商品进价:
";
cin>>buy;
cout<<"商品售价:
";
cin>>sale;
cout<<"商品数量:
";
cin>>amount;
sum=(sale-buy)*amount;
}
voidGoods:
:
change(stringcout1)
{