⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5.2.cpp

📁 关于友元的实验程序源代码
💻 CPP
字号:
#include <iostream.h>
class Cargo
{
private:  
      float b,n,m[100];
	  float weight,weight1;
      static  float  totalsweight;
public: 
        Cargo();  
    	~Cargo();

        void inCargo();
	    void putCargo();
};
Cargo::Cargo()
{  }
Cargo::~Cargo()
{  }
float  Cargo::totalsweight=0;
void Cargo::inCargo()
{   float  weight=0;
	cout<<"输入购进货物的箱数:";
    cin>>n;cout<<endl;
	for(int i=1;i<=n;i++)
	{cout<<"输入购进货物各箱的重量:";cin>>m[i];cout<<endl;
	 weight=weight+m[i]; 
	}
	
    totalsweight=weight; 
	cout<<"目前库存的货物的总箱数:"<<n<<endl;
	cout<<"目前库存的货物的总重量:"<<totalsweight<<endl;
	cout<<"                         "<<endl;
	cout<<"输入卖出货物的箱数:";
    cin>>b;cout<<endl;}

void Cargo::putCargo()
{	float  weight1=0; 
	for(int i=1;i<=b;i++)
	{weight1=weight1+m[i]; 
	}
     n=n-b; 
	 totalsweight=totalsweight-weight1;
	 cout<<"卖出货物的总箱数:"<<b<<endl;
	 cout<<"卖出货物的总重量:"<<weight1<<endl;
	 cout<<"                   "<<endl;
	 cout<<"目前库存的货物的总箱数:"<<n<<endl;
	 cout<<"目前库存的货物的总重量 :"<<totalsweight<<endl; 
}

void main()
{ Cargo myCargo;  
   myCargo.inCargo(); myCargo.putCargo();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -