非常感谢!
1、分析下面程序运行的结果。 #include
using namespace std;
int main()
{
int a,b,c;
a=10;
b=23;
c=a+b;
cout<<〃a+b=〃;
cout<
2、分析下面的程序,写出其运行时的输出结果。
#include
using namespace std;
class Date
{public:
Date(int,int,int);
Date(int,int);
Date(int);
Date( );
void display( );
private:
int month;
int day;
int year;
};
Date∷Date(int m,int d,int y):month(m),day(d),year(y)
{ }
Date∷Date(int m,int d):month(m),day(d)
{year=2005;}
Date∷Date(int m):month(m)
{day=1;
year=2005;
}
Date∷Date( )
{month=1;
day=1;
year=2005;
}
void Date∷display( )
{cout<
{
Date d1(10,13,2005);
Date d2(12,30);
Date d3(10);
Date d4;
d1.display( );
d2.display( );
d3.display( );
d4.display( );
return 0;
3、阅读下面程序,分析其执行过程,写出输出结果。
#include
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){ }
void change(int n,float s){num=n;score=s;}
void display( ){cout<
int num;
float score;
};
int main( )
{Student stud(101,78.5);
stud.display( );
stud.change(101,80.5);
stud.display( );
return 0;
5. 有以下程序结构,请分析访问属性。
class A // A为基类
{public:
void f1( );
int i;
protected:
void f2( );
int j;
private:
int k;
};
class B: public A //B为A的公用派生类
{public:
void f3( );
protected:
int m;
private:
int n;
};
class C: public B //C为B的公用派生类
{public:
void f4( );
private:
int p;
};
int main( )
{A a1; //a1是基类A的对象
B b1; //b1是派生类B的对象
C c1; //c1是派生类C的对象
return 0;
}问:
(1) 在main函数中能否用b1.i,b1.j和b1.k引用派生类B对象b1中基类A的成员?
(2) 派生类B中的成员函数能否调用基类A中的成员函数f1和f2?
(3) 派生类B中的成员函数能否引用基类A中的数据成员i,j,k?
请写出具体答案