You are on page 1of 3

Week 10

1. Write a program that takes a user-inputted string and outputs its acronym.

Example:
Enter a string: National Aeronautics and Space
Administration Acronym: NASA

2. Write a C++ program that prompts the user to enter a 11-digit phone number and determines the associated
telecom provider based on the first three digits of the number. The program should display the telecom provider's
name (Vodafone, Orange, WE, Etisalat) or indicate if the number is invalid.

Telecom Provider Prefixes


Vodafone 010, 011
Orange 012, 015
WE 016, 019
Etisalat 017

3. Imagine you are developing a software package that requires users to enter their passwords. Your software
requires that users’ passwords meet the following criteria:
• The password should be at least six characters.
• The password should contain at least one uppercase and at least one lowercase letters
• The password should have at least one digit.
Write a program that asks for a password and then verifies that it meets the stated criteria and display a message
if not asking to reenter a new one stating which criteria was not fulfilled.

4. Write a C++ program that removes a specific word from a given string. Return the updated string.

Example:
Enter a string: Exercises Practice Solution
Enter the word to remove: Practice
Updated string: Exercises Solution
5. Trace the Following program:

#include <iostream>
#include <string>

using namespace std;

int main()
{
cout << "Enter a string: ";
string inputString;
getline(cin, inputString);

int ALPHABET_SIZE = 26;


int charCount[ALPHABET_SIZE];

for (int i = 0; i < ALPHABET_SIZE; i++)


charCount[i] = 0;

for (int i = 0; i < inputString.length(); ++i)


{
char ch = tolower(inputString[i]);
if ('a' <= ch && ch <= 'z')
{
charCount[ch - 'a']++;
}
}

cout << "Alphabetic Character Counts:\n";


for (int i = 0; i < ALPHABET_SIZE; ++i)
{
if (charCount[i] != 0)
{
char ch = 'a' + i;
cout << "'" << ch << "': " << charCount[i] << " occurrence(s)\n";
}
}

return 0;
}
Home Work

6. Write a program that prompts the user to input a string and outputs the title case version of the entered string.

Example:
Enter a string: hello world, how are you?
Title Case: Hello World, How Are You?

7. Write a C++ program that takes a string and reverses the words of three or more lengths in a string. Return the
updated string. As input characters, only spaces and letters are permitted.

Example:
Original string: The quick brown fox jumps over the lazy dog
Reverse the words of three or more lengths of the said string:
ehT kciuq nworb xof spmuj revo eht yzal god

8. Write a C++ program that alternates the case of each letter in a given string of letters. Pattern: First lowercase
letter then uppercase letter and so on.

Example:
Enter a string of letters: helloWorld
Updated string: hElLoWoRlD

9. Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. The program should
print the date in the form March 12,2012.

You might also like