首页 » c++代写 » C++代写 | CS11440 Lab 6 – Class Templates

C++代写 | CS11440 Lab 6 – Class Templates

这是一篇美国的c++代写代码

 

Templates

Templates in C++ is not a difficult idea. This lab is not intended to help you understand the details of how templates work. It is only intented to give students an opportunity to start developing code using templated classes.

Everyone in the class has had to come to grips with the usage of variables in general. With templates, you can think of the type of the variable being a variable itself. The programmer is just saying that when you want to instantiate an instance of this class you will need to tell the compiler which variable type the class needs to use. After understanding that, templates just become a syntactical change.

Developing a templated class is not difficult either. I think the syntax is the most difficult aspect. It’s just pure ugly. So, I suggest that you approach the MyArray class as if it was the I nt Array class. Yes, I’m suggesting that you write pushBack, popBack, getSize, isEmpty, operator[], and toString as if you were writing the IntArray class we developed in the Big 4 lab. After completing that implementation and testing for correctness, go back and change all necessary instances of int to the template variable.

Here’s the MyArray class written as Mylnt from the Big 4 lab.

 

// You won * t be able to inherit from ContainerIfc at this point which means you may

// have to test locally to begin with.

class MyArray (

private:

int *data;

int capacity, size;

public:

// You will need to write all function defintions outside of the class defintion MyArray();

};

MyArray::MyArray()(

this->capacity = 5;

this->size = 0;

this->data = new int[this->capacity];

 

Here’s the MyArray class with the inheritance and templating in place.

 

template <class T>

class MyArray : public Containerlfc<T> {

private:

T *data;

int capacity, size;

public:

MyArray();

};

// notice the T used in the name of the class not the name of the function

template <class T>

MyArray<T>::MyArray()(

this->capacity = 5;

this->size = 0;

this->data = new T[this->capacity];

}

 

MyArray Class

MyArray will inherit from Containerlfc. Containerlfc is an abstract classes which requires you to implement the functions in your MyArray. In addition to overriding the pure virtual functions, you will need to implement the big four because of the precense of dynamic memory in the class.


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank