Question
Please help code in c++ and use the answers you get from question 1 and 2 into the 3rd answer! Question 1 is first, question 2 is in the middle, question 3 is last


Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rr
Multi-Dimensional Distance Part 1 (5 pts) Write a function only (no main) that takes two arrays of type double and assume the
Main (10 pts) Declare two arrays and make them size 3. Ask the user if they would like to calculate a distance. Loop as long
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your code:

#include<iostream>
#include<cmath>
using namespace std;
double InputArray(double arr[],int size)    // function for question 1
   {  
       int i,input;
       for(i=0;i<size;i++)
       {
           std::cout<<"\nEnter a number :";
           std::cin>>input;
           while(1)
           {
               if(input>=-100 && input<=100)
               {
                   arr[i]=input;
                   break;      
               }  
               else
                   std::cout<<"\nPlease enter number in the given range -100 to 100 (inclusive) :";
                   std::cin>>input;  
           }  
       }      
   }
double Distance(double a[],double b[])   //function for question 2
{
   double d,k,l,m;
   k=pow((a[0]-b[0]),2); // calculates the power by 2
   l=pow((a[1]-b[1]),2);   // calculates the power by 2
   m=pow((a[2]-b[2]),2);   // calculates the power by 2
   d=sqrt((k+l+m));        //calculate squareroot.
   return d;
}
int main()   //answer for question 3
{
   char decision;
   double kvm,f;
   while(1)
   {
       double x[3],y[3];
       InputArray(x,3); //calling InputArray function
       InputArray(y,3); //calling InputArray function
       std::cout<<"\nWould you like to calculate the distance between two vectors (y/n):";  
       std::cin>>decision;
       if(decision=='y')
       {
           kvm=Distance(x,y); //calling decision function.
           std::cout<<"distance is:"<<kvm;  
           f=fabs(kvm);
           if(f>0.0001 && f<10.0)
               std::cout<<"\nTarget in range!";
       }
       else
           break;
   }  
}

Output:

Enter a number :1 Enter a number :2 Enter a number:-20e Please enter number in the given range -100 to 100 (inclusive) :3 Ent

---------- Thank you ------------

Add a comment
Know the answer?
Add Answer to:
Please help code in c++ and use the answers you get from question 1 and 2...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • This is a C++ question we do not use namespace std at the beginning of the...

    This is a C++ question we do not use namespace std at the beginning of the program 9. Arrays: Functions and Reading From File Although this code is a little long, the strategy is straightforward and it will really help you practice functions. I have provided a large amount of detail to help you out. In a nutshell, you're going to read some numbers from a file (into an array) and then ask the user for a number that will...

  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

  • only use the most basic C++ code and utilize fabs and sqrt function from the cmath...

    only use the most basic C++ code and utilize fabs and sqrt function from the cmath library. please stick to iostream & cmath library only. use the given example points (3,-4) . please try to follow the instructions. thanks in advance. The distance d from a point M(x, y) to a line ax + by + c = 0 is given by: _|Axo + By + c VA2 + B2 Write a program to determine the distance of a point...

  • Need the c code please, also please only use <stdio.h> library. Simple code please Define a...

    Need the c code please, also please only use <stdio.h> library. Simple code please Define a struct with teg Capacitor that holds the following Information about a capacitor: Model number (e.g. 11-123U), capacitance (e.g. 1000 u.f), voltage (e.g. 2.5 V), cost {$6.50} Create your main program file capacltorsInfac. Declare two variables of type struct Capacitor and populate them with the following values: First' variable: model Is 11-123U, capacitance Is 100, voltage Is 25 and cost Is $6.00 Second variable: model...

  • 1.You are to write a program name search.java that will do the following: 2.You are to...

    1.You are to write a program name search.java that will do the following: 2.You are to create 3 arrays - prompt the user for a number that is greater than 100 that will serve as the size for the arrays (all 3 arrays will have the same user input size). Call them A, B & C. 3.Generate this amount of random numbers to fill these arrays – the random numbers must range from 1 to 99. 4.Write 1 sequential search...

  • Please help me to make this c programming code!! Thank you!! Concatenation of two strings using...

    Please help me to make this c programming code!! Thank you!! Concatenation of two strings using pointers Step 1: Ask the user to input ni,n2 and create two character arrays (strings) with ni, n2 size using malloc. Step 2: create a 3rd array using malloc of size(n1+n2). Step 3: Ask the user to input String1 (of size nl) Step 4: Ask the user to input String2 (of size n2) Step 5: concatenate the two arrays and store them in String3...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT