Professional Documents
Culture Documents
Lab 5
Lab 5
Lab 5
Lab 5
Lab Overview
In this lab we will mainly focus on these topics:
Lab Content:
C-String library:
https://www.programiz.com/cpp-programming/library-function/cstring
2
Single-Dimensional Array
A One-Dimensional Array is the simplest form of an Array in which the elements are stored
linearly and can be accessed individually by specifying the index value of each element stored in
the array.
Exercises:
1. Write a function which shortens a string to n characters and then print it. If the string is
already shorter than n, the function should not change the string. Assume the function is
“void truncate(string a, int n);”
3
Input: “Hello, World!”, 5
2. Write a function which capitalizes the first letter in every word. All other letters should be
turned into lowercase. You can use the predefined functions “toupper'' and “tolower”.
Assume the function is “string capitalizeWords(string a);”
3. Write a program that computes the average of an array of integers and then count the
number of elements above the average.
Input: 5, 6, 3, 2, 8
Expected Output: 2
4. Write a function that reverses an array of integers. Assume the function is “void reverse();”
Input: 1, 2, 3, 4, 5
Expected Output: 5, 4, 3, 2, 1
5. Write a function that generates 100 random lowercase letters and assign them to an array
of characters. Then, count the occurrence of each letter in the array. Assume the function
is “void countLetters();”