Q-1. Write a program to read a string and count the number of characters and the number of vowels ('a', 'e', 'i', 'o', 'u') in the string. For the counting of vowels, you should consider both uppercase and lowercase versions of the characters.
Hint:
1. You may use cin to read the string to a char array.
2. You may use the function strlen() in <cstring to count the number of characters in the string.
3. You may need to define a counter (initialized to 0) and write a for-loop to examine each character in the string (until the null character '\0' is encountered). If the character is vowel, update the count.
Expected Outputs:
Example 1 Example 2
Easter
The number of characters is: 6
The number of vowels is: 3 Hello
The number of characters is: 5
The number of vowels is: 2
Example 3 Example 4
AEIOU
The number of characters is: 5
The number of vowels is: 5 CityU
The number of characters is: 5
The number of vowels is: 2
Q-2. Download convert.cpp. Modify it to convert all lowercase letters in a string to uppercase letters and convert all uppercase letters to lowercase letters. The input string may contain multiple words.
Hint: You can use cin.getline() function in <cstring to read the string to a char array. You may also assume that the maximum size of char array is 50.
Expected Outputs:
Example 1 Example 2
HeLLO hEllo CityU cITYu
Example 3 Example 4
Course 2311 cOURSE 2311 a Survey A sURVEY
Q-3. Download sort.cpp. The program defines an array called course with six cstrings representing the course titles. Complete the program by sorting course in an ascending alphabetical order.
Hints: You can use strcmp() for comparison.
Expected Outputs:
C++ Programming
Data structures
English
Internet
Java Programming
Mathematics
Q-4. Download opt.cpp. The program defines an array with 10 cstrings representing the students list, and an array with 6 cstrings representing the course list. The program has already randomly assigned each student to register one course. Complete the program so that it can
1) count the number of registrations for each course.
2) print the course list in descending order according to the number of registrations.
3) print the registered students’ names for each course and students’ names should be sorted in ascending alphabetical order.
Note: Your actual output is likely to be different from the expected output if you're not using Microsoft Visual C++ 2015 (PASS). In case of any inconsistency between your output and PASS output, the PASS output shall prevail.
Expected Outputs:
Enter the seed for random number generation: 234
James registers Internet
Iverson registers Mathematics
Wade registers Internet
Jordan registers Data structures
George registers Java Programming
Curry registers Data structures
Westbrook registers C++ Programming
Durant registers Java Programming
Kobe registers Data structures
Harden registers Internet
Students' list:
Curry
Durant
George
Harden
Iverson
James
Jordan
Kobe
Wade
Westbrook
3 students register Data structures: Curry Jordan Kobe
3 students register Internet: Harden James Wade
2 students register Java Programming: Durant George