You are on page 1of 10

Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

LAB NO : 2
TASK # 1
 Objective:
Write a C++ Program which reads the input for the following information and
then prints it in the following format. The data type for “dues” should be saved
as Boolean (bool). If there are any remaining dues, enter true and it will print 1
and vice versa. Save the patient’s ID with const keyword, try to change the
value of that variable after successfully printing the following information
once. Patient’s ID: 0123
Full name: ABC
Age: 70
Contact no: 000000000
Address: XYZ
Department name: (For Example: Accident & Emergency, Neurology, ENT etc.)
Assigned Doctor: XYZ
Date: ------------
Dues: 0

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Source code:

 Output:

TASK # 2(1)
 Objective:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

Implement the above two Examples of Implicit Casting with user input.
 Source code:


 Output:

TASK # 2(Example 2)
 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

TASK # 3
 Objective:
Write a C++ program that reads a number in inches, converts it to meters.

Note: One inch is 0.0254 meter. Example:

Test Data

Input a value for inch: 1000.

Expected Output:

1000.0 inch is 25.4 meters.

 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

TASK # 4(a)
 Objective:
Write a C++ program which reads number of eggs in each basket and total
number of baskets from user, then calculates and prints result like following:

 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

TASK # 4(b)
 Objective:
b) Now alter the scenario and ask the user “how many eggs would you like to take
from each basket?” Then calculates the number of remaining eggs accordingly.

 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

TASK # 5(a)
 Objective:
Write a C++ program which initializes three variables with data type int, signed
int and unsigned int. Now read a whole number with negative sign in int type

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

variable, assign the same value to other two variables, then print all the three
integers and observe the output. In Second Case, read a positive number from
the user and observe the output
 Source code:

 Output:

TASK # 5(b)with positive num


 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

TASK # 6
 Objective:
Implement the Explicit type casting for every type as shown in above
hierarchy.
 Source code:

Computer Programming Page no:


Lab no : 2 MUBASHIRA DILSHAD 2021F-BCE-130

 Output:

Computer Programming Page no:

You might also like