0% found this document useful (0 votes)
9 views3 pages

Lab 5

This document provides an overview of Lab 5 which focuses on C-Strings, single-dimensional arrays, and includes exercises on string manipulation, arrays, and generating random characters. The lab content includes links about C-strings and 1D arrays and 5 exercises involving strings, arrays, averages, and character counting.

Uploaded by

zeina1912006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Lab 5

This document provides an overview of Lab 5 which focuses on C-Strings, single-dimensional arrays, and includes exercises on string manipulation, arrays, and generating random characters. The lab content includes links about C-strings and 1D arrays and 5 exercises involving strings, arrays, averages, and character counting.

Uploaded by

zeina1912006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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