qy7904120 2015-03-14 07:43 采纳率: 0%
浏览 1976

C++考试题,求运行结果

帮一个同事答题,C++语法不是很看得懂,程序在VS里跑总是报错,请各位帮我看一下,万谢!
求程序的运行结果
1
#include
class Widget

{public:
Widget(){++count;}
~Widget(){--count;}
int numWidgets(){return count;}
private:
static int caount;
};
int Widget::count=0;
void main()
{Widget w,x;
cout << "Now there are " << w.numWidgets() << "widgets.\n";
{Widget w,x,y,z;
cout << "Now there are " << w.numWidgets() << "widgets.\n";
}
cout << "Now there are " << w.numWidgets() << "widgets.\n";
Widget y;
cout << "Now there are " << w.numWidgets() << "widgets.\n";

}

2.
#include  
class Tdate
{
public:
Tdate(int m=5,int d=16,int y=2013)
{
month=m; day=d; year=y;
cout <<month << "/"<<day <<"/"<year <endl;
}
protected:
int mouth;
int day;
int year;
};
void main()
{
Tdate aday;
Tdate bday(8);
Tdate cday(10,20);
Tdate dday(11,2,2014);

}

3.
#include
class C0
{
public:
int nV;
void fun(){cout << "Member of C0" <<endl;}
};
class C1:public C0
{
public:
int nV1;
void fun(){cout << "Member of C1" <<endl;}
};
class C2:public C0
{
public:
int nV2;
void fun(){cout << "Member of C2" <<endl;}
}
class D1:public C1,public C2
{
public:
int nVd;
void fun(){cout << "Member of D1" <<endl;}
}
void main()
{
D1 d1;
d1.fun();
d1.C1::nV=2;
d1.C1::fun();
d1.C2::nV=3;
d1.C2::fun();
}

  • 写回答

6条回答 默认 最新

  • threenewbee 2015-03-14 07:54
    关注

    第一题
    http://codepad.org/vWqeLqrt
    Now there are 2widgets.
    Now there are 6widgets.
    Now there are 2widgets.
    Now there are 3widgets.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog