You are on page 1of 2

9.

3 LAB TASKS

1. Write a program which asks the user to enter current time in 24 hour format and display it in 12
hour format. Create an appropriate function to make this conversion happen. You can use A
instead of AM and P instead of PM while displaying 12 hour format.
[25 marks]

2. Any sequence of characters is called a string. String objects are actually in the form of a normal C
string with a null character as terminator. We can access any of its character by checking its index.

For example:
string str= “C++ programming is fun” ;
cout<<str[0]; // Show the character at 0th index

Output: C

Create a function which can be used to count a specific character in a long text. Programmer will
only provide it the desired text and a character to be counted and it should tell how many times
that character is repeated. Also check your function by calling it in the main of program.

[25 Marks]

3. Create a function named as SWAP which will be used to swap any two integers with each other.
One has to provide the numbers and it will exchange both. Can you use this as a basic building
block while sorting out a list of numbers?? Write another function to sort out 3 numbers in any
order ascending or descending and implement your SWAP function inside, if possible.
Note that the numbers and sorting order will be decided by the user.
Ascending: 1<2<3
Descending: 3>2>1
[25 marks]

4. Using functional approach write a code for a calculator which works for the fractions. User will
have to enter any two fractions and an operator to perform the desired manipulation. Your
calculator should have following specifications:
 Displays answer in p/q format
 Includes at least 4 basic operations (+, -, *, /)
 Specific function for each operation

[25 marks]
9.4 POST-LAB ACTIVITY

1. The area of an arbitrary triangle can be computed using the formula


area = √ss – as – bs – c

where a, b, and c are the lengths of the sides, and s is the semi perimeter.

s = a + b + c⁄2
Write a void function that uses five parameters: three value parameters that provide the lengths
of the edges, and computes the area and perimeter (not the semi perimeter) via reference
parameters. Make your function robust. Note that not all combinations of a, b, and c produce a
triangle. Your function should produce correct results for legal data and reasonable results for
illegal combinations.

You might also like