1345 - CS I2P (II) 2017-2 Lee Midterm 2 Exercises Scoreboard

Time

2017/11/24 13:20:00 2018/01/15 00:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11422 Shape
11423 Simulating Iterators
11445 Copy a vector (Implement a vector 6)
11462 cppreference
11677 Implement a list 4 (back and remove)

11422 - Shape   

Description

Warning: You are not allowed to use malloc and free

Following the lecture slide :

Giving a bass-class Shape and 3 derived class : Triangle, Rectangle, Circle

You need to calculate the area and the perimeter of each shape.

note : You need to do some basic check: if the given information cannot form a shape (e.g. height of the rectangle is negative number....etc), then the area and perimeter would be both 0)

Input

There are only 3 shapes in this problem :

  • Triangle, following by its 3 edges. (e.g. Triangle 3 4 5)
  • Rectangle, following by its width and height. (e.g. Rectangle 5 7)
  • Circle, following by its radius and the value of pi. (e.g. Circle 2 3.14)

Output

Ouput the total area and perimeter of all the shapes.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11422.cpp

Partial Judge Header

11422.h

Tags




Discuss




11423 - Simulating Iterators   

Description

Warning: You are not allowed to use:

1. any static variables

2. any variables which is not inside a function

3. malloc and free

You are required to implement a iterator.

Random_iter is a array-like pointer which goes next or previous element by increasing or decreasing one memory address.

Bidirect_iter is a linked list-like pointer which goes next or previous element by the next or prev data member of Node.

(After you learning template, you will know how iterator exactly work.)

Input

The first line contains a non-negative integer N (0<N<100) that specifies the number of elements.

The second line contains 2*N integer that specifies the next position of elements and the value ([-32767,32768)) of the next element.

For example, 4 24713 2 21367 5 -3338 1 1893 3 -4723 0 -16458 means

node 0: value is -16458, next is node 4

node 1: value is 1893, next is node 2

node 2: value is 21367, next is node 5

node 3: value is -4723, next is node 1

...

The thrid line contains a non-negative integer H (H<N) that specifies which element is head.

The following lines contain an instruction I (0<=I<4). The meaning of I is shown below:

0 means distance. Containg a non-negative P (P<N, from input) that specifies the distance from head. You have to display the distance between current position and P.

1 means set value. Replace the value of current position with input integer.

2 means next. Set the current position to next.

3 means prev. Set the current position to previous.

Current position is initialized with 0, which points to head.

Output

Complete Node (constructor), Iter (constructor), Random_iter (distance_, next_, prev_ and constructor) and Bidirect_iter (distance_, next_, prev_ and constructor).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11423.cpp

Partial Judge Header

11423.h

Tags




Discuss




11445 - Copy a vector (Implement a vector 6)   

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

4. memory usage limit: 9216 byte

You are required to implement a vector.

If you don't know what is an operator new, you can check 11419 - Using your vector.

Input

There are seven functions in Vector that you have to implement, the functionality is as below:

  • default constructor: initializes pointers. Do not allocate memory.
  • copy constructor: copys the elements of rhs. The new capacity is rhs.size().
  • copy assignment operator: copys the elements of rhs. The new capacity is rhs.size().
  • erase: erases a element at pos.
  • insert: inserts a val at pos. When capacity is not enough, the new capacity is max(old capacity + 1, old capacity * 3).
  • reserve: reserves storage (Increase the capacity of the container to a value that's equal to new capacity. If new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.).
  • destructor

Output

Complete a Vector (default constructor, copy constructor, copy assignment operator, erase, insert, reserve and destructor).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11445.cpp

Partial Judge Header

11445.h

Tags




Discuss




11462 - cppreference   

Description

版本:

20180311

 

使用說明:

請下載code或header(兩個是同個檔案)

把附檔名從.cpp改成.zip

解壓縮後

reference>en>cpp.html

即可看到官方文件

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

11462.cpp

Partial Judge Header

11462.h

Tags

CPP Reference



Discuss




11677 - Implement a list 4 (back and remove)   

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

4. memory usage limit: 2048 byte

You are required to implement a list.

You have to enable C++11 in this problem. (e.g. "g++ -std=c++11 ...")

Input

The input consist of a number of operations. Each operations (push_back, remove and show) are separated by a newline character ('\n').

Operation push_back: following by a non-negative integer (insert value, 0<=insert value<20). Push a node at the end position with insert value.

Operation remove: following by a non-negative integer (remove value, 0<=insert value<20). Erase all nodes which data is equal to remove value. 

Operation show: print the value of all nodes in the list. Print a whitespace character (' ') after printing the value of nodes. If the list is empty, do not print anything.

Output

Implement List (constructor, destructor, push_back and remove) and operator<<(std::ostream &os,const List &lst).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11677.cpp

Partial Judge Header

11677.h

Tags




Discuss