-->
当前位置:首页 > 题库

PROGRAMMING:Polygon perimeter calculation (inheritance)

Luz5年前 (2021-05-10)题库526
The following framework of polygon base classes is given
class polygon
{ protected:
int number;// Number of edges, up to 100
private:
int side_ length[100];// Side length array
public:
polygon();// Constructors are overloaded as needed
int perimeter();// Calculate polygon side length
void display();// Output polygon sides and perimeter
}
Create a derived class Rectangle and add the following data members:
int height;
int width;
Add the following member functions:
Parameterless and parameterized constructors of the rectangle class
int perimeter();// Calculate the side length of a rectangle
void display();// Output polygon sides and perimeter
Create a derived class equal_ Polygon, add the following data members:
int side_ len;
Add the following member functions:
equal_ Parameterless and parameterized constructors of polygon classes
int perimeter();// Calculate the length of an equilateral polygon
void display();// Output polygon sides and perimeter
Generate the above class and write the main function, according to the input polygon information, establish a polygon class object or rectangular class object or equilateral polygon class object, calculate the perimeter of each polygon, and output its number of sides and perimeter.
Input format: the test input contains a test case. In the first line of the test case, the number of polygons n is input. In the next N lines, each line gives the basic information of a polygon. The first number of each line is the type of the current polygon, 0 is a general polygon, followed by M numbers, which are the length of m edges, - 1 is the length of general polygon, and 1 is a rectangle, It is followed by two numbers, height and width respectively. 2 is an equilateral polygon, followed by two numbers, which are the number and length of the sides of the equilateral polygon.
Input example:
three
0 32 54 76 88 24 -1
1 32 54
2 3 32
Output example:
5 274
4 172
3 96






answer:If there is no answer, please comment