Question

In: Computer Science

c++ programming: Given: Struct myq { double a,b,c };      X1= -b + sqrt(b*b-4 * a*...

c++ programming:

Given:

Struct myq

{

double a,b,c

};

     X1= -b + sqrt(b*b-4 * a* c)/2 *a;

      X2= -b- sqrt(b*b- 4 * a * c)/2 * a;

      X0f v= (-b)/( 2*a);

      a>0 if maximum otherwise it is minimum

       b*b – 4*a*c >0    two unrepeated roots

       b*b- 4 * a* c =0 two repeated roots

       b*b- 4 * a* c <0 two complex roots

  1. Write a function with an argument to calculate x1, make sure to return value
  2. Write a function with an argument to determine x2, with return value.
  3. Write s function with an argument to determine x of vertex with return value
  4. Write a function with an argument to determine max and min
  5. Write a function to determine the roots

Solutions

Expert Solution

Find the code for the above question below, read the comments provided in the code for better understanding. If found helpful please do upvote this.
Please refer to the screenshot of the code to understand the indentation of the code.

Code

#include <iostream>

#include <cmath>

using namespace std;

//structure defintion

struct myq

{

    double a, b, c;

};

//method which returns value of x1

double x1(myq st)

{

    return (-st.b + sqrt(pow(st.b, 2) - 4 * st.a * st.c)) / 2 * st.a;

}

//method which returns value of x2

double x2(myq st)

{

    return (-st.b - sqrt(pow(st.b, 2) - 4 * st.a * st.c)) / 2 * st.a;

}

//method which returns value of x of a vertex

double x_vertex(myq st)

{

    return -st.b / 2 * st.a;

}

//method which returns 1 for max and 0 for min

int max_min(myq st)

{

    return st.a > 0 ? 1 : 0;

}

//method to determine the roots

void determine_roots(myq st)

{

    double val = (pow(st.b, 2) - 4 * st.a * st.c);

    if (val > 0)

    {

        cout << "Two unrepeated roots";

    }

    else if (val == 0)

    {

        cout << "Two repeated roots";

    }

    else

    {

        cout << "Two complex roots";

    }

}

int main()

{

    //create a structure

    myq s1 = {2.0, 10.0, 3.0};

    //call the various methods

    cout << "\nX1 : " << x1(s1);

    cout << "\nX2 : " << x2(s1);

    cout << "\nX of vertex : " << x_vertex(s1);

    int max_mi = max_min(s1);

    if (max_mi == 0)

    {

        cout << "\nMinimum";

    }

    else

        cout << "\nMaximum";

    cout << "\nRoot Type : ";

    determine_roots(s1);

}

Screenshot

Output


Related Solutions

Show that the set of all real numbers of the form a+b sqrt(2)+c sqrt(3)+d sqrt(6),where a,b,c,d...
Show that the set of all real numbers of the form a+b sqrt(2)+c sqrt(3)+d sqrt(6),where a,b,c,d ∈Q, forms a subfield of R
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale...
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale temperature; }; Reading reading; // reading structure variable Write statements that will store the following data below, in the variable written above in C++ please Wind Speed: 37 mph Humidity: 32% Fahrenheit temperature: 32 degrees Centigrade temperature: 0 degrees
Given A*B*C and A*C*D, prove the corollary to Axion B-4.
Given A*B*C and A*C*D, prove the corollary to Axion B-4.
Given ?(?) = sqrt(3 + ? ) + 4. Use the definition of 4.4.3 to evaluate...
Given ?(?) = sqrt(3 + ? ) + 4. Use the definition of 4.4.3 to evaluate each of the area in the range [0, 6] if ? = 4. a) Find the area under the curve when ?? ∗ is the left endpoint of the subinterval. b) Find the area under the curve when ?? ∗ is the midpoints of the subinterval. c) Find the area under the curve when ?? ∗ is the right endpoint of the subinterval.
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;...
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;     int quantity;     bool equals(const Product&); }; how would you define the equals function so two products are equal if their names and prices are equal? a. bool equals(const Product& to_compare) {     return (name == to_compare.name && price == to_compare.price); } b. bool Product::equals(const Product& to_compare) {     return (name == to_compare.name || price == to_compare.price); } c. bool equals(const Product& to_compare)...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double area = 0;     area = width * length;     cout << "\n***maxArea called" << endl;          cout << "***       rectangleCount = " << Rectangle::rectangleCount << endl << endl;    } Compete this code to find the maximum area of rectangle between a,b,c
In C programming: Write a program that initializes an array-of-double and then copies the contents of...
In C programming: Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations: double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5}; double target1[5]; double target2[5]; copyarr(source, target1, 5);
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c b) a % b c) b **c d) b *= c 27. Given the following var_1 = 2.0 var_2 = "apple" var_3 = 'orange' var_4 = 4 Predict the output of the following statements or indicate that there would be an error. a) print (var_1) b) print (var_2) c) print ("var_3") d) print (var_1 / var_4) e) print (var_4 + var_3) f) print (var_2...
Make a function definition in C for the following: void insert (double *b, int c, double...
Make a function definition in C for the following: void insert (double *b, int c, double s, int pos); //Insert value s at position pos in array. //needs: // c > 0, pos >= 0, and pos <= c-1. Elements b[0]...b[c-1] exist. //this will do: //Elements from indexes pos up to c-2 have been moved up to indexes pos+1 up to c-1. The value s has been copied into b[pos]. //Note: the data that was in b[c-1] when the function...
Linearize by hand y = a(x1)b(x2)c and determine the coefficients a, b and c, and the...
Linearize by hand y = a(x1)b(x2)c and determine the coefficients a, b and c, and the coefficient of determination using the data below. x1 x2 y 1 1 3.48 1 2 5.87 2 3 27.35 3 2 43.75 4 5 134.92 6 8 377.38
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT