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:
- You may use cin >> to read the string to a char array.
- You may use the function strlen() in <cstring> to count the number of characters in the string.
- 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 is encountered). If the character is vowel, update the count.
Expected Outputs:
Example 1 | Example 2 | |
Easter The number of characters is: 6The number of vowels is: 3 | Hello The number of characters is: 5The number of vowels is: 2 | |
Example 3 | Example 4 | |
AEIOU The number of characters is: 5The number of vowels is: 5 | CityU The number of characters is: 5The number of vowels is: 2 |
- Download 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 |
- Download 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
- Download 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
- count the number of registrations for each course.
- print the course list in descending order according to the number of registrations.
- 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 youre 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 InternetIverson registers MathematicsWade registers InternetJordan registers Data structuresGeorge registers Java ProgrammingCurry registers Data structuresWestbrook registers C++ ProgrammingDurant registers Java ProgrammingKobe registers Data structuresHarden registers Internet Students list:CurryDurantGeorgeHardenIversonJamesJordanKobeWadeWestbrook 3 students register Data structures: Curry Jordan Kobe3 students register Internet: Harden James Wade2 students register Java Programming: Durant George1 student registers Mathematics: Iverson 1 student registers C++ Programming: WestbrookNobody registers English |
Reviews
There are no reviews yet.