enum Quadratic_Solution

PHOTO EMBED

Mon Jun 10 2024 10:40:07 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>
 // TODO: Declare a Quadratic_Solution enumerated type here:
enum Quadratic_Solution
{
    TWO_COMPLEX,
    ONE_REAL,
    TWO_REAL
};
enum Quadratic_Solution get_solution_type(float a, float b, float c);
void print_solution_type(enum Quadratic_Solution qs);

int main(void) 
{
  float a_coefficent = 0.0f;
  float b_coefficent = 0.0f;
  float c_constant = 0.0f;
  printf("y = ax^2 + bx + c\n");
  printf("a? \n");
  scanf("%f", & a_coefficent);
  printf("b? \n");
  scanf("%f", & b_coefficent);
  printf("c? \n");
  scanf("%f", & c_constant);
  enum Quadratic_Solution result = get_solution_type(a_coefficent,
    b_coefficent,
    c_constant);
  print_solution_type(result);
  return 0;
}
// TODO: Define the get_solution_type function here:
enum Quadratic_Solution get_solution_type(float a, float b, float c)
{
    float result = b * b - 4 * a * c;
    if(result>0)
    {
        return TWO_REAL;   
    }
    else if(result==0)
    {
        return ONE_REAL;
    }
    else
    {
        return TWO_COMPLEX;
    }
}
// TODO: Define the print_solution_type function here:
void print_solution_type(enum Quadratic_Solution qs)
{
    switch(qs)
    {
        case TWO_COMPLEX:
        {
            printf("Two complex solutions.\n");
            break;
        }
        case ONE_REAL:
        {
            printf("One real solution.\n");
            break;
        }
        case TWO_REAL:
        {
            printf("Two real solutions.\n");
            break;
        }
    }
}
content_copyCOPY

Objective Create a C program that uses an enumerated type to represent the different types of roots a quadratic equation can have. Implement functions to determine the type of roots and print it. Program Components Enumerated Type: Declare an enumerated type named Quadratic_Solution with three possible values: TWO_COMPLEX, ONE_REAL, TWO_REAL. Functions: get_solution_type(float a, float b, float c): Takes the coefficients of a quadratic equation as parameters and returns the type of roots as a Quadratic_Solution value. print_solution_type(enum Quadratic_Solution qs): Takes an enumerated type as a parameter and prints out the text description of the type of roots. Main Function: Prompt the user to enter the coefficients for a quadratic equation. Call get_solution_type() to find the type of roots. Call print_solution_type() to print the result. root = (-b + sqrt( b^2 - 4ac))/2a or (-b - sqrt( b^2 - 4ac))/2a b^2 - 4ac > 0, two real roots b^2 - 4ac = 0, one real root b^2 - 4ac < 0, no real roots For example: Input Result 1 2 1 y = ax^2 + bx + c a? b? c? One real solution.