CalibTable Constructor Copy

#include <iostream>
using namespace std;

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

    public:

    CalibTable(int n, int arr[]){
        if(n < 1) size = 1;
        else if(n > 10) size = 10;
        else size = n;

        for(int i = 0; i < size; i++){
            table[i] = arr[i];
        }
    }
    int get(int index){
        if(index>10) return 0;
        else if(index < 0) return 0;
        else return table[index];
    }
    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