CS100 Pa3
CS100 Pa3
SOLVING
Assignment 3
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
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
Page 1
Computational Problem Solving - Assignment 3
Enter x - coordinate : -3
Enter y - coordinate : 4
Output :
Quadrant : 2
Page 2
Computational Problem Solving - Assignment 3
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 .
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
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*.
Page 4
Computational Problem Solving - Assignment 3
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
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.
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