Assignment 6 - String

1.

Write a C++ program to extract a character from the word as defined below.

string word = "Computer";

Sample Output
Array index = 2
Content = m

Array index = 9
Out of range

Array index = 3
Content = p

:

   
2.

Write a C++ program to extract a substring from the sentence as defined below.

string sentence = "Sacred Heart Canossian College";

Sample Output
Starting index = 7
Length of the substring = 5
Result = Heart

Starting index = 13
Length of the substring = 90
Length of the substring = 9
Result = Canossian

:

   
   
3.

Write a C++ program which counts the number of words in a sentence.

Sample Output
Enter a sentence: A fox kills a girl quickly but dies in the zoo afterwards.

Number of words = 12

   
4. Write a C++ program to convert a sentence to each of the following format.
(a) Convert all alphabets to uppercase letters
(b) Convert all alphabets to lowercase letters
(c) Convert the first letter of each word to uppercase letter and all the other letters to lowercase letters
   
5.

Encryption is the conversion of data into a form, called a cipher text that cannot be easily understood by unauthorized people. Decryption is the process of converting encrypted data back into its original form, so it can be understood. Write a C program to generate the following sample output.

Sample Output
Plain text: computer network
Cipher text (Method 1): krowten retupmoc
Cipher text (Method 2): dpnqvufs ofuxpsl
Cipher text (Method 3): ocpmturen teowkr

   
6.

Write a C++ program to generate an email address for a student with reference to her class and class number. Note: length of user name is 4 and strcat should be used in your program.

Sample Output
class : 6A
number : 1
email address: 6a01@shcc.edu.hk

   
7. Write a C++ program to accept two input string x and y. Then swap the values of x and y.