Sale!

COSC6000 Homework 10

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (10 votes)

Develop a template class, ShiftArray that has following features.
template parameters are data type and size of array.
Overload operator []
member function circshift(int n) that circularly shifts the elements in the array by n positions.
n is a int type.
If n is positive, shift elements towards right.
If n is negative, shift elements towards left.
For example :
1 2 3 4 5 Initial array elements
5 1 2 3 4 circshift(1)
1 2 3 4 5 circshift(­1)
4 5 1 2 3 circshift(2)
Use code below to test your class:
int main(int argc, char **argv)
{
// test int
ShiftArray<int,3> a;
a[0] = 21;
a[1] = -12;
a[2] = 103;
for (int j = 1 ; j < 5 ; j++){
a.circshift(j);
for (int i = 0 ; i < 3 ; i++){
std::cout << a[i] << ” “;
}
std::cout << std::endl;
}
// test char
ShiftArray<char,20> mes;
for (int i = 0 ; i < 20 ; i++){
mes[i] = ‘_’;
}
mes[0] = ‘H’;
mes[1] = ‘e’;
mes[2] = ‘l’;
4/23/2018 Homework 10
https://tulane.instructure.com/courses/2165899/assignments/13470336 2/2
mes[3] = ‘l’;
mes[4] = ‘o’;
for (int j = 0 ; j < 20 ; j++){
for (int i = 0 ; i < 20 ; i++){
std::cout << mes[i];
}
std::cout << std::endl;
mes.circshift(-1);
}
return 0;
}
output will be:
103 21 -12
21 -12 103
21 -12 103
103 21 -12
Hello_______________
ello_______________H
llo_______________He
lo_______________Hel
o_______________Hell
_______________Hello
______________Hello_
_____________Hello__
____________Hello___
___________Hello____
__________Hello_____
_________Hello______
________Hello_______
_______Hello________
______Hello_________
_____Hello__________
____Hello___________
___Hello____________
__Hello_____________
_Hello______________