Test2Q2 (Practical) SCSJ1013 202120221 (2)

.pdf
School
Universiti Teknologi Malaysia**We aren't endorsed by this school
Course
SCSJ 1013
Subject
Mathematics
Date
Jan 2, 2025
Pages
4
Uploaded by MasterJackalPerson1129
1 CONFIDENTIAL UNIVERSITI TEKNOLOGI MALAYSIA TEST 2 QUESTION 2 (FLOWCHART) SEMESTER I 2021/2022 SUBJECT CODE : SECJ/SCSJ1013 SUBJECT NAME : PROGRAMMING TECHNIQUE I YEAR/COURSE : 1 (SECJ/ SECV/ SECB/ SECR/ SECP) TIME : 08:35 PM 09:20 PM MYT (45 minutes) DATE : 11thJANUARY 2022 (Tuesday) INSTRUCTIONS TO THE STUDENTS: Please read the General Guidelines for the Programming Technique I Test 2that is shared in UTM e-learning Read the problem and instructions carefully You are given 45 (FOURTY-FIVE) MINUTES to complete the test inclusive of the submission of your program (35 minutes to answerthe question and 10 minutes to submitthe answer). Your program must follow the input and output as required in the text and shown in the examples. You must test the programs with (but not limited to) all the input given in the examples. IMPORTANT NOTES: All the COMMENT STATEMENTSin the submitted program WILLNOT BE EVALUATED. SUBMISSION PROCEDURE: Only the source code is required for the submission (do not need to compress the file) File name format for INTERIMsubmission: Test2Q2_Name_matricsNo_section-interim.cpp(i.e., Test2Q2_AinaAli_A20EC018_01-interim.cpp) File name format for FINALsubmission: Test2Q2_Name_ matricsNo_section-final.cpp(i.e., Test2Q2_AinaAli_A20EC018_01-final.cpp) Submit the source code file via the UTM’s e-Learning System.
Background image
2 Question 2 [30 Marks] Quadratic equations are particularly interesting especially for teaching the concepts of roots of nonlinear equations. Given a quadratic equation in standardform, ax^2 + bx + c = 0, we can determine whether the quadratic equation has two real roots, one real root, or a complex root by calculating the discriminant as: 1)Two real-roots: b^2-4ac > 0 2)One real-root (repeating roots): b^2-4ac = 0 3)Complex roots: b^2-4ac < 0 For cases 1 and 2 above, we can compute the quadratic roots by the following formula 𝑥 =−? ± √?2− 4??2?where we just plug in the coefficients a, b, and c into the above formula. Figures 1(a) and 1(b) are the flowcharts to create quadratic equation in standard form, and compute and display its discriminant and roots (if it has two-real roots or one-real root).Figure 1(a):Flowchart to create and compute quadratic equation
Background image
3 Figure 1(b):Flowchart to create and compute quadratic equation Write a C++ program to implement the computation of standard quadratic equation as specified by the above flowcharts. Table 1 is the test cases that you can use to test the program and the details of the input/output style of the program. Table 1: Test cases to run and test the program (user inputs are shown in red-boldtext) TEST CASE 1 Welcome to Quadratic Equation Program Create a quadratic equation in standard form: ax^2 + bx + c = 0 Enter the values of a, b, and c: 1 -6 2Quadratic equation created: 1x^2 + -6x + 2 = 0 Discriminant of the Quadratic equation is: 28 The roots are, x1 = 5.64575, x2 = 5.64575 The equation entered had two real roots Do you wish to continue? (y/n): y
Background image
4 TEST CASE 2Welcome to Quadratic Equation Program Create a quadratic equation in standard form: ax^2 + bx + c = 0 Enter the values of a, b, and c: 1 2 3Quadratic equation created: 1x^2 + 2x + 3 = 0 Discriminant of the Quadratic equation is: -8 Program cannot solve for complex root The equation entered had complex root Do you wish to continue? (y/n): yTEST CASE 3Welcome to Quadratic Equation Program Create a quadratic equation in standard form: ax^2 + bx + c = 0 Enter the values of a, b, and c: 1 4 4 Quadratic equation created: 1x^2 + 4x + 4 = 0 Discriminant of the Quadratic equation is: 0 The roots are, x1 = -2, x2 = -2 The equation entered had one real root Do you wish to continue? (y/n): y
Background image