Question

In: Computer Science

IN C++ LANGUAGE PLEASE::: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...

IN C++ LANGUAGE PLEASE:::

Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2]

Solutions

Expert Solution

PSEUDO CODE:

1. enter first point : (x1,y1) and second point: (x2,y2)
2. calculateDistance( x1,y1,x2,y2):
i) find difference of the x co-ordinates and square them  (x2-x1)^2
ii) find difference of the y co-ordinates and square them  (y2-y1)^2
iii) find sum of (i) and (ii).
iv) find square of the sum found in (iv)
3. print the distance calculated.

c++ code

#include <iostream>
#include <cmath>
using namespace std;
float calculateDistance(float x1, float y1, float x2, float y2)
{
   return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); // Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2]
}
int main()
{
   float x1,y1,x2,y2;
   cout << "\n Enter the first point:\t";
   cin>>x1>>y1;
   cout << "\n Enter the second point:\t";
   cin>>x2>>y2;
   float distance = calculateDistance(x1,y1,x2,y2);
   cout << "\n Distance between ("<< x1 <<"," <<y1<<") and ("<< x2 <<"," <<y2<<") is : "<<distance<<"units."<<endl;
   return 0;
}

/* OUPUT :

Enter the first point: 2 4

Enter the second point: 5 6

Distance between (2,4) and (5,6) is : 3.60555units.
*/


Related Solutions

JAVA ONLY. Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...
JAVA ONLY. Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs. Note: for C++, #include and then...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display the area and perimeter of a rectangle with width = 4 and height = 8.
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values...
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 your code and properly label the input prompts and the...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
C++ Question The aim of this assignment is to design and implement a computerized “Library Management...
C++ Question The aim of this assignment is to design and implement a computerized “Library Management System”. The system will be used in the back-office to manage the books in the library catalog and to keep track of the various users (borrowers) of the library. The system provides the following key functionalities: Books are characterized by a call number, a title, and a flag that indicates whether the book is currently ‘on-shelf’ (in the library) or ‘on-loan’. -Adding and removing...
Design an algorithm ( pseudocode or C ) to calculate the frequency of each of the...
Design an algorithm ( pseudocode or C ) to calculate the frequency of each of the vowels (lowercase and uppercase) in a text. The program will ask the user for a text, which will be entered by keyboard and will save, in a table (in%), the frequency of each of the vowels within the text, taking into account all the characters of the text. The text will end with the character '' # ''. Includes the emty sequence.
QUESTION 6 A single line comment in C++ language source code can begin with _____   ...
QUESTION 6 A single line comment in C++ language source code can begin with _____        a) // b) ; c) : d) /* QUESTION 7 What is the output of the following program? #include<iostream> using namespace std; class abc { public: int i; abc(int i) { i = i; } }; main() { abc m(5); cout<<m.i; } a)Garbage b)5        c)Compile Error d)None of the answers QUESTION 8 The following operator can be used to calculate the...
C++, Take this 3 pseudocode and transform them into C++ then implement them making a quick...
C++, Take this 3 pseudocode and transform them into C++ then implement them making a quick sort program using the function of the pseudocode that you changed to C++, also in the main the user need to put the array that he wants to do quick sort with. plz comment everything you do in details this is for a presentation 1. A first draft of pseudocode for the quick sort algorithm follows: // Sorts theArray[first..last]. quickSort(theArray: ItemArray, first: integer, last:...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample runs below. Sample run...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT