0% found this document useful (0 votes)
13 views8 pages

CS100 Pa3

This document outlines Assignment 3 for a Computational Problem Solving course, focusing on implementing if-else statements in C++. It includes various tasks such as classifying temperature ranges, checking leap years, identifying quadrants in a Cartesian plane, calculating areas of shapes, and managing student details, among others. The assignment emphasizes the importance of originality and prohibits plagiarism, with a submission deadline set for February 21.

Uploaded by

rayyan.cems
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)
13 views8 pages

CS100 Pa3

This document outlines Assignment 3 for a Computational Problem Solving course, focusing on implementing if-else statements in C++. It includes various tasks such as classifying temperature ranges, checking leap years, identifying quadrants in a Cartesian plane, calculating areas of shapes, and managing student details, among others. The assignment emphasizes the importance of originality and prohibits plagiarism, with a submission deadline set for February 21.

Uploaded by

rayyan.cems
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/ 8

COMPUTATIONAL PROBLEM

SOLVING
Assignment 3

Working with if-else statements


Deadline: 11:55 PM, 21 February

Lead TAs: Muhammad Abdullah Sohail (26100142)


Salaar Masood (26100149)

Learning Outcomes
• Implement conditional logic to solve problems
• Translate problem descriptions into functional code

Submission Guidelines
• Attempt each task in separate C++ source files (task#.cpp).
• Combine all .cpp files into a folder, zip it, and rename as 2XXXXXXX PA3.zip.

Important Notes
• Copying or plagiarism is strictly prohibited.
• This assignment is a practical exercise to enhance your learning; dishonest prac-
tices will impede your progress.
Computational Problem Solving - Assignment 3

Task 1: Temperature Range Classifier [10]

Problem Description: Write a program that takes a temperature value (in Celsius)
as input from the user. Classify the temperature into categories based on the following
ranges:
• Freezing: Temperature is less than 0 degrees Celsius.
• Cold: Temperature is between 0 degrees Celsius (inclusive) and 10 degrees Celsius
(exclusive).
• Moderate: Temperature is between 10 degrees Celsius (inclusive) and 25 degrees
Celsius (exclusive).
• Warm: Temperature is between 25 degrees Celsius (inclusive) and 40 degrees Celsius
(exclusive).
• Hot: Temperature is 40 degrees Celsius (inclusive) or higher.
The program should output the temperature category.
Example

Enter temperature in Celsius : 15


Temperature Category : Moderate

Task 2: Leap Year Checker [10]

Problem Description: Write a program to determine if a given year is a leap year.


A leap year is defined as follows:
• A year is a leap year if it is divisible by 4.
• However, if a year is divisible by 100, it is NOT a leap year, unless it is also divisible
by 400.
Your program should take a year as input and output whether it is a ”Leap Year” or
”Not a Leap Year”.
Example

Input : Enter a year : 2000


Output : Leap Year

Input : Enter a year : 1900


Output : Not a Leap Year

Page 1
Computational Problem Solving - Assignment 3

Task 3: Quadrant Identifier [10]

Problem Description: In a 2D Cartesian coordinate system, points are located in


quadrants based on their x and y coordinates. Write a program that takes the x and y
coordinates of a point as input and determines which quadrant the point lies in.
• Quadrant 1: x > 0 and y > 0
• Quadrant 2: x < 0 and y > 0
• Quadrant 3: x < 0 and y < 0
• Quadrant 4: x > 0 and y < 0
• Origin: x = 0 and y = 0
• On X-axis: y = 0 (and x ̸= 0)
• On Y-axis: x = 0 (and y ̸= 0)
The program should output the quadrant or axis on which the point lies.
Input:

Enter x - coordinate : -3
Enter y - coordinate : 4
Output :
Quadrant : 2

Task 4: Shape Area Calculator with Shape Selection [15]

Problem Description: Design a program that calculates the area of different 2D


shapes. First, prompt the user to choose a shape: ”rectangle”, ”circle”, or ”triangle”.
Based on the shape chosen:
• If ”rectangle”, ask for length and width, then calculate and display the area (length
* width).
• If ”circle”, ask for the radius, then calculate and display the area (π * radius * radius,
use π ≈ 3.14159).
• If ”triangle”, ask for the base and height, then calculate and display the area (0.5 *
base * height).
• If the user enters an invalid shape name, display an ”Invalid shape selection” message.
Ensure your program clearly prompts for the necessary dimensions for each shape and
provides informative output.

Page 2
Computational Problem Solving - Assignment 3

Task 5: Triangle Type Checker [15]

Create a program that analyzes three given side lengths to determine if they can form a
valid triangle and, if so, to classify the type of triangle. The program should take three
integer inputs representing the lengths of the sides.
First, the program must validate whether these side lengths can form a triangle by
checking the triangle inequality theorem, which states that for three sides a, b, and c
to form a triangle, the sum of any two sides must be greater than the third:
• (a + b) > c
• (a + c) > b
• (b + c) > a
If the sides are not valid, the program should print the following error message: ”The
sides do not form a valid triangle.”
If the sides are valid, the program should then classify the triangle based on its side
lengths into one of three types:
• Equilateral (all three sides are equal)
• Isosceles (exactly two sides are equal)
• Scalene (all three sides are of different lengths)
Sample Output 1 (Valid Triangle):

Enter side 1: 5
Enter side 2: 5
Enter side 3: 8
The triangle is isosceles .

Sample Output 2 (Invalid Triangle):

Enter side 1: 1
Enter side 2: 2
Enter side 3: 10
The sides do not form a valid triangle .

Page 3
Computational Problem Solving - Assignment 3

Task 6: Class Manager - Classroom Management System


[10]

Design a basic classroom management system for a class of 5 students. The program
should:

1. Collect Student Details: For each of the 5 students, prompt for and store the
following information:
• Name
• Roll Number
• Email Address
• Contact Number
• Seat Number
Use appropriate input methods to collect this information.

2. Display All Student Details: After collecting details for all 5 students, display
*all* student details in a clear and organized format.

3. Implement Retrieval Feature: Allow the user to enter a roll number and, based
on that roll number, look up and display the corresponding student’s *name* and
*seat number*.

Example Output (Input Phase):

Enter details for student 1:


Name : Alukeiparathay
Roll Number : 26100130
Email : a@gmail . com
Contact Number : 123 -456 -7890
Seat Number : 1
Enter details for student 2:
Name : Salloo bhai
Roll Number : 26100149
Email : s@gmail . com
Contact Number : 987 -654 -3210
Seat Number : 2
Enter details for student 3:
Name : Abdullah Sohail
Roll Number : 26100142
Email : igris@jinwoo . com
Contact Number : 111 -222 -3333
Seat Number : 3

Page 4
Computational Problem Solving - Assignment 3

Enter details for student 4:


Name : Lil Huzi Vert
Roll Number : 26100067
Email : l@gmail . com
Contact Number : 444 -555 -6666
Seat Number : 4
Enter details for student 5:
Name : Hammad jr
Roll Number : 26100044
Email : h@gmail . com
Contact Number : 777 -888 -9999
Seat Number : 5

Example Output (Display All Details):

All student details :


Name : Alukeiparathay , Roll Number : 26100130 , Email :
a@gmail . com , Contact Number : 123 -456 -7890 , Seat Number
: 1
Name : Salloo bhai , Roll Number : 26100149 , Email :
s@gmail . com , Contact Number : 987 -654 -3210 , Seat Number
: 2
Name : Abdullah Sohail , Roll Number : 26100142 , Email :
igris@jinwoo . com , Contact Number : 111 -222 -3333 , Seat
Number : 3
Name : Lil Huzi Vert , Roll Number : 26100067 , Email :
l@gmail . com , Contact Number : 444 -555 -6666 , Seat Number
: 4
Name : Hammad jr , Roll Number : 26100044 , Email : h@gmail .
com , Contact Number : 777 -888 -9999 , Seat Number : 5

Example Output (Retrieval):

Enter roll number of student and find student ' s name and
seat number : 26100149
Student Name : Salloo bhai , Seat Number : 2

Page 5
Computational Problem Solving - Assignment 3

Task 7: Unit Conversion Program (Length) [15]

Problem Description: Write a program to convert length units. Ask the user to
choose the input unit (”meters”, ”feet”, or ”inches”) and the output unit (”meters”,
”feet”, or ”inches”). Then, ask for the length value.
Implement the following conversions using nested if-else:
• If input unit is ”meters”:
• If output unit is ”feet”, convert meters to feet (1 meter ≈ 3.28084 feet).
• If output unit is ”inches”, convert meters to inches (1 meter ≈ 39.3701 inches).
• If output unit is ”meters” (same unit), no conversion needed.
• Else if input unit is ”feet”:
• If output unit is ”meters”, convert feet to meters (1 foot ≈ 0.3048 meters).
• If output unit is ”inches”, convert feet to inches (1 foot = 12 inches).
• If output unit is ”feet” (same unit), no conversion needed.
• Else if input unit is ”inches”:
• If output unit is ”meters”, convert inches to meters (1 inch ≈ 0.0254 meters).
• If output unit is ”feet”, convert inches to feet (1 inch ≈ 0.0833333 feet).
• If output unit is ”inches” (same unit), no conversion needed.
• Else (invalid input unit), display ”Invalid input unit”.
After performing the conversion (or if no conversion is needed), display the converted
length in the specified output unit. Use approximate conversion factors as given.

Task 8: Simplified Hotel Room Booking System [15]

Problem Description: Create a simplified hotel room booking system. Ask the user
to specify the room type (”single”, ”double”, ”suite”) and the number of nights they
want to book.
Room rates per night:
• ”single” - $50
• ”double” - $80
• ”suite” - $150
Apply discounts based on number of nights:
• If booking for 3 or more nights, apply a 5% discount on the total cost.
• If booking for 7 or more nights, apply a 10% discount on the total cost (instead of
5%).
Use nested if-else to calculate the total booking cost. First, determine the base cost
based on room type and number of nights. Then, apply discounts based on the number of
nights using nested conditions. Output the total cost before discount, discount amount

Page 6
Computational Problem Solving - Assignment 3

(if any), and the final discounted cost. Handle invalid room type input by displaying
”Invalid room type”.

Page 7

You might also like