CalibTable Constructor Copy

#include <iostream>
using namespace std;

// Write your CalibTable class here
class CalibTable{
    int size;
    int table[10];

    static int SaznitizeSize(int n){
        if(n>10){return 10;}
        if(n<1){return 1;}
        return n;   
    }

public:

    CalibTable(int n, int arr[]) : size(SaznitizeSize(n))  {
        std::copy(arr, arr + size, table);
    }

    int get(int index){
        if((index<size)&&(index>0)){
            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