[go: up one dir, main page]

0% found this document useful (0 votes)
25 views4 pages

PF LAB 03 (Conditional Statements)

Uploaded by

ibrahimahsan485
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

PF LAB 03 (Conditional Statements)

Uploaded by

ibrahimahsan485
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

National University of Computer and Emerging Sciences

Lab Manual # 3
Programming Fundamentals
(Section BCS-2A1&2A2)

Course Instructor Miss. Hira Butt


Lab Instructor(s) Ahmed Khalid
Hooria Najeeb
Section BCS-2A1 & 2A2
Semester Spring 2024

Department of Computer Science,


Fast NUCES,
Lahore
Instructions:
• Work in this lab individually. Discussion is not allowed.
• Evaluation of tasks will be conducted in the lab.
• Anyone caught indulging in the act of plagiarism would be awarded an “F” grade in this lab.

Objective:
After performing this lab, students shall be able to:
• Usage of Input/output statements
• Conditional Structures o If- selection statement o If-else statement o Nested if statement o Switch
statement

Question#1 (10 marks)


Write C++ expressions that represents the following English expression. Assume that all variables have
been properly defined and initialized.
1. x is even and y is odd (x and y are integers).
2. x is not between -47.5 and 132.0 (x is double)
3. w is more than 200, and one or more of the following three conditions is fulfilled:
• x is less than 98.6
• y is less than 60.0
• z is more than 160.0
4. score is between 50 and 60 inclusive
5. age is outside the range p to q
6. at least one of x and y value is odd
7. the hit is not more than 6.7 units away from target
8. ch is an uppercase alphabetic character (between ‘A’ and ‘Z’)
9. year is divisible by 4
10. w is either equal to 6 or not greater than 3

Question#2 (5 marks)
Write a C++ program that calculates the cashback amount. If user total purchasing bill is greater than 1000,
then it is eligible for cashback, otherwise not. If user is eligible for cashback then cashback is calculated
via (purchasing bill * 10/100). If cashback is greater than 200, then it is multiplied by the 2, otherwise not.
In last it should display the cashback.

Sample:
Question#3 (5 marks)
(Switch statement) Write a C++ program that prompts the user to enter a character. If the character is a
vowel (a, e, i, o, u), display "Vowel". Otherwise, display "Consonant"

Question#4 (5 marks)
(if-else) In a particular country, the legal age for voting is 18 and for driving is 21. Check if a person is
eligible for voting, driving, both, or none based on their age.
Sample:

Question# 5 (10 marks)


(Nested-if-else) Write a C++ program that takes four numbers from user as an input. Find the maximum
from the given numbers using nested if.
Sample:
Question#6 (10 marks)
(Switch statement) Write a C++ program to simulate a grading system. Prompt the user to enter the marks
obtained by a student (out of 100). Based on the marks, display the corresponding grade according to the
following criteria:

90-100: A+
85-89: A
80-84: A-
75-79: B+
70-74: B
65-69: B-
60-64: C+
55-59: C
50-54: C-
Below 50: Fail

Question#7 (10 marks)


(Nested-if-else) Write a program that prompts the user to enter a number. Your task is to determine
whether a number is positive or negative. If a number is positive, then check whether it is an even or an
odd number. If the number is even then display a message “Positive Even Number” if it is an odd number
then print “Positive Odd Number”. If a number is negative, then check whether it is a perfect square or
not. If a number is a perfect square, then print the message “Negative value with perfect square of
absolute” otherwise simply display the message “Neither positive nor perfect square of absolute”. (You
can use sqrt (square root) function here e.g., sqrt(49) will return 7 if you are storing the value in int data
type and we know that 7*7 = 49. Similarly sqrt(40) will return 6 if the result is stored in int data type and
we know that 6*6 is not equal to 40. So if the number is a perfect square then the square of the returned
value by sqrt function will also be equal to that number) but the problem is that we can only calculate the
square root of a positive number and here we have negative number so convert this negative number into
a positive number first for the calculation such that the actual value remains the same. For this purpose,
you can use abs (absolute) function. It will change the negative value into positive like abs(-12) will
return 12 but as I mentioned that original negative value should be preserved.
Sample:
Enter a number: 864
Positive Even number
OR
Enter a number: -81
Negative Value, perfect square of absolute
OR
Enter a number: 923
Positive Odd Number
OR
Enter a number: -40
Neither positive nor a perfect square of absolute

You might also like