[go: up one dir, main page]

0% found this document useful (0 votes)
49 views2 pages

C++ Lab 9 Alpha

This lab manual provides exercises for students to practice using C++ strings. The objectives are to declare and initialize C-strings and string objects, use getline() to input strings, and manipulate strings using predefined functions. The lab contains 6 questions that involve extracting data from C-strings, concatenating strings, determining if one string is a subset of another, counting characters in a string, checking for anagrams, and exploring various string library functions.

Uploaded by

Attia Batool
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)
49 views2 pages

C++ Lab 9 Alpha

This lab manual provides exercises for students to practice using C++ strings. The objectives are to declare and initialize C-strings and string objects, use getline() to input strings, and manipulate strings using predefined functions. The lab contains 6 questions that involve extracting data from C-strings, concatenating strings, determining if one string is a subset of another, counting characters in a string, checking for anagrams, and exploring various string library functions.

Uploaded by

Attia Batool
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/ 2

LAB MANUAL # 9

Course: Computer Programming (CP-107)


Session: 22CP Alpha

C++ Strings

This lab has been designed to practice programs of C++ strings. In this lab students will
practice declaring, initializing and using C-string as well as string objects. Students will also
use getline() function to take string input. Clear concept about C++ strings has already been
provided in the class along with examples.
Objectives:
In this lab, you will practice:
 C-string declaration and initialization.
 Using getline() with C-string.
 Using C-string predefined functions to perform string manipulation.
 Class string object declaration and initialization.
 Using getline() with string class.
 Using string class functions for string manipulation.
 Defining string array.
 Defining 2D char array.

Lab Tasks: 15/


Question # 1: 2/
Create a C-string variable (char array) that contains a name, age, and title. Each field is
separated by a space. Write a program using only functions from c-string (not the class
string) that can extract the name, age, and title into separate variables.
Question # 2: 2/
Write a program that inputs two string variables, first and last, each of which the user
should enter with his or her name. Then convert both strings to lowercase and
concatenate both strings and store in first string variable.
Question # 3: 2/
Write a program to determine whether one string is subset of another string.

Question # 4: 2/
Write a program to count the total number of alphabets, digits and special characters in
a string.

Question # 5: 3/
Write a program to determine whether two strings are anagrams of each other. Anagram
means containing same letters in a different order e.g., rescue and secure are anagrams
of each other.
LAB MANUAL # 9
Course: Computer Programming (CP-107)
Session: 22CP Alpha

Question # 6: 4/
Write a program to explore and apply the following string library functions:
c-string functions:
Strlen, strcat, strcpy, strncat, strncpy, strcmp, strstr, atoi,
itoa
String class member functions:
compare, copy, length, append, at, insert, replace, swap, size.

****************

You might also like