72. CalibTable Constructor Copy

Create a class CalibTable that stores a fixed-size calibration table.
The constructor must safely clamp the table size and copy calibration values into an internal array.

A minimum of one value must always be read, even if the input requests size 0 or a negative size.

  • Private members:
    • int size
    • int table[10]
  • Constructor Requirements:
    • Implement a constructor:
      • CalibTable(int n, int arr[])
        
  • It must follow these rules:
    • If n < 1, set size = 1
    • If n > 10, set size = 10
    • Otherwise, set size = n
    • Copy exactly size elements from arr into the internal array
    • Ignore extra inputs beyond the allowed size
  • Public Methods:
    • int get(int index) → return value or 0 if index is out of range
    • void print() → print stored calibration values space-separated

Program Behavior:

  1. Read integer n
  2. Read max(n, 1) calibration values into a temporary array
  3. Construct CalibTable
  4. Print stored calibration values

 

Example Input:

0
5

Example Output:

5

Explanation:

  • n = 0 → size becomes 1
  • One value (5) is read, stored, and printed

 

Constraints:

  • No dynamic memory allowed
  • Constructor must handle size clamping
  • Must correctly handle n ≤ 0 by reading at least one value

 

 

 

 

Loading...

Input

5 10 20 30 40 50

Expected Output

10 20 30 40 50