You are on page 1of 3

CS100 Computational Problem Solving

Fall 2021-2022
Daim Armaghan

Section 2 Friday 1 Oct

Lab# 04: Exercise

Lab Guidelines

1. You are allowed to perform/submit the lab only during the lab timings
2. Make sure you do not leave the lab without submitting your work on LMS
3. Copying/sharing code is strictly prohibited. Using any unfair means will lead to immediate
disqualification
4. Put all cpp files into a folder YourRollNo_Lab4_TAname and submit it on LMS
(Assignments>Lab4)
5. Lab ends at 8:50 pm and the submission tab closes at the same time

Task1 Total
20

Task2 Total
30

Task3 Total
30

Total Marks: 100 (80 + 20 for Viva)


Task 1 – string parsing [20 marks]

Write a program that asks for your LUMS email address (2xxxxxxx@lums.edu.pk) and
displays the roll number in full form (20xx-xx-xxxx).

Sample Output:

Enter your LUMS email address:


23100221@lums.edu.pk

Your roll number in full form is:


2023-10-0221

__________________________________________________________________

Task 2 – Manipulating strings [30 marks]

Write a program that asks user for name, phone number (in format 03xxxxxxxxx) and
date of birth (in format dd/mm/yyyy) and displays a unique code in following format:
name_mm_dd_yyyy_03xxxxxxxxx

<you can only use ‘string’ datatype for this task>


<for simplicity enter your name without spaces>
Enter your name:
DaimArmaghan

Enter your Date of Birth (in format dd/mm/yyyy):


20/11/2002

Enter your phone number (in format 03xxxxxxxxx):


03331234567

Your Unique Code is:


DaimArmaghan_11_20_2002_03331234567

________________________________________________________________

Task 3 – Letter swapping [30 marks]

Write a program that swaps two letters in a word. It should first ask user to input a
word and then ask the user to input position of character to be replaced. It should
then ask the user to input position of character to replace with. Finally, it displays the
updated word after swapping.
<you are not allowed to use If/else in this task. (-5 marks for violation)>
<positions start from 1>
<Hint: First character has position 1, second character has position 2, and so on>
<for simplicity:
• assume that positions entered by user are valid i.e., in range 1 to length of
word
• input word has at least 2 characters.
• position 1 is less than position 2. (“position of character to be replaced” is less
than “position of character to replace with”)>

<Note: All test Examples given below must pass to get full credit>

Test Examples:

Input word position of character position of character Updated word


to be replaced to replace with
salmon 1 6 nalmos
tuna 2 3 tnua
101011 1 2 011011
an 1 2 na

Sample Output:
Enter a word:
rocket

Enter position of character to be replaced:


2

Enter position of character to replace with:


5

Updated Word:
reckot

You might also like