帮一个同事答题,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();
}