代寫C C++ Java Python 視頻講解客服在線客服在線

代做國外C C++ Java程序 Python QQ 2365427650 Email 2365427650@qq.com 免費咨詢編程問題

« An infectious diseaseGraph algorithms in C »

overloading Buffer

Implement a Buffer template class. The buffer stores elements
of some type. In case the buffer is full and the user attempts
to add more elements to it, memory is allocated with some
margin. E. g., consider a buffer of capacity 10 which already
contains 10 elements. In case of an attempt to add new element
memory should be allocated, and not for 11 elements but, for
example, for 15 elements. Upon addition of two buffers of
sizes 10 and 20, memory is allocated for, say, 40 elements
instead of 30 and so on.
size - number of elements in the buffer;
capacity - maximum number of elements that can be stored in
the buffer. If size == capacity and a new element is added,
allocation of memory for a greater number of elements takes
place;
buffer - pointer to a memory region where the elements of the
buffer are stored;
Resize(int AddCapacity) - extends capacity of the current buffer by
AddCapacity. The data stored in the buffer and its size are
left unchanged.
template <typename T>
class Buffer
{
private:
unsigned int size;
unsigned int capacity;
T* buffer;
void Resize(unsigned int AddCapacity);public:
Buffer();
Buffer(unsigned int Capacity);
Buffer(const Buffer& Other);
Buffer(Buffer&& Other);
~Buffer();
Buffer& operator=(const Buffer& Other);
Buffer& operator=(Buffer&& Other);
//...
};
I
Implement the given constructors, destructor, assignment
operators and Resize member function.
The Buffer(int Capacity) constructor creates a buffer of
capacity Capacity, the default constructor creates a buffer
of some given capacity (defined by you).
The constructors, destructor and assignment operators must
contain debug prints with their names.
II
Implement constant member functions for retrieving the current
number of elements in the buffer (Size()), its capacity
(Capacity()) and the values of the first (First()) and last
(Last()) elements.III
Implement the Delete(unsigned int Idx) member function, which
removes the element at the given index Idx. The buffer elements
are numbered starting at zero.
For example, if your buffer contained the following data
{1, 2, 3, 4, 5, 6, 7, 8, 9}
Then, after the element at index 3 is removed, its contents
would be:
{1, 2, 3, 5, 6, 7, 8, 9}
IV
Overload the operators +, +=, <<, [] and the writing to an
output stream operator (<<).
Operator +
The return type: Buffer<T>
1) Addition of two buffers. The result is a new buffer, the
operands themselves are left unchanged.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
Buffer<int> buff2 = ...; // {6, 7, 8, 9, 10}
...
Buffer<int> buff3 = buff1 + buff2; // {1,2,3,4,5,6,7,8,9,10}
2) Addition of a buffer and an element of type T. The result
is a new buffer with the element added to its end. The operands
themselves are left unchanged.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
Buffer<int> buff2 = buff1 + 10; // {1,2,3,4,5,10}
3) Addition of an element of type Т и буфера. and a buffer.
The result is a new buffer with the element added to its beginning. Positions of the other elements are shifted by one.
The operands themselves are left unchanged.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
Buffer<int> buff2 = 10 + buff1; // {10,1,2,3,4,5}
Operator +=
The return type: Buffer<T>&
1) Addition of an element of type Т to the end of the current
buffer.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
buff1 += 10; // {1, 2, 3, 4, 5, 10}
2) Addition of a buffer to the end of the current one.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
Buffer<int> buff2 = ...; // {6, 7, 8, 9, 10}
buff1 += buff2; //buff1 = {1,2,3,4,5,6,7,8,9,10}
Hint: the private member function Resize implemented earlier
could be used to change the size of a buffer.
Operator <<
The return type: void
1) Addition of an element of type Т to the end of the current
buffer.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
buff1 << 10; // {1, 2, 3, 4, 5, 10}
2) Addition of a buffer to the end of the current one.
Buffer<int> buff1 = ...; // {1, 2, 3, 4, 5}
Buffer<int> buff2 = ...; // {6, 7, 8, 9, 10}
buff1 << buff2; //buff1 = {1,2,3,4,5,6,7,8,9,10}Hint: the private member function Resize implemented earlier
could be used to change the size of a buffer.
Operator []
Retrieving and setting the value of the element at the given
index.
The following code must work:
Buffer<Type> buff;
...
Type val = buff[3];
buff[5] = val2;
Operator << (writing to an output stream)
Outputs the contents of a buffer to the screen. This operator
must be implemented as a global function. It is forbidden to
use friend functions.
The following code must work:
Buffer<int> buff; //buff = {1, 2, 3, 4, 5}
std::cout << buff << std::endl;
The result:
{ 1, 2, 3, 4, 5 }
V
Your application must call all the implemented public member
and global functions.
Class and function declarations must be put into a Buffer.h
header file, their implementations – into a Buffer.hpp file.
It is necessary to include Buffer.hpp into the source file
containing the main() function of your applicatiion.
classes,
constructors,
destructor,
operator
overloading, friend functions
  • 相關文章:

發表評論:

◎歡迎參與討論,請在這里發表您的看法、交流您的觀點。

最新評論及回復

最近發表

Powered By Z-Blog 1.8 Walle Build 100427

Copyright 代寫C.

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信
悉尼代写,商科assignment代写,网课代修,论文加急-OnlyEssay 澳洲作业代写,essay代写,网课代修,exam代考-ESSAYSHIFU 代写essay,代写assignment|DRS英国论文代写留学推荐网站 Assignment代写,【essay代写】美国作业代写-留学代写ESSAY网 Dueduedue论文服务-【美国论文代写】加拿大论文ESSAY代写服务 ESSAYCASE |essay代写|assignment代写|paper代写,全球在线写作中心 EasyDue™-北美地区论文作业ESSAY代写服务机构,作业代写-覆盖100+全学科 EssayBerry:美国论文ESSAY代写服务,代写essay,统计代写,代写文章 EssayWill-论文代写网|经济代写,数学,CS代写,Assignment代写 Essaymint:专注软文代写和代写作业等服务|作业代写-100%原创高分