Question

I need help writing the test case in C++ code can you help? This is apart...

I need help writing the test case in C++ code 
can you help? This is apart of my professors pseudo code for the project.

// TEST CASE 1
//
// DESCRIPTION
// Coefficients a and c are > 0 and b < 0 so the equation should be output as:
//
//     p(x) = 122.50000x^2 - 6.70000x + 3.00000 = 0
//
// where we note that the operator printed before b is subtraction and we
 actually output -b rather than b. Also
// this equation has complex roots so the program should output two complex
 numbers which are complex conjugates

//
// INPUT DATA
//a=122.5 b=-6.7 c=3
//
// EXPECTED OUTPUT
// The equation p(x) = 122.50000x^2 - 6.70000x + 3.00000 = 0 has two complex

 roots: root1 = 0.02735 + 0.15408i
// and root2 = 0.02735 - 0.15408i
//
// ACTUAL OUTPUT:
// The equation p(x) = 122.50000x^2 - 6.70000x + 3.00000 = 0 has two complex
 roots: root1 = 0.02735 + 0.15408i
// and root2 = 0.02735 - 0.15408i
//
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ program for Test Case 1

#include <iostream>
#include <cmath> // including cmath library to call sqrt() function

using namespace std;

int main()
{
double a, b, c, discriminant, imaginary, real; // Variable decleration
// sequence of cout and cin to get the input data
cout<< "INPUT DATA\na=";
cin >> a;
cout << "b=";
cin >> b;
cout << "c=";
cin >> c;
// Computing the discriminant, discriminant< 0 so multiply with -1 to compute squart
discriminant = b*b-4*a*c;
imaginary = sqrt(discriminant*-1)/2/a; // Computing the imaginary part of the root
real = -1*b/2/a; // Computing the real part of the root
// Printing the required informations to the output
printf("The equation p(x) = %0.5fx^2 - %0.5fx + %0.5f = 0 has two complex roots:",a,-1*b,c);
printf("root1 = %0.5f + %0.5fi\n root2 = %0.5f - %0.5fi \n", real, imaginary, real, imaginary);
}

Screen shot of the code

SAMPLE OUTPUT OF THE CODE

REMARK

The program is compiled using g++ in Linux system.

Add a comment
Know the answer?
Add Answer to:
I need help writing the test case in C++ code can you help? This is apart...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do...

    Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do on the imports... pure code.. 3.) numbers are float - not integer. Here's the prompt: (Algebra: solve quadratic equations) The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac)) / (2a) and r2 = (-b - sqrt(b^2 - 4ac)) / (2a) b^2 - 4ac is called...

  • MATLAB HELP : Create a MATLAB function starting as follows:- Function [root1,root1] = quadraticroots (a,b,c) to...

    MATLAB HELP : Create a MATLAB function starting as follows:- Function [root1,root1] = quadraticroots (a,b,c) to find the roots of a quadratic function. To test your function find the roots of the following equation:- X^2+5x+6=0 Submit the complete listing and results of a run with the variable a=1,b=5 and c=6. Your file should contain at least the following:- Purpose of the function, Description of the input and output variables, Call statement(s), PLEASE SHOW FULL SCRIPT OF THE MATLAB with results...

  • Java Programming Question. I am writing a code to calculate the roots of the quadratic equation...

    Java Programming Question. I am writing a code to calculate the roots of the quadratic equation based on the values of the coefficients A, B, and C. I am supposed to enter 5 values for each coefficient, and the output should be five different answers (see example) using a for loop and if else statements. However, when I run my code, I am only able to enter one value for each coefficient and the output is one answer repeated five...

  • Need help with number 3, thanks! isplays l itnuml is less than num2. 2. (50+30- 80...

    Need help with number 3, thanks! isplays l itnuml is less than num2. 2. (50+30- 80 Points) Write a MATLAB function numcomp502 (numl, num2) that takes two numbers numl and as input and returns num3 as output, such that num3 is equal to 0, 1, and-1 depending on whether numl is equal to, greater than or less than num2 respectively. Test your code with the pairs (10, 5), (-3,-3), and (2, 10) as input. Attach a screen-shot. 3. 80 Points...

  • *****THIS IS FOR MY PYTHON CLASS. PLEASE HELP***** { "cells": [ { "cell_type": "markdown", "metadata": {},...

    *****THIS IS FOR MY PYTHON CLASS. PLEASE HELP***** { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### CS 497 Lab 1\n", "\n", "\n", "### Instructions\n", "0. Rename this file username_lab1. **Not literally, yourName_lab1 (technically correct, the best kind of correct!) but use your BU ID to fill in yourName.** If I was submitting this lab, it would be called dbrennan_lab1.\n", "1. Read all instructions carefully, ask questions if anything is confusing. \n", "2. Fill in the code/text blocks...

  • I need help writing the Verilog Design code for this test bench. I have to calculate...

    I need help writing the Verilog Design code for this test bench. I have to calculate the dot product of two 8-bit vectors a and b. I have listed the test bench below: // Code your testbench here module test_VVM; wire [3:0] value; wire done; reg clk, rst; reg [7:0] a, b; initial begin a = 8'b11011101; b = 8'b11010111;    clk = 1'd0;   //at time 0    rst = 1'd0; //at time 0    rst = #2 1'd1; //at...

  • I need help writing a test bench for the following Verilog code module CU(IE, WE, WA,...

    I need help writing a test bench for the following Verilog code module CU(IE, WE, WA, RAE, RAA, RBE, RBA, ALU,                SH, OE, start, clk, reset, Ng5); //nG5 denotes (N>5);    input start, clk, reset;    output IE, WE, RAE, RBE, OE;    output [1:0] WA, RAA, RBA, SH;    output [2:0] ALU;       input wire Ng5;    reg [1:0] state;    reg [1:0] nextstate;    parameter S0 = 3'b000;    parameter S1 = 3'b001;...

  • C++ programming language , I need help writing the code . Please explain if you can...

    C++ programming language , I need help writing the code . Please explain if you can . Exercise 10: Unit conversion (10 points) Write a console program that converts meters into feet and inches. The program starts by asking the user for a measurement in meters. The program should accept a floating point number. After getting the number, the program computes the number of feet and inches equal to the specified number of meters. The program outputs feet and inches...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT