Assignment
Assignment
Assignment # 1
Submission Instructions:
1) You have to submit 1 zip file containing:
• MS word document containing C++ programs with screen shot of console
• .cpp file of the program and input files where required
2) You have to upload your assignments on CMS.
3) Plagiarism is not acceptable. If someone’s assignment is plagiarized, that student will be given F
straight away, so beware.
4) The deadline for this assignment is April 10th, 2022, 11:59 pm. No late submission will be
accepted.
Learning Objectives: Demonstrate knowledge of character arrays and file handling in programming
(C++).
Task 1:
Write a C++ program asks user for a string and checks its length. If the length of string is even then display
it in reverse order and if the length is odd, sort the string alphabetically.
Sample Output:
Sample output 1:
Enter a string: UCP Lahore
Length is: 10
String is: erohaL PCU
Sample output 2:
Enter a string: file handling
Length is: 13
String is: adefghiillnn
Task 2:
Write a C program which takes a string of unknown length from the file input.txt. Then find the total number of
vowels and consonants in that string, also sort vowels in descending order and write the results in output.txt. You also
have to write sorting code for sorting of vowel array. Note that the count of vowels is case independent.
Input.txt:
This is a string which contains vowels and consonants. Our task is to sort them in descending order, and print their
count.
Output.txt:
Total Consonants: 66
Total Vowels: 33
Total ‘i’: 10
Total ‘o’: 9
Total ‘a’: 6
Total ‘e’: 6
Total ‘u’: 2
Task 3:
Write a C++ program that reads registration numbers from the file students.txt and after required formatting write it
records.txt as shown below.
students.txt
FA21-BCS-110
FA20-BCS-122
SP21-BSE-134
FA21-BCS-137
FA21-BSE-145
record.txt
Semester Program Roll No.
FA21 BCS 110
FA20 BCS 122
SP21 BSE 134
FA21 BCS 137
FA21 BSE 145