#include<iostream> using namespace std; class aspl { public: aspl(float p){price=p;TotalPrice=p+TotalPrice;} ~aspl(){TotalPrice=TotalPrice-price;} static float get(){return TotalPrice;} private: float price; static float TotalPrice;//总价格 }; float aspl::TotalPrice=0; int main() { float f; cout<<"阿司匹林的库存总价格为"; cout<<aspl::get()<<endl; int i=0; cout<<"请输入第"<<i+1<<"次购进的阿司匹林的单箱价格:"; cin>>f; aspl *p[5]; p[i]=new aspl(f); cout<<"阿司匹林的库存总价格为"; cout<<aspl::get()<<endl; i++; cout<<"请输入第"<<i+1<<"次购进的阿司匹林的单箱价格:"; cin>>f; p[i]=new aspl(f); cout<<"阿司匹林的库存总价格为"; cout<<aspl::get()<<endl; cout<<"请输入卖出的阿司匹林的编号,编号即第几次购进"; cin>>i; i=i-1; delete p[i]; cout<<"阿司匹林的库存总价格为"; cout<<aspl::get()<<endl; return 0; }
<img src="http://img.blog.csdn.net/20150128164928263?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjUwMzYzOQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
时间: 2024-10-09 23:46:51