.
class A {int *a; public:
A(int x=0):a(new int(x)){} ~A() {delete a;}
int getA() {return *a;} void setA(int x) {*a=x;} };
void main() {A x1,x2(3); A *p=&x2;
(*p).setA(x2.getA()+5); x1.setA(10+x1.getA());
cout< 108; 六、程序设计题(本大题共1小题,共10分) 1. 已知交通工具类定义如下。 要求:(1)实现这个类;(2)定义并实现一个小车类car,是它的公有派生类,小车本身的私有 属性有载人数,小车的函数有init(设置车轮数,重量和载人数),getpassenger(获取载人数 ),print(打印车轮数,重量和载人数)。 class vehicle {protected: int wheels;//车轮数 float weight;//重量 public: void init(int wheels,float weight); int get_wheels(); float get_weight(); void print(); }; void vehicle::init(int wheels,float weight) {this->wheels=wheels; this->weight=weight; cout< int vehicle::get_wheels() {return wheels; } float vehicle::get_weight() {return weight;} void vehicle::print() {cout<<\车轮数:\重量:\ . . .
自考C++试题及答案(9套合集).
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)