Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are 2 question that i wanna ask you. Please notice that this is all C++. S

ID: 3723538 • Letter: T

Question

There are 2 question that i wanna ask you. Please notice that this is all C++.

Secondly, write function to add a constant to every array element

6.21 HW11-01: Distance between two points Given two points (x1, y1) and (x2, y2), the distance between this points is defined as the square root of (x2-x1)A2 + (y2-y1)12. Write a function distance(x1, y1, x2, y2) that returns the distance between the given points. The main0 function is written for you your job is to write the distance function. Start by reviewing the code for "main.cpp which is visible in the editor panenote that this code is read-only you cannot modify it). Notice that the main program inputs two points (x1, y1) and (x2, y2), calls distance to compute the distance, and then outputs this result. Above the editor pane you'll see the text "Current file: main.cpp, with a little drop-down arrow to the right. Click the drop-down and select functions.cpp". Then, to avoid a bug in some web browsers, please immediately click the link "Load default template.... You only need to do this once, the first time you view the file Implement the function. To test your work in Develop mode, supply two points in the following format 0,0 10,10 Each point is on a line by itself, with no spaces. In this case the output should be Distance: 14.1421

Explanation / Answer

/**
function :distance
The function distance that takes four integer
values and then returns the distance between
two points.*/
double distance(int x1,int y1,int x2,int y2)
{
   //declare dist=0
   double dist=0;
   //calculate the distance between two points
   //(x1,y1) and (x2,y2)
   dist=sqrt(float(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

   //returns dist value
   return dist;
}
--------------------------------------------------------------------------------------
//Sample main.cpp
//main.cpp
#include<iostream>
#include<math.h>
using namespace std;
double distance(int x1,int y1,int x2,int y2);
int main()
{
   int x1,y1,x2,y2;
   cout<<"Enter x1,y1,x2 and y2 :";
   cin>>x1>>y1>>x2>>y2;
   cout<<"Distance between two points "<< distance(x1,y1,x2,y2)<<endl;

   system("pause");
   return 0;
}
/**The function distance that takes four integer
values and then returns the distance between
two points.*/
double distance(int x1,int y1,int x2,int y2)
{
   //declare dist=0
   double dist=0;
   //calculate the distance between two points
   //(x1,y1) and (x2,y2)
   dist=sqrt(float((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));

   //returns dist value
   return dist;
}


------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
/**
Function :add
The function add that takes integer array,
size of the array , and a constant value,c
and then add c value to the array,A at index, i*/
void add(int A[], int N, int c)
{
   //declare i as integer
   int i;
   //run for loop till i <N,size
   for(i=0;i<N;i++)
       //add c value to A at index i
       A[i]=A[i]+c;
}

--------------------------------------------------------------------------------------------------
//Sample Output to test the program
//main.cpp
#include<iostream>
#include<math.h>
using namespace std;
void add(int A[], int N, int c);
void output(int A[], int N);
int main()
{
  
   int N=3;
   int A[]={88,92,6};

   add(A,N,12);
   output(A,N);

   system("pause");
   return 0;
}
/**The function add that takes integer array,
size of the array , and a constant value,c
and then add c value to the array,A at index, i*/
void add(int A[], int N, int c)
{
   //declare i as integer
   int i;
   //run for loop till i <N,size
   for(i=0;i<N;i++)
       //add c value to A at index i
       A[i]=A[i]+c;
}
//Helper method to output the array on console
void output(int A[], int N)
{
   for(int i=0;i<N;i++)
   {
       cout<<A[i];
       if(i<N-1)
           cout<<",";
   }
}