0% found this document useful (0 votes)
18 views1 page

Assignment1 PF 2024

Uploaded by

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

Assignment1 PF 2024

Uploaded by

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

University of Management and Technology, Lahore

Assignment 1 Programming Fundamentals F2024 Marks 10

Note: Complete all programming questions by hand on white A4 paper. To ensure accuracy, type each code into
a C++ compiler, and include a screenshot of each successful solution along with your handwritten answers.

1. Write a program that prompts the user to enter their name (using char array) and age (as a short integer).
Display a greeting message formatted as “Welcome, [name].” and on new line age should be printed.
2. Develop a program that asks the user to enter two double numbers. Calculate and display their sum,
difference, product, and quotient. Include a check to prevent division by zero, and display an error message if
the user attempts division by zero.
3. Write a program that takes an integer input representing a user’s age. Use relational operators to check if the
age is less than 13 (child), between 13 and 19 (teen), or 20 and above (adult), then display a message based
on the category. Ensure that your program outputs one of these messages: "Child," "Teen," or "Adult."
4. Write a program that takes two boolean inputs (true or false) from the user and uses logical operators (&&, ||,
!) to demonstrate AND, OR, and NOT operations.
5. Write a program that asks the user to enter an integer. Use if-else if conditions to check if the number is
positive, negative, or zero, then display a message such as “Positive number,” “Negative number,” or “Zero.”
Use a short integer data type for this task.
6. Create a program that prompts the user for a char input to represent their answer (Y or N). Use if-else if
statements and a logical operator to check if the input is either uppercase or lowercase (e.g., Y or y), and
display a message based on whether the answer was "Yes" or "No."
7. Develop a program that asks for the user’s temperature in Celsius (use float) and humidity level (use double).
Using if-else if and logical operators, check if the temperature is above 30 and humidity above 50 to display
“It’s hot and humid,” if both conditions are met. If only one condition is met, display “It’s hot” or “It’s
humid,” and if neither, display “Weather is comfortable.”
8. Write a program with a global variable score (type int) and a local variable score in main. Assign different
values to both variables, then display both values with clear labels to demonstrate how C++ differentiates
between global and local scope.
9. Create a program where you declare an integer variable value at the start of main. Then, inside an if
statement, declare a char variable value with a different value. Display both values inside their respective
scopes, and attempt to access the local char variable outside the if block to see the effect of block scope.
10. Create a program that prompts the user to enter two integers and checks if the first is greater than the second,
equal to the second, or less than the second.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy