Write the function rotateLeft which shifts each element in the array left by one position, moving the first element to the end. Return the modified array. arrays.cpp 1 #include // size t 2 3 int* rotateleft(int a[], size t len) { 4 6. return a; 9. } Tester.cpp 1 #include 2 using namespace std; 3 #include "arrays.h" int main() { int al[] = {10,13,14,10,10,8}; auto len1 = sizeof(al) / sizeof(al[0]); print ("before al->", al, len1); print("after al: ", rotateLeft(al, len1), len1); cout « "Expected: [13, 14, 10, 10, 8, 10]" « endl; cout « endl; 4 5 7 8 9. 10 11 12 13 int a2[] = {3,9,9,5}; auto len2 = sizeof(a2) / sizeof(a2[0]); print("before a2->", a2, len2); print("after a2: ", rotateLeft(a2, len2), len2); cout « "Expected: [9, 9, 5, 3]" « endl; } 14 15 16 17 18 19 CodeCheck Reset

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 29SA
icon
Related questions
Question

C++

Write the function rotateLeft which shifts each element in the array left by one position, moving
the first element to the end. Return the modified array.
arrays.cpp
1
#include <cstddef> // size t
2
int* rotateleft(int a[], size_t len)
{
3
4
5
6
7
8
return a;
}
Tester.cpp
1
#include <iostream>
2
using namespace std;
3
#include "arrays.h"
int main()
{
int al[] = {10,13,14,10,10,8};
auto len1 = sizeof(al) / sizeof(al[0]);
print("before al->", al, len1);
print("after al: ", rotateLeft(al, len1), len1);
cout « "Expected: [13, 14, 10, 10, 8, 10]" « endl;
cout « endl;
4
5
6.
7
10
11
12
13
int a2[] = {3,9,9,5};
auto len2 = sizeof(a2) / sizeof(a2[0]);
print("before a2->", a2, len2);
print("after a2: ", rotateLeft(a2, len2), len2);
cout « "Expected: [9, 9, 5, 3]" « endl;
}
14
15
16
17
18
19
CodeCheck
Reset
Transcribed Image Text:Write the function rotateLeft which shifts each element in the array left by one position, moving the first element to the end. Return the modified array. arrays.cpp 1 #include <cstddef> // size t 2 int* rotateleft(int a[], size_t len) { 3 4 5 6 7 8 return a; } Tester.cpp 1 #include <iostream> 2 using namespace std; 3 #include "arrays.h" int main() { int al[] = {10,13,14,10,10,8}; auto len1 = sizeof(al) / sizeof(al[0]); print("before al->", al, len1); print("after al: ", rotateLeft(al, len1), len1); cout « "Expected: [13, 14, 10, 10, 8, 10]" « endl; cout « endl; 4 5 6. 7 10 11 12 13 int a2[] = {3,9,9,5}; auto len2 = sizeof(a2) / sizeof(a2[0]); print("before a2->", a2, len2); print("after a2: ", rotateLeft(a2, len2), len2); cout « "Expected: [9, 9, 5, 3]" « endl; } 14 15 16 17 18 19 CodeCheck Reset
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr