![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_largeCoverImage.gif)
(General math) a. Write a C++
b. How do you know the result your program produced is correct?
c. After verifying the output your program produces, modify it to determine the slope of the line connecting the points (2,10) and (12,6).
d. What do you think will happen if you use the points (2,3) and (2,4), which results in a division by zero? How do you think this situation can be handled?
e. If your program doesn’t already do so, change its output to this:
The value of the slope is xxx.xx
The xxx.xx denotes placing the calculated value in a field wide enough for three places to the left of the decimal point and two places to the right of it.
(a)
![Check Mark](/static/check-mark.png)
Program plan: -
Variables
used in the following program are given below: -
- line_slope: -To store the slope of the line
- a1, a2: - To store the coordinates point values of x1 and x2.
- b1, b2: - To store the coordinate point values of y1 and y2.
Formula used: - (b2 − b1)/(a2 − a1)
Program description: -The purpose of the C++ program is to determine the slope of the line connecting two points with the coordinates (3, 7) and (8, 12).
1
Explanation of Solution
Given information:
The slope between two points with the coordinates
Program:
//header file #include <iostream> //using the namespace usingnamespacestd; intmain() { //declaring the variables floatline_slope, a1 =3, a2 =8, b1 =7, b2 =12; //calculating the slope of the line connecting two points line_slope=(b2 - b1)/(a2 - a1); //displaying the slope of the line_slope cout<<"Slope of a line is: "<<line_slope<<endl; //return statement return0; }
Explanation:
The above code is used to calculate the slope of a line connecting the two points.
Firstly, declaring the variables of float data type. The variable line_slope will store the slope of the line, a1, a2 and b1, b2 is used to store the coordinates point values of x1, x2 and y1, y2.
The slope of a line is calculated by the given formula
Sample output: -
(b)
![Check Mark](/static/check-mark.png)
To verify the result of the program is correct.
Explanation of Solution
Given information: formula to calculate the slope: -
Slope of the line is 1
Explanation:
Now, calculating the slope of the line by manual calculating to verify the result of the above program.
Since, the slope of the line is 1.
Hence, verified
(c)
![Check Mark](/static/check-mark.png)
To modify the program of exercise by changing the value of coordinates point values.
Explanation of Solution
Given information:formula to calculate the slope: -
a1 = 2, a2 = 12 and b1 = 10, b2 = 6
Program:
//header file #include <iostream> //using the namespace usingnamespacestd; intmain() { //declaring the variables floatline_slope, a1 =2, a2 =12, b1 =10, b2 =6; //calculating the slope of the line connecting two points line_slope=(b2 - b1)/(a2 - a1); //displaying the slope of the line_slope cout<<"Slope of a line is: "<<line_slope<<endl; //return statement return0; }
Sample output: -
Explanation:
The slope of a line is calculated by same formula as used in the exercise 1.a
In the above program only the value of the coordinates point has changed.
(d)
![Check Mark](/static/check-mark.png)
To determine the situation while using the points (2, 3) and (2, 4) and the denominator part becomes zero.
Explanation of Solution
Given information:New coordinates point values: - (2, 3) and (2, 4)
Explanation:
While calculating the slope of a line where the coordinates point values are (2, 3) and (2, 4)thanthe values of x1, and x2 are 2 same and the values of y1, and y2 are 3 and 4,here the denominator value is zero as the expression (x2-x1) is equal to zero.
In this case, the value of the slope will be infinite. This situation can be handled by using a conditional statement given below: -
//header file #include <iostream> //using the namespace usingnamespacestd; intmain() { //declaring the variables floatline_slope, a1 =2, a2 =2, b1 =3, b2 =4; //calculating the slope of the line connecting two points line_slope=(b2 - b1)/(a2 - a1); //displaying the slope of the line_slope cout<<"Slope of a line is: "<<line_slope<<endl; //to check when the denominator is equal to zero if((a2 - a1 ==0)) { //message cout<<"The slope of the line is infinite."<<endl; } //return statement return0; }
Sample output: -
(e)
![Check Mark](/static/check-mark.png)
To make changes in the above program so that the output is produced in the given format: xxx.xx
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.267<<"|";
Explanation of Solution
Given information:The format of the output is xxx.xx
Program:
#include <iostream> #include <iomanip> //using the namespace //for using the standard I/O usingnamespacestd; intmain() { //declaring the variables //as per the requirement floatline_slope, a1 =12, a2 =7, b1 =8, b2 =3; //calculating the slope //by usinf the given formula line_slope=(b2 - b1)/(a2 - a1); //displaying the slope and settingthe format of output as xx.xxx //the width is set to 6 and the number of digits after decimal is //set //to 2 cout<<"The value of the slope is "<<setw(6)<<setiosflags(ios::fixed )<<setprecision(2)<<line_slope<<endl; //return statement return0; }
Sample output: -
Want to see more full solutions like this?
Chapter 3 Solutions
C++ for Engineers and Scientists
- Compare the security services provided by a digital signature (DS) with those of a message authentication code (MAC). Assume that Oscar can observe all messages sent between Rina and Naseem. Oscar has no knowledge of any keys but the public one, in the case of DS. State whether DS and MAC protect against each attack and, if they do, how. The value auth(x) is computed with a DS or a MAC algorithm. In each scenario, assume the message M = x#####auth(x). (Message integrity) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message M, and then sends M in cleartext to Naseem. Oscar intercepts the message and replaces “Mark” with “Oscar.” Will Naseem detect this in the case of either DS or MAC? If yes, how will Naseem detect it? If not, why? (Replay) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message…arrow_forwardI need to resolve the following....You are trying to convince your boss that your company needs to invest in a license for MS-Project (project management software from Microsoft) before beginning a systems project. What arguments would you give her?arrow_forwardWhat are the four types of feasibility? what is the issues addressed by each feasibility component.arrow_forward
- I would like to get ab example of a situation where Agile Methods might be preferable versus the traditional SDLC? What are the characteristics of this situation that give Agile Methods an advantage?arrow_forwardWhat is a functional decomposition diagram? what is a good example of a high level task being broken down into tasks in at least two lower levels (three levels in all).arrow_forwardWhat are the advantages to using a Sytems Analysis and Design model like the SDLC vs. other approaches?arrow_forward
- 3. Problem Description: Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea() that returns the area of the circle. • A method getPerimeter() that returns the perimeter of the circle. • • • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b). A method overlaps (Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. р O со (a) (b) (c)< Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another…arrow_forward1. Explain in detail with examples each of the following fundamental security design principles: economy of mechanism, fail-safe default, complete mediation, open design, separation of privilege, least privilege, least common mechanism, psychological acceptability, isolation, encapsulation, modularity, layering, and least astonishment.arrow_forwardSecurity in general means the protection of an asset. In the context of computer and network security, explore and explain what assets must be protected within an online university. What the threats are to the security of these assets, and what countermeasures are available to mitigate and protect the organization from such threats. For each of the assets you identify, assign an impact level (low, moderate, or high) for the loss of confidentiality, availability, and integrity. Justify your answers.arrow_forward
- Please include comments and docs comments on the program. The two other classes are Attraction and Entertainment.arrow_forwardObject-Oriented Programming In this separate files. ent, you'll need to build and run a small Zoo in Lennoxville. All classes must be created in Animal (5) First, start by building a class that describes an Animal at a Zoo. It should have one private instance variable for the name of the animal, and one for its hunger status (fed or hungry). Add methods for setting and getting the hunger satus variable, along with a getter for the name. Consider how these should be named for code clarity. For instance, using a method called hungry () to make the animal hungry could be used as a setter for the hunger field. The same logic could be applied to when it's being fed: public void feed () { this.fed = true; Furthermore, the getter for the fed variable could be named is Fed as it is more descriptive about what it answers when compared to get Fed. Keep this technique in mind for future class designs. Zoo (10) Now we have the animals designed and ready for building a little Zoo! Build a class…arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report. 2. [20 pts] Student A B will enjoy his picnic on sunny days that have no ants. He will also enjoy his picnic any day he sees a hummingbird, as well as on days where there are ants and ladybugs. a. Write a Boolean equation for his enjoyment (E) in terms of sun (S), ants (A), hummingbirds (H), and ladybugs (L). b. Implement in Logisim, the logic circuit of E function. Use the Circuit Analysis tool in Logisim to view the expression, include an image of the expression generated by Logisim in your report. 3.[20 pts] Find the minimum equivalent circuit for the one shown below (show your work): DAB C…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)