0% found this document useful (0 votes)
44 views

Programs Using String Functions: IT 105 Computer Programming 2

The document describes 4 programs that use string functions in C++. Program 1 accepts two words of equal length. Program 2 accepts words ending in 'y'. Program 3 produces a full name by concatenating first and last names entered by the user. Program 4 determines if a word is a palindrome by reversing the string and comparing it to the original. Several solutions for each program are provided and explained in 1-3 sentences each.

Uploaded by

blessie balagtas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Programs Using String Functions: IT 105 Computer Programming 2

The document describes 4 programs that use string functions in C++. Program 1 accepts two words of equal length. Program 2 accepts words ending in 'y'. Program 3 produces a full name by concatenating first and last names entered by the user. Program 4 determines if a word is a palindrome by reversing the string and comparing it to the original. Several solutions for each program are provided and explained in 1-3 sentences each.

Uploaded by

blessie balagtas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Programs Using String Functions

IT 105 Computer Programming 2


Program 1

A program using string functions that accepts two words


with equal number of characters.

IT 105 Computer Programming 2


Program 1 - Solution A

getting the length of two strings ,


storing the results on variable x
and y

IT 105 Computer Programming 2


Program 1 - Solution B

testing directly if two strings are


equal in length

IT 105 Computer Programming 2


Program 2

A program using string functions that accepts word


ending in y.

IT 105 Computer Programming 2


Program 2 - Solution A

Testing if the last index contains


character ‘y’ . The last index is
dependent on string length

IT 105 Computer Programming 2


Program 2 - Solution B

getting the last index of the string


variable word

IT 105 Computer Programming 2


Program 2 - Solution C

Testing if the first character of the


reversed string is ‘y’

IT 105 Computer Programming 2


Program 3

A program using string functions that produces a string


that contains the full name from the first name and last
name entered by the user

IT 105 Computer Programming 2


Program 3

IT 105 Computer Programming 2


Program 4

A program using string function that determines if the


input word is a palindrome. A palindrome is a word that
produces the same word when it is reversed.

For example,

madam, pop, mom and dad are palindromes

IT 105 Computer Programming 2


Program 4 - Solution A

Setting the letters to


uniform case

Creating a duplicate copy


of the inputted string
before reversing

Comparing the inputted


word and its reversed form
.

IT 105 Computer Programming 2


Program 4 - Solution B

Instead of converting the


string to a uniform case,
strcmpi is used to ignore
string case

IT 105 Computer Programming 2


Program 4 - Solution C

IT 105 Computer Programming 2

You might also like