There are 2 programs but they both are related in a way that first one depend on
ID: 3591757 • Letter: T
Question
There are 2 programs but they both are related in a way that first one depend on the second one. There is a way to write them both in one program but I need to have 2 seperate ones. Instructions are expllined below. Thank you for your time and work.
(PROGRAM 1). Create the program simple_quadratic.pl
#! /usr/bin/perl -lw
...
We want to write and test a program for solving a quadratic equation of the form: A*x2 + B*x + C = 0
Based on the input, use the quadratic formula to calculate and output the two roots.
x = [-B + square root (B2 – 4*A*C)] / (2*A)
Run a program few times using different combinations of A, B, and C. Note the different results you get from various combinations.
(PROGRAM 2). Create the program smart_quadratic.pl
Based on the program "simple_quadratic.pl" that you just created previously ,create another program and call it "smarter_quadratic.pl".
#! /usr/bin/perl -lw
...
Write a SMARTER version of "simple_quadratic.pl", one that can gracefully handle ANY combination of A, B, and C. Go through a few test running the program and note the results.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,d,x1,x2;
cout<<" A quadratic equation is given as: aX^2 + bX + c = 0";
cout<<" Enter a,b,c : ";
cin>>a>>b>>c;
getch();
}
d=(b*b)-(4*a*c);
if(d>=0){
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<" The roots of the quadratic equation are : "<<x1<<" and "<<x2;
}else{
d=d*(-1);
}
cout<<" The roots are imaginary!";
cout<<" The roots of the quadratic equation are : " <<(-b/(2*a))<<" + "<<(sqrt(d)/(2*a))<<"i and "<<(-b/(2*a))<<" - "<<(sqrt(d)/(2*a));
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.