销售员未来规划怎么写:C++运行结果的题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/19 07:20:46
1.给出下面程序运行的结果。
#include <iostream.h>
class MyClass {
public:
int number;
void set(int i);
};
int number=33;
void MyClass::set (int i)
{
number=i;
}
void main()
{ MyClass my1;
int number=10;
my1.set(5);
cout<<my1.number<<endl;
my1.set(number);
cout<<my1.number<<endl;
my1.set(::number);
cout<<my1.number;
}
2.运行下面的程序,给出当输入225,160时的输出结果。
#include <iostream.h>
class goods{
private:
static int totalWeight;
int weight;
public:
goods(int w)
{
weight=w;
totalWeight+=w;
}
goods(goods& gd)
{
weight=gd.weight;
totalWeight+=weight;
}
~goods()
{
totalWeight-=weight;
}
int getwg()
{
return weight;
}
static int getTotal()
{
return totalWeight;
}
};
int goods::totalWeight=0;
void main()
{
int w;
cout<<"The initial weight of goods:"<<goods::getTotal()<<endl;
cin>>w; //输入225
goods g1(w);
cin>>w; //输入160
goods g2(w);
cout<<"The total weight of goods:"<<goods::getTotal()<<endl;
}

1.
5
10
33

2.
The total weight of goods:0