Question

*** C++ only, Every code researched so far keeps adding 'sprt' but the system rejects it....

*** C++ only, Every code researched so far keeps adding 'sprt' but the system rejects it. If I need that (try to avoid if possible) then I also need to know how to add 'sprt' to be a called upon variable.

Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is:

Distance=(x2−x1)2+(y2−y1)2


Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0.

code-------------------------------------------

#include <iostream>
#include <cmath>
using namespace std;

int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;

xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;

cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;

/* Your solution goes here */

cout << pointsDistance << endl;

return 0;
}

Homework Answers

Answer #1

/* WITHOUT SQRT*/

#include <iostream>
#include <cmath>
using namespace std;

int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;

xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;

cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;

/* Your solution goes here */
pointsDistance = (double)(pow(x2-x1,2)+pow(y2-y1,2));
double sqrt = pointsDistance / 2;
int temp = 0;


while(sqrt != temp){
temp = sqrt;
sqrt = ( pointsDistance/temp + temp) / 2;
}
pointsDistance = sqrt;
cout << pointsDistance << endl;

return 0;
}

/* WITH SQRT */

#include <iostream>
#include <cmath>
using namespace std;

int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;

xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;

cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;

/* Your solution goes here */
pointsDistance = (double)sqrt(pow(x2-x1,2)+pow(y2-y1,2));

cout << pointsDistance << endl;

return 0;
}

/* PLEASE UPVOTE */

Know the answer?
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
Similar Questions
CISP 400 C++ Programming    Please note, you are required to include the following when you...
CISP 400 C++ Programming    Please note, you are required to include the following when you use g++ to compile: -pedantic            For example:                                     g++ -pedantic filename.cpp This will give a warning if you attempt to use any non-standard feature in g++. You must correct your code so that you do not receive any warnings of this type. Log on to the Linux server. Create four files: Vector.h Vector.cpp VectorMain.cpp Makefile In Vector.h: //Student header here #ifndef VECTOR_H_DEF   //DEF: These...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put the result in st3 with a space separator. it has to be done using array representation of strings #include <iostream> using namespace std; #include <string> int main() { string st1,st2, st3; int c = 0, i =0;    cout << "Enter a string: "; cin >> st1; cout << "Enter another string: "; cin >> st2;    while (st1[c] != '\0'){ st3[c] = st1[c];...
How do I make this code not include negative numbers in the total or average if...
How do I make this code not include negative numbers in the total or average if they are entered? (C++) For example, if you enter 4, 2, and -2, the average should not factor in the -2 and would be equal to 3. I want the code to factor in positive numbers only. ----- #include using namespace std; int main() {    int x, total = 0, count = 0;       cout << "Type in first value ";   ...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
Implement the Calculator code, this's C++ /* Implement a calculator take the input for a character...
Implement the Calculator code, this's C++ /* Implement a calculator take the input for a character if character is "+", then it's going to take the input of two numbers and show the sum if character is "-", then it's going to take the input of two numbers and show the minus result if character is "*", then it's going to take the input of two numbers and show the product if character is "/", then it's going to take...
C++ Converting from binary to decimal. Here's what i have. it doesn't work yet unfortunately. Fix?...
C++ Converting from binary to decimal. Here's what i have. it doesn't work yet unfortunately. Fix? #include <conio.h> // For function getch() #include <cstdlib> // For several general-purpose functions #include <fstream> // For file handling #include <iomanip> // For formatted output #include <iostream> // For cin, cout, and system #include <string> // For string data type using namespace std; // So "std::cout" may be abbreviated to "cout" int main() {       int n;    int a[10], i;    int...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark...
There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark them in the code and explain the reason briefly in place. #include<iostream> using namespace std; int main() { cout<<”Please input the radius (in integer): ”>>endl; int 1var = 10, var=20; double area = 40; cin<< var; //get an input of the radius and store in var float continue; float const pi = 2.64; pi += 0.5; do { cout<<”The radius is ”<<”var”<<endl; //print the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT