Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need answer to this one below only! please provide both screen shots of input and out put of this question below Consider a simple OOP

image text in transcribed
image text in transcribed
image text in transcribed
need answer to this one below only! please provide both screen shots of input and out put of this question below
image text in transcribed
Consider a simple OOP application, written in Java, which defines a PythogoreanTriple class and tests it with a driver. A Pythagorean Triple is a set of three numbers which could be the three sides of a possible right triangle. In this example, it is possible for two instances of my PythTriple class to be equivalent, but with side A and side B reversed, but this is not. important for this purpose. PythTriple.java: package pythex: public class PythTriple I private double sideA; private double sideB; private double hyp: public void inputTwoSides(double sideAln, double sideBIn) [ side A = sideAln: sideB = sideBin; hyp = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2)); 1 public void inputOneSideAndHyp(double sideAln, double hypln) ( sideA = sideAln; hyp = hypln; sideB = Math.sqrt(Math.pow(hyp, 2) - Math.pow(sideA, 2)): ] @Override public String to String ? return "PythTriple [sideA = " + String format(" %5.3f, sideA) + ", sideB ="+ String. format(" %5.3F, sideB) + ". hyp = " + String. format("\%5.35"; hyp) + "]"; OOPPythDriver.java: package pythex; public class OOPPythDriver I public static void main(String[] args) \& PythTriple[] pyths = new PythTriple[3]; PythTriple pt1 = new PythTriple(); pt1.inputOneSideAnd Hyp (3,5) : PythTriple pt2 = new PythTriple(); pt2.inputOneSideAndHyp(1, Math.sqrt(2)); Pythiriple pt3 = new PythTriple); pt3.inputTwoSides (2,3); pyths[0] = pt1: pyths [1]=pt2; pyths [2]=pt3; for(PythTriple p: pyths) System.out.println(p): ) 1 Run this code, either from a command line or with Eclipse or some other IDE. Then go over the code until you understand it. Note that this small application relies heavily on OOP: a) The data is represented using a Java class, with one instance of the class representing one Pythagorean triple. b) The driver uses several of PythTriple's instance methods. Assignment: Write a similar application in C, which requires you to do it without using OOP. - Your entire application should be in one code file. - Represent the Pythagorean triples with a 33 array of doubles. - Write a function similar to the inputTwoSides method in the OOP version. This method should take values for side A, side B, and an array row index, calculate the hypotenuse, and add the values to the 2D array at the specified row. For example, if this method is called with parameters 3,4 , and 0 , it will set triples [0][0] to 3 , triples [0][1] to 4, and triples[0] [2] to 5. - Write a function similar to the inputOneSideAndHyp method in the OOP version. - Write a main() method that uses the "same examples" used in my driver class and generates output formatted similarly to the output in the example. - The methods that do calculations should "not" produce any user output; the output must be done in main(). - You may use global scope for the array (ie, declare the array at the top of the file, outside any functions.) Array declaration syntax is slightly different in C than in Java. The declaration will look like this: double triples[3][3]: - The functions sqrt and pow are part of the math.h header file, so put this line of code right after the include for stdio.h: \#include math.hs - You can call these functions like this: - pow(base, exponent) for example, pow (2,3) will return 8 - sqrtinumber) for example, sqrt(4) will return 2 - Alist of printf formatting codes is available here: https:// mwwitutorialspoint.com/c standard library/c function printf.htm . Don't forget to prepend the \% (for example, %d for base 10 integer) - You will need to add -Im to the command to compile the program with the math library. For example, if the program is called impex.c, the command to compile it to an executable named impex is gec-Wall-std=c17 -o impex impex.c - Im Use gcc. "Don't" use g++, the C++ comniler Write a new version of the imperative programming exercise (involving Pythagorean Triples) in C, with these changes: - use an array of instances of a Pythagorean Triple struct instead of a two dimensional array - make sure the array is on the heap (use malloc) Paste your code and the output from a sample run of your program into the text window

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago