Default constructor called. Default constructor called. Default constructor called. Construcotor:a=1,b=2 Construcotor:a=3,b=4 3.23
3.24
3.25
3.26
Construcotor:a=5,b=6 Con. Copy con. default. Copy con. A=5 B=14 A=9 B=14 5,7 22.25 Constructing Constructing A=5 B=15 A=10 B=15 Destructing Destructing 3.27
void pintStu();函数只有声明,没有定义。 age是私有成员,不能用对象直接调用。 3.28
void printStu() 和 void setSno(int s) 没有加限定符 Student::
void setAge(int a)在类中没有声明 3.29
构造函数不能定义为私有。否则无法创建对象。
3.30 下面是一个计算器类的定义,请完成该类成员函数的实现。
class counter {
public:
counter(int number);
void increment(); //给原始值加1 void decrement(); //给原始值减1 int getvalue(); //取的计数器值 int print(); //显示计数 private:
int value; };
counter::counter(int number) {
value = number; }
void counter::increment() {
++value; }
void counter::decrement() {
--value; }
int counter::getvalue() {
return value; }
int counter::print() {
cout << value < 3.31 根据注释语句提示,实现类Date的成员函数 #include class Date { public: void printDate(); void setDay(int d); void setMonth(int m); void setYear(int y); private: int day, month, year; }; void Date::printDate() { cout << \今天是\ << year << \年\ << month << \月\ << day << \日\ << endl; } void Date::setDay(int d) { day = d; } void Date::setMonth(int m) { month = m; } void Date::setYear(int y) { year = y; } int main() { Date testDay; testDay.setDay(5); testDay.setMonth(10); testDay.setYear(2003); testDay.printDate(); return 0; } 3.32 建立类cylinder, cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度。用类cylinder计算圆柱体的体积,并存储在一个double变量中。在类cylinder中包含一个成员函数vol,用来显示每个cylinder对象的体积。 const int PI = 3.14; class cylinder {