Question

Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class...

Pseudocode and PYTHON source code, thanks!

Program 1: Design (pseudocode) and implement (source code) a class (name it QuadraticEquation) that represents a quadratic equation of the form of ax2+ bx + x = 0. The class defines the following variables and methods:

  1. Private data field a, b, and c that represent three coefficients.
  2. A constructor for the arguments for a, b, and c.
  3. Three get methods for a, b, and c.
  4. Method getDiscriminant()returns the discriminant value, which is disc = b2 – 4ac.
  5. Method getRoot1() returns first root if the discriminant is not negative. First root is defined as

                    R1 = (-b + SquareRoot (disc) ) / 2a

  1. Method getRoot2() returns second root if the discriminant is not negative. Second root is defined as

                    R2 = (-b - SquareRoot (disc) ) / 2a

Note that if the discriminant values is negative, the roots are Undefined.

Write a test program (name it testEquation) to create objects and test the class methods. Organized your output following these sample runs.

Sample run 1 for 3x2+ 8x + 4:

a = 3
b = 8

c = 4

Root 1 = -0.6666666666666666

Root 2 = -2.0

Sample run 2 for 3x2+ 4x + 8:

a = 3
b = 4

c = 8

Root 1 is Undefined

Root 2 is Undefined

Sample run 3 for 2x2+ 8x + 2:

a = 2
b = 8

c = 2

Root 1 = -0.2679491924311228

Root 2 = -3.732050807568877

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class QuadraticEquation:
    def __init__(self, a, b, c):
        self.__a = a
        self.__b = b
        self.__c = c

    def get_a(self):
        return self.__a

    def get_b(self):
        return self.__b

    def get_c(self):
        return self.__c

    def getDiscriminant(self):
        return self.__b**2 - 4*self.__a*self.__c

    def getRoot1(self):
        return (-self.__b + (self.getDiscriminant()) ** 0.5) / (2 * self.__a)

    def getRoot2(self):
        return (-self.__b - (self.getDiscriminant()) ** 0.5) / (2 * self.__a)


def main():
    a = float(input("Enter value of a: "))
    b = float(input("Enter value of b: "))
    c = float(input("Enter value of c: "))
    q = QuadraticEquation(a, b, c)

    print("a = " + str(a))
    print("b = " + str(b))
    print("c = " + str(c))
    if q.getDiscriminant() > 0:
        print("Root 1 = " + str(q.getRoot1()))
        print("Root 2 = " + str(q.getRoot2()))
    elif q.getDiscriminant() == 0:
        print("Root 1 = " + str(q.getRoot1()))
        print("Root 2 is Undefined")
    else:
        print("Root 1 is Undefined")
        print("Root 2 is Undefined")


main()

Add a comment
Know the answer?
Add Answer to:
Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class...
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
  • PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name...

    PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students’ grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a...

  • Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the...

    Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the following 3 methods: Method isValid() returns true if the sum of the width and height is greater than 30 Method Area() returns the area of the rectangle if it is a valid rectangle Method Perimeter() returns the perimeter of the rectangle if it is a valid rectangle The main method of MyRectangle prompts the user to enter the width and height of a rectangle...

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code)...

    PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • Do this in Python please Program 2: Design (pseudocode) and implement (source code) a program (name...

    Do this in Python please Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts...

  • IN PYTHON the original problem was Design (pseudocode) and implement (source code) a program (name it...

    IN PYTHON the original problem was Design (pseudocode) and implement (source code) a program (name it WeeklyHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers’ daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers...

  • java code Design a class named QuadraticEquation for a quadratic equation with real coefficients ax? +...

    java code Design a class named QuadraticEquation for a quadratic equation with real coefficients ax? + bx + x = 0 where a = 0. The class contains: (a) Private data fields a, b, and c that represent three coefficients. (b) A constructor taking arguments for a, b, and c. (c) Getter and setter methods for each attribute field. (d) A method named getDiscriminant() that returns the discriminant, 62 - 4ac. (e) A method named hasReal Solution that determines If...

  • IN PYTHON ONLY!!! Program 2: Design (Pseudocode) and implement (Source Code) a program that asks the...

    IN PYTHON ONLY!!! Program 2: Design (Pseudocode) and implement (Source Code) a program that asks the user for their height (in inches), weight (in pounds), age and gender. Use loops to validate user input and to continue running for a new user until a sentinel value is entered. Ask them to select their approximate level of exercise each week from the options below, then determine and print their allowed daily caloric intake using their BMR: Female BMR = 655+(4.35 *...

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
ADVERTISEMENT