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

Lab 09

The document discusses arrays and strings in C++ programming. It provides 3 practice tasks to work with character arrays, strings, and string operations. It also provides 4 exercises, including using a 2D array to display the middle row and column elements, a program to print only alphabets from a user-input string, a program to count the number of words in a line of text, and a program to replace all four-letter words in a line of text with the word "work". The document is for a programming fundamentals lab focusing on further understanding arrays and string manipulation in C++.

Uploaded by

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

Lab 09

The document discusses arrays and strings in C++ programming. It provides 3 practice tasks to work with character arrays, strings, and string operations. It also provides 4 exercises, including using a 2D array to display the middle row and column elements, a program to print only alphabets from a user-input string, a program to count the number of words in a line of text, and a program to replace all four-letter words in a line of text with the word "work". The document is for a programming fundamentals lab focusing on further understanding arrays and string manipulation in C++.

Uploaded by

Prince Haris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IBA Institute of Emerging Technologies Khairpur

PROGRAMMING FUNDAMENTALS
Lab 09: Understanding Arrays - II
Under

Course Programming Fundamentals


Course Code CSC-102
Course Instructor(s) Nadeem Ahmed Tunio
Date (Lab Conducted) 8th November 2023 Date (Lab Submitted)

Objectives of Lab No. 9:


1. Use 2D array
2. Use char array (CString)
3. Use of String

Practice Task No. 1:


Write a program that will find the frequency of each character from character array (c-string).
Strings in C++:

Strings are used for storing text, a string variable contains a collection of characters surrounded by
double quotes:

To use strings, you must include an additional header file in the source code, the <string> library:

Practice Task No. 2:


Write a program that some operations on strings.

Practice Task No. 3:


Write a program that reverse the string
Exercise
1. Write a function in C++ which accepts a 2D array of integers and its size as arguments and
displays the elements of middle row and the elements of middle column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3x3, 5x5, 7x7 etc...]

Example, if the array contents is

3 5 4
7 6 9
2 1 8

Output
Middle Row: 7 6 9
Middle column: 5 6 1

2. Write a program in C++ that take String as an input from user and print only
alphabets from the sentence.

Input:

Hello h3w are you?

Output Hellohwareyou

3. Write a program that will read in a line of text and output the number of words.

4. Write a program that reads in a line of text and replaces all four-letter words with the word
“work”. For example,

Input:

I hate you, you dodo!


Output:

I work you, you work!

…END…

You might also like