根据UML类图写C类定义【精编】
Review (复习) Contents 1 概念 2 简答 3 选择 填空 改错 4 根据UML类图写C++类定义 根据C++代码画UML类图 5 编程 1 概念 对象,消息,方法,类,继承,封装,聚集,多态性,抽象类 友元函数,构造函数,析构函数,函数名重载,虚函数,纯虚函数, 异常 2 简答 简述C++程序中类的一般结构。 在C++程序中,类成员的访问权符有哪几种? 公有派生和私有派生有什么区别? 用成员函数和友元函数重载运算符有什么区别? 当进行多重继承时,如果在派生类中使用不同父类的同名成员,如何避免二义性? C++主要使用哪两个流类进行预定义类型的输入和输出,重载了哪两个运算符? UML类图中,如何表示聚集和泛化关系? 请列举出5种UML模型图。 3 根据UML类图写C++类定义 例:UML类图 类定义 #include class Figure{ protected: float x,y; public: void Set(); virtual void ShowArea(); }; class Triangle:public Figure{ public: void ShowArea(); }; class Square: public Figure{ public: void ShowArea(); }; class Circle: public Figure{ public: void ShowArea(); }; 4 根据C++代码画UML类图 例:源程序 #include class X{ protected: int a; public: void make(int i){a = i;} }; class Y{ protected: int a; public: void make(int i){a = i;} }; class Z: public X, public Y{ public: int make(){return X::a*Y::a;} }; UML类图 1. 定义一个Shape基类,在此基础上派生出Rectangle和Circle类,二者都有GetArea()函数计算对象的面积。使用Rectangle类创建一个派生类Square。 #include class Shape { public: Shape ( ) ( } ~Shape () { } virtual float GetArea () { return - 1; } }; class Circle : public Shape { public: Circle (float radius ): itsRadius (radius) { } ~Circle () { } float GetArea(){ return 3.14 * itsRadius * itsRadius; } private: float itsRadius; }; class Rectangle : public Shape { public: Rectangle(float len, float width): itsLength(len), itsWidth(width) { }; ~Rectangle () { ); float GetArea(){ return itsLength * itsWidth; } float GetLength() { return itsLength; ) float GetWidth() { return itsWidth; } private: float itsWidth; float itsLength; }; class Square : public Rectangle { public .. Square (float len); ~Square () { } }; Square:: Square (float len): Rectangle (len,len) { } void main() { Shape * sp; sp=new Circle (5); cout << "The area of the Circle is " << sp->GetArea () << endll d