Pf Assignment c String or String
Pf Assignment c String or String
Programming Fundamentals
String/C-String Practice Questions
1. Reverse a String: Write a C++ program that takes a string as input and prints its reverse. For
example:
o Sample Input: “w3resource”
o Sample Output: “ecruoser3w”
2. Shift Letters in Alphabet: Create a C++ program that changes every letter in a given string to the
letter following it in the alphabet. For instance:
o Sample Input: “w3resource”
o Sample Output: “x3sftpvsdf”
3. Capitalize First Letter of Each Word: Develop a C++ program that capitalizes the first letter of
each word in a given string. Words must be separated by only one space.
o Sample Input: “cpp string exercises”
o Sample Output: “Cpp String Exercises”
4. Find the Largest Word: Write a C++ program that finds the largest word in a given string.
o Sample Input: “C++ is a general-purpose programming language.”
o Sample Output: “programming”
5. Sort Characters in a String: Create a C++ program that sorts characters (excluding numbers and
punctuation symbols) in a string.
o Sample Input: “python”
o Sample Output: “hnopty”
o Hint (Sort by ascii)
6. Count Vowels in a String: Write a C++ program to count all the vowels in a given string.
o Sample Input: “eagerer”
o Sample Output: “number of vowels -> 4”
7. Count Words in a String: Develop a C++ program to count all the words in a given string. Words
can be separated by a space or punctuations.
o Sample Input: “Python”
o Sample Output: “number of words -> 1”
8. Check Equal Appearance of Two Characters: Create a C++ program to check whether two
characters appear equally in a given string.
o Sample Input: “aabcdeef”
o Sample Output: “True”
9. Check Palindrome: Write a C++ program to check if a given string is a palindrome or not. A
palindrome reads the same backward as forward (e.g., “madam” or “racecar”).
o Sample Input: “madam”
o Sample Output: “True”
10. Word with Highest Repeated Letters: Implement a C++ program to find a word in a given string
that has the highest number of repeated letters.
o Sample Input: “Print a welcome text in a separate line.”
o Sample Output: “Word which has the highest number of repeated letters: separate”
11. Insert Dashes Between Odd Numbers: Create a C++ program to insert a dash character (‘-’)
between two odd numbers in a given string of numbers.
o Sample Input: “1345789”
o Sample Output: “Result -> 1-345-789”
12. Change Case of Characters: Write a C++ program to change the case (lower to upper and upper to
lower) of each character in a given string.
o Sample Input: “Pythpn”
o Sample Output: “pYTHPN”.