商店货物管理系统
来源:互联网 发布:java中 get set方法和f 编辑:程序博客网 时间:2024/06/10 13:05
商店经销一种货物,货物成箱购进,成箱卖出,购进和卖出时以重量为单位,各箱的重量不一样,单价不一样,因此商店需要记录下目前库存的货物的总重量和总价值。编写一个程序,通过定义类Carlo来模拟商店货物购进和卖出的情况。
//Menu.h
#ifndef MENU_H
#define MENU_H
class Menu
{public:
int show();
};
#endif;
// Carlo.h
class Carlo
{public:
Carlo(double Weight = 0,double Price = 0);
virtual ~Carlo();
void SetCarlo(double = 0,double = 0);
const double &GetCurrentTotalWeight() const;
const double &GetCurrentTotalPrice() const;
void BuyBox();
void SellBox();
void ShowBoxInfor() const;
protected:
static double TotalWeight;
static double TotalPrice;
private:
double BoxWeight;
double BoxPrice;
};
//Carlo.cpp
#include <iostream>
#include "Carlo.h"
using namespace std;
double Carlo::TotalPrice=0.0;
double Carlo::TotalWeight=0.0;
Carlo::Carlo(double Weight, double Price)
{ BoxWeight = Weight;
BoxPrice = Price;
TotalPrice += Weight * Price;
TotalWeight += Weight;
}
void Carlo::BuyBox()
{ system("cls");
Carlo carlo;
double Weight , Price;
cout<<"请输入进货的重量和价格:";
cin>>Weight>>Price;
carlo.SetCarlo(Weight,Price);
}
const double &Carlo::GetCurrentTotalPrice() const
{ return TotalPrice;
}
const double &Carlo::GetCurrentTotalWeight() const
{ return TotalWeight;
}
void Carlo::SetCarlo(double Weight, double Price)
{ BoxWeight = Weight;
BoxPrice = Price;
TotalPrice += Weight * Price;
TotalWeight += Weight;
}
void Carlo::SellBox()
{ system("cls");
double Weight,Price;
cout<<"输入出货的重量和单价:";
cin>>Weight>>Price;
while (Weight < 0 || Price < 0)
{ cout<<"参数不对,请重新输入:";
cin>>Weight>>Price;
}
if ((Weight * Price > TotalPrice) || Weight > TotalWeight
|| TotalPrice < 0)
{cout<<"存货不够!";
cin.get();
cin.get();
}
else
{ TotalPrice -= Weight * Price;
TotalWeight -= Weight;
cout<<"出货完成!";
cin.get();
cin.get();
}
}
void Carlo::ShowBoxInfor() const
{system("cls");
cout<<"库中的存货总重量为:";
cout.precision(6);
cout.setf(ios_base::showpoint);
cout<<GetCurrentTotalWeight()<<endl;
cout<<"库中的存货总价钱为:";
cout.precision(6);
cout<<GetCurrentTotalPrice();
cin.get();
cin.get();
}
Carlo::~Carlo()
{
}
//Menu.cpp
#include <iostream>
#include <windows.h>
#include "Menu.h"
using namespace std;
int Menu::show()
{ system("cls");
int chioce;
cout<<"/n/n/n/n/n/t/t/t"<<"/>/>/>";
cout<<"进出货演示"<<"/</</<"<<endl<<endl;
cout<<"/t/t/t"<<"1.进货登记."<<endl<<endl;
cout<<"/t/t/t"<<"2.出货登记."<<endl<<endl;
cout<<"/t/t/t"<<"3.获取库存信息."<<endl<<endl;
cout<<"/t/t/t"<<"4.退出."<<endl<<endl;
cout<<"/t/t/t"<<"请选择操作:";
cin>>chioce;
return (chioce);
}
//CarloDemo.cpp
#include <iostream>
#include "Menu.h"
#include "Carlo.h"
using namespace std;
void main()
{ Menu menu;
Carlo carlo;
int chioce;
while( (chioce = menu.show()) - 4)
{ switch(chioce)
{ case 1: carlo.BuyBox();
break;
case 2: carlo.SellBox();
break;
case 3: carlo.ShowBoxInfor();
break;
}
}
}
运行结果:
1.进货登记.
2.出货登记.
3.获取库存信息."
4.退出.
请选择操作: 1
请输入进货的重量和价格:20 1
1.进货登记.
2.出货登记.
3.获取库存信息."
4.退出.
请选择操作: 2
请输入出货的重量和价格:10 1
出货成功!
1.进货登记.
2.出货登记.
3.获取库存信息."
4.退出.
请选择操作: 3
库中的存货总重量为:10,0000
库中的存货总价钱为:10,0000
- 商店货物管理系统
- 进销存货物管理系统 论文
- 商店商品管理系统
- 商店管理系统代码
- 货物管理系统(数据结构顺序表)
- 货物管理系统(数据结构链式表)
- 货物管理
- 货物管理
- 商店进存销管理系统C++
- 商店管理系统源代码(一)
- 商店管理系统源代码(二)
- 商店管理系统源代码(三)
- 商店管理系统源代码(四)
- 商店管理系统源代码(五)
- 商店管理系统源代码(六)
- 商店管理系统源代码(七)
- 商店管理系统源代码(八)
- 商店管理系统源代码(九)
- 团队介绍
- 在DOS运行有包的java文件
- 架构设计学习
- 改变
- 索引在数据库中的应用分析
- 商店货物管理系统
- 火箭残骸有些吓人啊?
- 世界上最远的距离
- 理想
- 关于对使用类实现C++指针功能性能打折扣的反驳
- 思念
- div+css - !important规则
- 第一篇
- 一段经典C代码分析