Create a program that implements the functions of a quadratic equation.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

I need a C code of this.

Create a program that implements the functions of a quadratic equation. I have also attached an image in what would the quadratic formula be. 

 

STRUCTURE DEFINITION OF A QUADRATIC EQUATION

 

typedef struct{

           float a;

           float b;

           float c;

}Quadratic;

Implement the following functions:

 

void discriminant(Quadratic *q, float a, float b, float c);

           - Initialize coefficients of Quadratic q.

 

int isImaginary(Quadratic *q);

           - Returns 1 if discriminant is less than 0, else returns 0.

 

float firstRoot(Quadratic *q);

           - Returns the first root of the equation.

 

float secondRoot(Quadratic *q);

           - Returns the second root of the equation.

 

void display(Quadratic *q);

-Prints the coefficients a, b, c.

 

int getValue(Quadratic q, int x);  

-Given value of x, substitute it in the quadratic

-example: 2x^2 + 3x + 3 ; x = 2; therefore getvalue will return 17.

The task is to implement the functions. And to create a main code. This is the current code.

typedef struct{
    float a;
    float b;
    float c;
} Quadratic;

void discriminant(Quadratic *q, float a, float b, float c);
int isImaginary(Quadratic *q);
float firstRoot(Quadratic *q);
float secondRoot(Quadratic *q);
void display(Quadratic *q);
int getValue(Quadratic q, int x);

 

Input

1. Value for a

2. Value for b

3. Value for c

4. Value for x

 

Output should be:

Enter·a: 2

Enter·b: 5

Enter·c: 3

Discriminant·is·not·Imaginary.

First·Root: -1.00

Second·Root: -1.50

Coefficients:

a: 2.00

b: 5.00

c: 3.00

Enter·value·of·x: 4

Equation: (2.00x^2) + (5.00x) + (3.00)

Solution: (2.00(4)^2) + (5.00(4)) + (3.00)

Result:·55

 

Another test case or another output should be:

Enter a: 1

Enter b: 2

Enter c: 3

Discriminant is Imaginary.

Can't calculate first root. Discriminant is Imaginary.

Can't calculate second root. Discriminant is Imaginary.

Coefficients: a: 1.00

b: 2.00

c: 3.00

Enter value of x: 4 Equation: (1.00x^2) + (2.00x) + (3.00)

Solution: (1.00(4)^2) + (2.00(4)) + (3.00)

Result: 27

 

Another test case or another  output should be:

Enter a: -5

Enter b: 4

Enter c: 2

Discriminant is not Imaginary.

First Root: -0.35

Second Root: 1.15

Coefficients:

a: -5.00

b: 4.00

c: 2.00

Enter value of x: 3

Equation: (-5.00x^2) + (4.00x) + (2.00)

Solution: (-5.00(3)^2) + (4.00(3)) + (2.00)

Result: -31

Quadratic formula:
Quadratic formula = -b+ vb*b-4*a*c
2*a
First root formula = -b+ vb* b-4*a*c
2* a
Second root formula = -b- vb*b-4*a*c
2*a
Transcribed Image Text:Quadratic formula: Quadratic formula = -b+ vb*b-4*a*c 2*a First root formula = -b+ vb* b-4*a*c 2* a Second root formula = -b- vb*b-4*a*c 2*a
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY