0% found this document useful (0 votes)
16 views2 pages

Lab07 A

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Lab07 A

Uploaded by

abdulhamid.jamon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS2311 Computer Programming 2024-25A

Lab 7-a Strings


Please test the correctness of your program in Q1, Q2, Q3 on PASS.
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 Hello
The number of characters is: 6 The number of characters is: 5
The number of vowels is: 3 The number of vowels is: 2
Example 3 Example 4
AEIOU CityU
The number of characters is: 5 The number of characters is: 5
The number of vowels is: 5 The number of vowels is: 2

Q-2.
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.
The output of your program should look like the following:

C++ Programming
Data structures
English
Internet
Java Programming
Mathematics

Q-3. [Optional]
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.

1/2
CS2311 Computer Programming 2024-25A

Note: Your actual output is likely to be different from the expected output if you're not using
Microsoft Visual C++ 2019 (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:
2019
James registers English
Iverson registers Internet
Wade registers Data structures
Jordan registers English
George registers C++ Programming
Curry registers Mathematics
Westbrook registers Mathematics
Durant registers Java Programming
Kobe registers Java Programming
Harden registers English

Students' list:
Curry
Durant
George
Harden
Iverson
James
Jordan
Kobe
Wade
Westbrook

3 students register English: Harden James Jordan


2 students register Mathematics: Curry Westbrook
2 students register Java Programming: Durant Kobe
1 student registers Data structures: Wade
1 student registers C++ Programming: George
1 student registers Internet: Iverson

2/2

You might also like