Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My homework is about class and interface of c++. I don't understand how to do it to come out expect result like below. { 0

My homework is about class and interface of c++. I don't understand how to do it to come out expect result like below.

{ 0 1 2 3 4 5 6 7 8 9 } { 0 2 4 6 8 10 12 14 16 18 } { 0 1 2 3 4 5 6 7 8 9 0 2 4 6 8 10 12 14 16 18 } 0 18

and I have some function, The compiler chooses the appropriate overload based on usage like this example:

Array a; a.at(0) = 42; // stores 42 at index 0 cout << a.at(0); // prints value at index 0 const Array b = a; // const copy of a b.at(0) = 73; // NO! b is const cout << b.at(0); // OK! prints 42

This is my header file:

#ifndef ARRAY_H #define ARRAY_H #include  #include  /// An Array is a container that encapsulates a fixed size array. class Array { public: // type aliases using value_type = int; using size_type = std::size_t; using reference = value_type&; using const_reference = const value_type&; // constants static const size_type CAPACITY = 20; // constructors Array(); Array(const value_type source[], size_type count); void fill(value_type value); // element access reference at(size_type pos); const_reference at(size_type pos) const; reference front(); const_reference front() const; reference back(); const_reference back() const; private: value_type data[CAPACITY]; }; // Array bool equal(const Array& lhs, const Array& rhs); void print(const Array& array, Array::size_type first = 0, Array::size_type last = Array::CAPACITY);

This is my CPP file:

#include  #include "Array.h" using namespace std; int main() { Array list; for (int i = 0; i < 10; ++i) { list.at(i) = i; list.at(i + 10) = i * 2; } print(list, 0, 10); print(list, 10); print(list); cout << list.front() << '\t' << list.back() << ' '; return 0; }

I hope you guys can help me, this is my first time encounter this homework. This homework is really rush.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions