CalibTable Constructor Copy

#include <iostream>
#include <cstring>
using namespace std;

// Write your CalibTable class here
class CalibTable{
    private:
        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;
            }
            memcpy(table, arr, size*sizeof(int));
        }
        int get(int index){
            if(index <0 || index >9){
                return 0;
            }
            return table[index];
        }
        void print(){
            for(int i=0;i<size;i++){
                cout << table[i];
                if(i != size - 1) cout << " ";
            }
        }
};

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