Documente Academic
Documente Profesional
Documente Cultură
CE 2-2
Application
To utilize the general knowledge, you have gained in this lesson, create a program that
will find all roots of a quadratic equation. Following the quadratic equations below,
y = ax2 + bx + c
your program should ask your user an input value for the coefficients a, b and c. The program should
display all roots of a quadratic equation using the formula,
𝒚 = −𝒃±√𝒃𝟐−𝟒𝒂𝒄/𝟐𝒂
The program should also display “Roots are real and different” if the determinant is
greater than 0, “Roots are real and same” if the determinant is equal to 0, and “Roots
//Ruthie Tabanguil
//MODULE 6 MACHINE PROBLEM ASYNCHRONUOUS CLASS
//M6L1APPP1
#include <iostream>
#include <cmath>
using namespace std;
int main() {
if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
x1 = -b/(2*a);
cout << "x1 = x2 =" << x1 << endl;
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
}
return 0;
}
MODULE 6: FUNCTIONS 6.2 Void Functions
Application
Write a C++ code for a void function that receives an input value from the main program. This function
should compute and display the equivalent factorial number.
If the input value is less than 0 it should display "Wrong value", if the input value is equal to 0 it should
display "Terminating condition", otherwise it should compute and display the equivalent factorial
number.
//Ruthie Tabanguil
//MODULE 6 MACHINE PROBLEM ASYNCHRONUOUS CLASS
//M6L2APPP1
#include<iostream>
using namespace std;
//function calling//
factorial (n);
return 0;
}
MODULE 6: FUNCTIONS 6.3 Value Returning Functions
Write a C++ code for a value returning function that receives an input values from the main program.
This function should compute and display depending on the basic mathematical operations chosen by
the user. The program should not be case sensitive for an input options. If the user input a wrong
character for the option, it should display “Wrong options!”.
//Ruthie Tabanguil
//MODULE 6 MACHINE PROBLEM ASYNCHRONUOUS CLASS
//M6L3APPP1
//program that will compute and display an area of a rectangle//
#include <iostream>
using namespace std;
// function prototype
double area(double length, double width);
DRIVE LINK:
https://drive.google.com/drive/folders/1qie-yu8bvLxRmj3r23OSRexKHc0tw1WD?usp=sharing