当输入25,60时,这个c++程序的输出结果

来源:百度知道 编辑:UC知道 时间:2024/06/27 16:15:03
#include<iostream.h>
class goods{
private:
static int totalWeight;
int weight;
public:
goods(int w)
{
weigh=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;
cont<<"The initial weight of goods:"<<goods::getTotal()<<endl;
cin>>w;//输入25
goods g1(w);
cin>>

输出结果为:85
程序有些许小错误,改正后:
#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;//输入25
goods g1(w);
cin>>w;//输入60
goods g2(w);
cout<<"The total weight of goods:"<<goods::getTotal()<<endl;
}

The total weight of goods:85

fafafs

85

c语言当执行下面的程序时,如果输入ABC,则输出的结果是:ABC6789 如何编写C程序:从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入 C程序:输入若干字符,分别统计数字字符的个数、英文字母的个数,当输入换行符时输出统计结果,运行结束。 这个c程序的输出结果是什么 这个C程序输出是多少? 设计一个程序当输入一个数时,输出的数是输入的数改变了次序? 输入a、b、c三个值,输出其中最大者,并运行这个程序 帮个忙,怎么用C语言做这个程序?1的三次方,一直加到N的三次方,要求输入N这个数字能够输出结果 C程序设计:从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入。 2写一个判断素数的程序段。以InputBox接收输入的整数,当该数为素数时,输出TRUE,否则输出FALSE