Lab 5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

SWE111 - Computer Programming & Problem

Solving - Spring 2024


Instructors: Dr. Taraggy Mohiy, Dr. Nermin Jean, Dr. Ahmed Mansour
TA’s: Eng. Sarah Hatem, Eng. Nada Nofal, Eng. Saja Saadoun, Eng. Yasmin Kandil,
Eng. Salma Osama, Eng. Lina Bassel, Eng. Youssef Talaat, Eng. Jamila Mohamed

Lab 5
Lab Overview
In this lab we will mainly focus on these topics:

● C-Strings ● Single-Dimensional Arrays

Lab Content:

C-String library:

https://www.programiz.com/cpp-programming/library-function/cstring
2

Single-Dimensional Array

C++ One-Dimensional Array (codescracker.com)

One Dimensional Array in C++ | What are 1D Arrays? | Examples (toppr.com)

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

Expected Output: “Hello”

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);”

Input: ”hello world”

Expected Output: ”Hello World”

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();”

You might also like