OJ积累--商品销售
2015-06-19 16:58
225 查看
/* *copyright (c)2015,烟台大学计算机学院 *All rights reserved *文件名称:project.cpp *作者:孙春红 *完成日期:2015年6月18日 *版本号:v1.0 * *问题描述: 店销售某一商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此基础上,一次购10件以上者,还可以享受9.8折优惠。现已知当天m个销货员销售情况为 销货员号(num) 销货件数(quantity) 销货单价(price) 101 5 23.5 102 12 24.56 103 100 21.5 请编写程序,计算出当日此商品的总销售款sum以及每件商品的平均售价。要求用静态数据成员和静态成员函数。 (提示: 将折扣discount,总销售款sum和商品销售总件数n声明为静态数据成员,再定义静态成员函数average(求平均售价)和display(输出结果)。 *输入描述:m和m个销货员销售情况。 *程序输出:总销售款sum以及每件商品的平均售价 */ #include <iostream> #include <iomanip> #include <cstring> using namespace std; class Product { private: int name; int quantitys; float prices; static float sum; static float discount; static int n; public: Product () {} Product(int n,int q,float p):name(n),quantitys(q),prices(p) {} void total(); static double average(); static void display(); }; float Product::discount=0.05; float Product::sum=0; int Product::n=0; void Product::total() { if (quantitys>=10) { prices=prices*0.98; } sum+=quantitys*prices*(1-discount); n+=quantitys; } double Product::average() { return (sum/n); } void Product::display() { cout<<sum<<" "<<average(); } int main() { const int NUM =10; Product Prod[NUM]; int m,i; cin>>m; int num; int quantity; float price; for(i=0; i<m; i++) { cin>>num>>quantity>>price; Product temp(num,quantity,price); Prod[i]=temp; } for(i=0; i<m; i++) Prod[i].total(); cout<<setiosflags(ios::fixed); cout<<setprecision(2); Product::display(); return 0; }
运行结果:
相关文章推荐
- 查看树莓派的CPU温度
- Android的第二次增加SurfaceView基本使用
- JAVA 安全性转码代码(包括sql注入,跨站脚本)
- 解决gnuplot中'Terminal type set to 'unknown'不能显示绘图的问题
- COPRA RF 2005 SR1最新版 (冷弯成型,轧辊设计)
- 自适应屏幕大小的网页是怎么做出来的
- Rhel6.5_Nginx1.45_Php5.59_MySQL5.6.16编译安装(集成LNMP环境)
- 获取日志$6到$NF的字段
- Android Choreographer 源码笔记
- Android Studio开发JNI工程
- 使用向量的方法计算点到直线的距离
- 一步步走进Android MaterialDesign 之 DrawerLayout
- How to install ipsec-tools on RHEL6
- bat批量目光声明
- 【Training versus Testing】林轩田机器学习基石
- 114 Flatten Binary Tree to Linked List 二叉树到单链表的扁平化处理
- IOS prepareForSegue 多窗口切换学习
- 如何编译&使用boost库?
- 好久没更新了,对这段时间做个总结
- ABAP中操作回车、换行、回车加换行、的方案