CalibTable Constructor Copy

#include <iostream>
using namespace std;

// Write your CalibTable class here
class CalibTable {
    private:
        int size;
        int table[10];
    public:
        CalibTable(int n, int arr[]):size(min(10,max(1,n))){
            for (int i=0; i<size; i++) {
                table[i] = arr[i];
            }
        }
        int get(int index) {
            if (index < size) return table[index];
            else return 0;
        }
        void print() {
            for (int i=0 ; i<size ;i++) {
                cout << table[i] << " ";
            }
        }
};

int main() {
    int n;
    cin >> n;

    int arr[100];

    int countToRead = (n < 1 ? 1 : n);  // ensure at least one value is read

    for (int i = 0; i < countToRead; i++) {
        cin >> arr[i];
    }

    CalibTable t(n, arr);
    t.print();

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 10 20 30 40 50

Expected Output

10 20 30 40 50