[Solved] CS2310 Lab 4-Flow control (I) Conditional statements

$25

File Name: CS2310_Lab_4-Flow_control_(I)__Conditional_statements.zip
File Size: 499.26 KB

SKU: [Solved] CS2310 Lab 4-Flow control (I) – Conditional statements Category: Tag:
5/5 - (1 vote)

Please test the correctness of your program in Q 1, Q-2, and Q 3 using PASS.

Q1.

Write a program that reads 3 integer values (>0) from the user. The 3 values are interpreted as representing the lengths of the three sides of a triangle. The program prints a message saying whether the triangle is Equilateral (all sides equal), Isosceles (only 2 sides equal), Scalene (all sides unequal), or Impossible (cant form a triangle). A triangle can be formed only if the sum of the length of any 2 sides is greater than the length of the 3rd side and the length of all the sides of the triangle are positive.

Expected Output:

Example 1 Example 2
Enter the value of A, B and C:345Scalene Enter the value of A, B and C:3Equilateral
Example 3 Example 4
Enter the value of A, B and C:2Isosceles Enter the value of A, B and C:10Impossible
Example 5 Example 6
Enter the value of A, B and C:10Impossible Enter the value of A, B and C:10Impossible

Hint-1: If youd like to check for equality, you should not write something like: if (A==B==C), but instead, you should use the && operator: if (A==B && B==C)

Hint-2: The order of checking may affect the complexity of your code (although it still works). You may wish to check for impossible cases first, and identify the scalene case last.

NOTE: Your program MUST follow the EXACT input/output format! Otherwise, you may not pass the test cases even though your calculation is correct.

1

Computer Programming

Q2.

Write a program that prompts the user to enter an integer and determines whether it is

  • divisible by 3 and 5
  • divisible by 3 only
  • divisible by 5 only (d) not divisible by 3 or 5 Expected Output:
Example 1 Example 2
Enter an Integer Number: 15 15 is divisible by 3 and 5. Enter an Integer Number: 21 21 is divisible by 3 only.
Example 3 Example 4
Enter an Integer Number: 40 40 is divisible by 5 only. Enter an Integer Number: 23 23 is not divisible by 3 or 5.

Q3.

Write a program that calculates the result of a, operations, b which are entered by users, like 1+4 = 5.

  • Verify whether the input a and b are digits.
  • The operations include +, -, *, /, <, >, =.
  • True is simplified as T while False is simplified as F.
  • When operation is =, output == instead of = and add brackets to the equation, e.g., (1==2)=F.

Expected Output:

Example 1 Example 2
Enter the equation: 1 + 4 1+4=5 Enter the equation: 10 / 6 10/6=1.66667
Example 3 Example 4
Enter the equation: a + 1 Invalid input. Enter the equation: 1 < 4 1<4=T
Example 5 Example 6
Enter the equation: 1 $ 4 Invalid operation. Enter the equation: 5 = 5 (5==5)=T

Hint: Try to use switch case!

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2310 Lab 4-Flow control (I) Conditional statements
$25