Guidelines: The following exercises are to evaluate students’ understanding in the following topics (as essential programming concepts):
- Basic I/O functions (5%)
- Selection structure (20%)
- Repetition structure (20%)
- Arrays and strings (20%)
- Functions (10%)
- Programming techniques (25%)
Each question does not require external libraries or any special knowledge except for basic I/O functions. Skillful students should complete both question within only 20 minutes, while some students may take up to an hour.
Q1. Write a program that takes a string as an input, passes the string to a function which swaps the first 2 vowels of the string, and then prints the result as the output. The input string is assumed to consist only of lower-case letters and have its length of less than 32 characters. The program, however, must meet the following specifications:
- The function takes a string as an argument and does not return any value.
- The function swaps only the first 2 vowels of the string if 2 or more presented; the string remains unchanged otherwise.
- The function should not print any message.
- The input and the output must be taken and printed only in the main program.
The followings are expected outputs:
Test case #1
Enter a string: demo
Output: dome
Test case #2
Enter a string: print
Output: print
Q2. Write a program that takes a string as an input, passes the string to a function which returns the character that most frequently appears in the string, and then prints that character as the output. The input string is assumed to consist only of lower-case letters and have its length of less than 32 characters. The program, however, must meet the following specifications:
- The function takes a string as an argument and returns a character.
- The function may return any of the characters if many appear equally but most frequently.
- The function should not print any message.
- The input and the output must be taken and printed only in the main program.
The followings are expected outputs:
Test case #1
Enter a string: macbook
'o' appears most frequently in "macbooK"
Test case #2
Enter a string: iphone
'e' appears most frequently in "iphone"