You are on page 1of 4

CS100 Computational Problem Solving

Fall 2021-22

Deadline: 10:55AM Monday 27 September 2021

Pre-Lab 04: I/O Manipulators, String, ASCII

(Lab Section 3) Total Marks = 20

Lab Guidelines

1. You must put all your work into a folder named PreLab04_YourRollNo (e.g,
PreLab04_22100063), compress it into a “zip” file and submit the zip file on LMS
(Assignment -> PreLab04) before Monday, 27th Sept 10:55 AM. No late
submissions or email submissions will be accepted.
2. Communicating with each other is NOT permitted. Searching for answers or help on
the internet is not permitted. All help material provided in the Lab Manual is allowed.
If you have a question, ask the TAs on Slack in your lab section channel.
3. The object is not simply to get the job done, but to get it done in the way that is asked
for in the lab. The objective is not just to get the code working, but to have a deep
understanding of why it is working.
4. Any cheating case will be reported to the Disciplinary Committee without any delay.
5. Failure to adhere to the naming convention of the file will result in 2.5 marks deduction.
6. Failure to adhere to coding conventions of the file will also result in 2.5 marks
deduction.

Coding Conventions:
● Constants are “ALLCAPS” or “ALL_CAPS”.
● Variables are “allsmall” or “all_small”.
● All function names must be “firstWordSmallAllOtherWordsCamelCase”.
● All curly brackets defining a block must be vertically aligned.
● File naming: PreLab04_YourRollNo

Learning Objective:
● Use of integer and double data types
● Practice mathematical operations
Task 1: [10 marks]
Write a program that uses price of different products in Rupees and displays the price in Dollar
and Yen. Your display should look like the one shown below. Dollar should be correct to 3
significant figures and Yen should be correct to 2 decimal places. Read Lab Manual or consult
lecture recording for explanations.
(Hint: Read Lab Manual and ask Tas on Slack. Use cout.unsetf(ios::fixed) to unset the fixed
flag to print dollar correct to 3 significant figures and then use fixed keyword again to print Yen
correct to 2 decimal places).
1 Rupee = 0.0059 Dollar = 0.65 Yen

Products Rupees
Burger 160
Pizza 355
Cold drink 45

Steps
 Store the product costs (Burger=160, Pizza=355, Cold Drink=45) in variables of suitable
types
 Use I/O Manipulators to print the table headers “Products”, “Rupees”, “Dollars”, “Yen”.
 Then print the values of each of the products in three currencies, again using I/O
Manipulators for spacing, and also using other tools mentioned in Lab Manual and
taught in the lecture to make sure that the dollar value is printed upto 3 decimal places
and the yen value is printed upto 2 decimal places.

Sample output:

(Note: You must use I/O manipulators to create the table)


Task 2: [10 marks]
You are part of an intelligence agency working as an undercover agent. You must send an
encrypted message containing your name to confirm that you have successfully completed your
mission. Your name will be encoded as follows:
“Samee Arif”
Encoding: 83 97 109 101 101 32 65 114 105 102
This encoding is done using ASCII values of the characters in your name. The ASCII value of
‘S’ is 83, the ASCII value of ‘a’ is 97, and so on.

Steps
1. Store the following string

“Mission successful.
Regards,”

in a single string variable.


(Hint: Use a certain escape sequence to represent the new line in the string. Do not use
endl.)
2. Then print the variable.
3. Then print the encoding of your name.

Sample output:

(Hint: Use ascii encoding. You can seperately convert each characters in your name to interger
ascii code and print the integer value with space in between. Read Lab Manual for explanation
of how to do that.)

You might also like