ProductManager

本文介绍了一个简单商品管理系统的实现,包括产品和交易记录的类定义、管理功能如添加新品种、记录销售过程等,并展示了如何通过命令行界面进行交互操作。
/*
*File:Product.h
*Author:88250
*
*CreatedonMay2,2008,5:51PM
*/

#ifndef_PRODUCT_H
#define_PRODUCT_H

#include
<string>

classProduct{
public:

Product(std::stringproductName){
name
=productName;
}

std::stringname;
};

#endif
/*_PRODUCT_H*/


/*
*File:RecordRow.h
*Author:88250
*
*CreatedonMay2,2008,5:54PM
*/


#ifndef_RECORDROW_H
#define_RECORDROW_H

#include
<string>

classRecordRow{
public:

RecordRow(std::
stringn,std::stringdir,intam,floatp,intm,intd){
name
=n;
direction
=dir;
amount
=am;
price
=p;
month
=m;
day
=d;
}

std::
stringname;
std::
stringdirection;
intamount;
floatprice;
intmonth;
intday;
};


#endif/*_RECORDROW_H*/


/**//*
*File:ProductManager.h
*Author:88250
*
*CreatedonMay2,2008,5:57PM
*/


#ifndef_PRODUCTMANAGER_H
#define_PRODUCTMANAGER_H

#include
<vector>

#include
"Product.h"
#include
"RecordRow.h"

usingnamespacestd;

classProductManager...{
public:
voidinit();
voidsaveProduct(std::vector<Product>products);
voidreadProduct(std::vector<Product>&products);
voidsaveRecord(std::vector<RecordRow>records);
voidreadRecord(std::vector<RecordRow>&records);
voidnewProduct(stringname);
voidnewRecord(RecordRowrr);
voiddisplayName(void);
voiddisplayRecords(void);
voiddisplayStat(intproductNum,intstartM,intendM,intstartD,intendD);
voiddisplayAllStat(intstartM,intendM,intstartD,intendD);
vector
<Product>productVector;
vector
<RecordRow>recordVector;
private:
vector
<RecordRow>getRRByName(stringname,vector<RecordRow>rrs);
vector
<string>getNames(vector<RecordRow>rrs);
boolcontainsName(vector<string>names,stringname);
voiddisplayAProduct(vector<RecordRow>rr,float&mao,float&chun);
}
;

#endif/*_PRODUCTMANAGER_H*/


/*
*File:ProductManager.cpp
*Author:88250
*
*CreatedonMay2,2008,7:7PM
*/

#include
"ProductManager.h"

#include
<vector>
#include
<string>
#include
<fstream>
#include
<iostream>

usingnamespacestd;

voidProductManager::displayAllStat(intstartM,intendM,intstarD,intendD){
vector
<RecordRow>rrs;
for(inti=0;i<recordVector.size();i++){
RecordRowrr
=recordVector[i];
if(rr.month>startM&&rr.month<endM){
rrs.push_back(rr);
continue;
}
if(rr.month==startM||rr.month==endM){
if(rr.day>=starD&&rr.day<=endD){
rrs.push_back(rr);
}
}
}

vector
<string>names=getNames(rrs);
vector
<vector<RecordRow>>rrss;
for(inti=0;i<names.size();i++){
rrss.push_back(getRRByName(names[i],rrs));
}
cout
<<"品种 "<<"进总数 "<<"出总数 "<<"进总价 "
<<"出总价 "<<"阶段利润 "<<"总金额流量"<<endl;
floatmao=0.0;//毛利
floatchun=0.0;//纯利

for(inti=0;i<rrss.size();i++){
displayAProduct(rrss[i],mao,chun);
}

cout
<<"当前的总毛收入:"<<mao<<endl;
cout
<<"当前的总纯收入:"<<chun<<endl;
cout
<<endl;

}

voidProductManager::displayStat(intproductNum,
intstartM,intendM,intstarD,intendD){
vector
<RecordRow>rrs;
for(inti=0;i<recordVector.size();i++){
RecordRowrr
=recordVector[i];
if(rr.name==productVector[productNum].name){
if(rr.month>startM&&rr.month<endM){
rrs.push_back(rr);
continue;
}
if(rr.month==startM||rr.month==endM){
if(rr.day>=starD&&rr.day<=endD){
rrs.push_back(rr);
}
}
}
}

cout
<<"品种 "<<"进总数 "<<"出总数 "<<"进总价 "
<<"出总价 "<<"阶段利润 "<<"总金额流量"<<endl;

floatmao=0.0;
floatchun=0.0;
displayAProduct(rrs,mao,chun);

cout
<<"当前的总毛收入:"<<mao<<endl;
cout
<<"当前的总纯收入:"<<chun<<endl;
cout
<<endl;
}

voidProductManager::displayAProduct(vector<RecordRow>rr,
float&mao,float&chun){
intiam=0;
intoam=0;
floatip=0.0;
floatop=0.0;
floatpro=0.0;
floatppro=0.0;
floatiavg=0.0;
intinum=0;
if(rr[0].name.length()>=8){
cout
<<rr[0].name<<" ";
}
else{
cout
<<rr[0].name<<" ";
}

for(inti=0;i<rr.size();i++){
if(rr[i].direction==""){
iam
+=rr[i].amount;
iavg
+=rr[i].price;
ip
+=rr[i].amount*rr[i].price;
inum
++;
}
else{
oam
+=rr[i].amount;
op
+=rr[i].amount*rr[i].price;
}
}
iavg
=iavg/inum;
pro
=op-ip;
ppro
=op-oam*iavg;
cout
<<iam<<" "<<oam<<" "<<ip<<" "<<op<<" "
<<ppro<<" "<<pro<<" "<<endl;

chun
+=ppro;
mao
+=op;
}

vector
<RecordRow>ProductManager::getRRByName(stringname,
vector
<RecordRow>rrs){
vector
<RecordRow>ret;
for(inti=0;i<rrs.size();i++){
if(rrs[i].name==name){
ret.push_back(rrs[i]);
}
}
returnret;
}

vector
<string>ProductManager::getNames(vector<RecordRow>rrs){
vector
<string>ret;

for(inti=0;i<rrs.size();i++){
if(!containsName(ret,rrs[i].name)){
ret.push_back(rrs[i].name);
}
}
returnret;
}

boolProductManager::containsName(vector<string>names,stringname){
for(inti=0;i<names.size();i++){
if(names[i]==name){
returntrue;
}
}
returnfalse;
}

voidProductManager::init(){
std::vector
<Product>products;
readProduct(products);
productVector
=products;

std::vector
<RecordRow>rrs;
readRecord(rrs);
recordVector
=rrs;
}

voidProductManager::newProduct(stringname){
vector
<Product>::iteratori;
boolisExisted=false;
for(i=productVector.begin();i!=productVector.end();i++){
if((*i).name==name){
isExisted
=true;
}
}
if(!isExisted){
productVector.push_back(Product(name));
}
saveProduct(productVector);
}

voidProductManager::newRecord(RecordRowrr){
recordVector.push_back(rr);
saveRecord(recordVector);
}

voidProductManager::displayName(void){
for(inti=0;i<productVector.size();i++){
cout
<<i<<"."<<productVector[i].name<<endl;
}
cout
<<endl;
}

voidProductManager::displayRecords(void){
if(!recordVector.empty()){
cout
<<"品种 "<<"流向 "<<"数量 "<<"单价 "<<"日期"<<endl;
for(inti=0;i<recordVector.size();i++){
if(recordVector[i].name.length()>=8){
cout
<<recordVector[i].name<<" "<<recordVector[i].direction<<" "
<<recordVector[i].amount<<" "<<recordVector[i].price
<<" "<<recordVector[i].month<<"-"<<recordVector[i].day
<<endl;
}
else{
cout
<<recordVector[i].name<<" "<<recordVector[i].direction<<" "
<<recordVector[i].amount<<" "<<recordVector[i].price
<<" "<<recordVector[i].month<<"-"<<recordVector[i].day
<<endl;
}
}
cout
<<endl;
}
}

voidProductManager::saveProduct(std::vector<Product>products){
ofstreamfout(
"name");

if(!fout){
cout
<<"Cannotopenoutputfile! ";
return;
}

for(inti=0;i<products.size();i++){
fout
<<products[i].name<<endl;
}

fout.close();
}

voidProductManager::saveRecord(std::vector<RecordRow>records){
ofstreamfout(
"data");

if(!fout){
cout
<<"Cannotopenoutputfile! ";
return;
}

for(inti=0;i<records.size();i++){
fout
<<"Record"<<endl
<<records[i].name<<endl
<<records[i].direction<<endl
<<records[i].amount<<endl
<<records[i].price<<endl
<<records[i].month<<endl
<<records[i].day<<endl;
}

fout.close();
}

voidProductManager::readProduct(std::vector<Product>&products){
ifstreamfin(
"name");

if(!fin){
cout
<<"Cannotopeninputfile! ";
return;
}

stringaLine;
while(getline(fin,aLine)){
products.push_back(Product(aLine));
}

fin.close();
}

voidProductManager::readRecord(std::vector<RecordRow>&records){
ifstreamfin(
"data");

if(!fin){
cout
<<"Cannotopeninputfile! ";
return;
}

stringaLine;
while(getline(fin,aLine)){
stringn,dir;
intam,m,d;
floatpr;

if(aLine.at(0)=='R'){
getline(fin,aLine);
n
=aLine;
getline(fin,aLine);
dir
=aLine;
getline(fin,aLine);
am
=atoi(aLine.c_str());
getline(fin,aLine);
pr
=atof(aLine.c_str());
getline(fin,aLine);
m
=atoi(aLine.c_str());
getline(fin,aLine);
d
=atoi(aLine.c_str());
records.push_back(RecordRow(n,dir,am,pr,m,d));
}
}

fin.close();
}

/*
*File:Main.cpp
*Author:88250
*
*CreatedonMay2,2008,9:36PM
*/

#include
"ProductManager.h"

#include
<iostream>

usingnamespacestd;

intmain(intargc,char**argv){
ProductManagerpm;
pm.init();

intinput;
intnum=0;
stringname;
intamount=0;
floatprice=0.0;
intmonth=1;
intday=1;
intdir=1;
intsm=1;
intsd=1;
intem=2;
inted=1;
intpn=0;
stringd;
charconfirm='n';
while(true){
cout
<<"1.查看现有品种"<<endl;
cout
<<"2.增加新品种"<<endl;
cout
<<"3.添加销售记录"<<endl;
cout
<<"4.查看所有销售记录"<<endl;
cout
<<"5.统计帐目"<<endl;

cout
<<"请选择:"<<"";
cin
>>input;

switch(input){
case1:
pm.displayName();
break;
case2:
cout
<<"请输入品种名称(111返回):"<<"";
cin
>>name;
if(name=="111"){
break;
}
pm.newProduct(name);
cout
<<"新建品种成功!"<<endl;
break;
case3:
pm.displayName();

cout
<<"请输入产品编号(111返回):";
cin
>>num;
if(num==111){
break;
}
if(num>=0&&num<=pm.productVector.size()){
name
=pm.productVector[num].name;
}
else{
cout
<<"输入有误!";
break;
}
cout
<<"请选择流向(1.进;2.出):";
cin
>>dir;
if(dir==1){
d
="";
cout
<<"请输入进货数量:";
cin
>>amount;
cout
<<"请输入进货单价:";
cin
>>price;

cout
<<"请输入进货月:";
cin
>>month;

cout
<<"请输入进货日:";
cin
>>day;
}
elseif(dir==2){
d
="";
cout
<<"请输入卖出数量:";
cin
>>amount;

cout
<<"请输入卖出单价:";
cin
>>price;

cout
<<"请输入销售月:";
cin
>>month;

cout
<<"请输入销售日:";
cin
>>day;
}
else{
cout
<<"输入有误!";
break;
}

cout
<<"确定?(y.确定n.放弃)"<<endl;
cin
>>confirm;
if(confirm=='y'){
pm.newRecord(RecordRow(name,d,amount,price,month,day));
}
break;
case4:
pm.displayRecords();
break;
case5:
cout
<<"开始月(111返回):";
cin
>>sm;
if(sm==111){
break;
}

cout
<<"开始日:";
cin
>>sd;

cout
<<"结束月:";
cin
>>em;

cout
<<"结束日:";
cin
>>ed;

cout
<<"请选择统计方式(1.单项品种2.所有品种):";
cin
>>num;
if(num==1){
pm.displayName();
cout
<<"请输入产品编号:";
cin
>>pn;
pm.displayStat(pn,sm,em,sd,ed);
}
elseif(num==2){
pm.displayAllStat(sm,em,sd,ed);
}
else{
cout
<<"选择有误,返回!"<<endl;
}
break;
default:
cout
<<"选择有误!"<<endl;
}


}

return(EXIT_SUCCESS);
}

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值