Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the previous exercise you wrote a C++ program to compute the slope of a line. For example, given the points (1, 3) and (4,

In the previous exercise you wrote a C++ program to compute the slope of a line. For example, given the points (1, 3) and (4, 10) input as follows:

1 3 4 10 

The program computes the slope and outputs both the points, and the resulting slope:

(1,3) (4,10) Slope: 2.33333 

Recall that the slope is defined as rise / run, or (y2-y1) / (x2-x1). In the previous exercise you were allowed to assume that the run would never be 0, thus avoiding division by 0. This assumption is no longer true.

Since division by 0 is mathematically undefined, your task in this assignment is to check for a run == 0.0, and output Slope: undefined in this case. Example: given the inputs

1 3 1 -3 

Your program should now output

(1,3) (1,-3) Slope: undefined 

In other words, your program should work as before except when the run is 0, in which case the output should be Slope: undefined. Hint: use an if-then-else statement to check the run, and decide whether to output the error message, or compute the slope and output. Feel free to read ahead to Chapter 3 (in particular section 3.1) for an overview of if-then-else statements.

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_2

Step: 3

blur-text-image_3

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago