Page 439 - Computer Software Application TP - Volume 1
P. 439
COMPUTER SOFTWARE APPLICATION - CITS
This VBA (Visual Basic for Applications) macro is designed to solve quadratic equations of the form ax² + bx +
c = 0 and display the roots and nature of the roots (real and equal, real and unequal, or imaginary) in an Excel
worksheet.
Here’s an explanation of the macro:
1 Variable Declarations:
• Three integer variables a, b, and c are declared to store the coefficients of the quadratic equation.
• Three single precision variables d, root1, and root2 are declared to store the discriminant and roots of the
equation.
2 User Input:
• The macro prompts the user to input the values of a, b, and c using InputBoxes.
3 Calculating the Discriminant:
• The discriminant d is calculated using the formula: b2- 4ac
• The calculated discriminant is rounded to 2 decimal places.
4 Displaying the Discriminant:
• The calculated discriminant is displayed in cell B6 of the Excel worksheet under the heading “Discriminant”.
5 Determining the Roots:
• The macro checks the value of the discriminant d to determine the nature of the roots.
• If d is equal to 0, there is one real root, which is calculated and displayed.
• If d is greater than 0, there are two real roots, which are calculated and displayed.
• If d is less than 0, the roots are imaginary.
6 Displaying the Roots:
• The roots, along with their nature, are displayed in cells A7, B7 (for root 1), and A8, B8 (for root 2) of the
Excel worksheet.
• If the roots are real and equal or real and unequal, the nature of the roots is displayed in cell B9.
Explanation Summary:
• The macro prompts the user for coefficients of a quadratic equation.
• It calculates the discriminant and determines the nature of the roots.
• The roots and their nature are displayed in an Excel worksheet.
This macro offers a handy tool for quickly solving quadratic equations and understanding their nature within Excel.
Related Exercises:
1 Develop a macro to perform temperature conversion( Celsius to Fahrenheit and Vice versa)
2 Develop a macro for interest calculation(I=PNR)
3 Develop a macro to do Simple Arithmatic Operations
424
CITS : IT & ITES - Computer Software Application - Exercise 70