11428 - Copy a vector (Implement a vector 4)   

Description

You must follow the rules as below:

1. do not use any static variables

2. do not use any variables which is not inside a function

3. only new, operator new, delete and operator delete are allowed to allocate or deallocate memory

You are required to implement a vector with copy constructor and copy assignment operator.

The main function will create two empty vector which object type is Shape. The Shape calss has a Shape_impl pointer, and when you copy, you need to copy class Shape_impl instead of Shape_impl pointer in class Shape.

You should write three class (Rectangle, Square and Circle) to inhert Shape_impl, and these class also need to have copy constructor or copy assignment operator.

Please refer to function.h for detail.

Input

The input will have eight command.

Note: shape will look like rect length width, squa length and circ radius( the area of circle is radius*radius*3.14)

  • p num shape: push_back a shape in vec[num]( vec[num] is vec[0] or vec[1])
  • e num begin end: erase the shape between begin and end in vec[num] (erase vec[num][begin]~vec[num][end-1])
  • i num pos count shape: insert #count shape into vec[num] in position pos
  • c num: print vec[num].capacity()
  • s num: print vec[num].size()
  • copy num num2: copy vec[num2] to vec[num]
  • sort num: sort the vec[num] (compare the area of shape)
  • area num: print the total area in vec[num]

Output

Please complete 

  • class Rectangle, class Square, class Circle (pi will be 3.14)
  • function: Shape_impl* new_rect, Shape_impl* new_squa, Shape_impl* new_circ
  • function: Shape_impl* copy_Shape_impl, void delete_Shape_impl
  • operator: bool operator<(const Shape_impl &,const Shape_impl &);  note: (true return 1, false return 0)
  • operator: std::ostream& operator<<(std::ostream &,const Shape_impl &);
  • Vector function(push_back, erase, reserve, insert, ~Vector())  note: you can use the class vector you write in the previous homework. (you should modify erase function)
  • Vector copy constructor (Vector(const Vector &)) and copy assignment operator (Vector& operator=(const Vector &))

Note: When you use vector copy constructor, e.g. oj::Vector temp(vec[num2]), temp's capacity will as same as vec[num2]

When you use vector copy assignment operator, e.g. vec[num]=temp, vec[num]'s capacity will be max(vec[num].capacity(), temp.capacity())

If you want to know the rule of size and capacity, you can see 11410 - Implement vector

When you input a command, the output will show the vec[0] and vec[1].

Sample Input  Download

Sample Output  Download

Partial Judge Code

11428.cpp

Partial Judge Header

11428.h

Tags




Discuss