WRITE AN INTERACTIVE PROGRAM that allows the user to enter a

WRITE AN INTERACTIVE PROGRAM

that allows the user to enter (at least two)....UP-TO 15 vectors that are to be added........display the resultant on the screen

study in your text the if statement

[use the if statement to make sure the user only enteres between two and 15 vectors] **Comments all the line

use , , ,< math.h> as a header file, do not use any other

one of my friend did it like below, i think all patterns are good here, but professor asked to use if statement  to make sure the user only enteres between two and 15 vectors

***please follow teachers hint, do not do it other way, if you do it otherway, its not going to help me, professor very strict*** ;(

Professor hint:

***Please follow his direction***

Comments all The line*** do not use any other header than he used***

*** i asked this question in the morning, someone just copy and paste teachers hint as answer!!! i need help please ASAP

Thank you.

Solution

/*
adding two vectors
h thomas tucker
2017 spring EGR111

*/
using namespace std;


#include<iostream>
#include<math.h>

#define PI 3.14159265

//functional prototype
void get_data();
void resultant();


int N;
double M=0, K=0;
float mag[20], dir[20];


int main()
{
cout<<\"how many vectors are you going to enter? \"; cin>>N;
if(N>2 && N<15)
{
get_data();
resultant();
//system(\"pause\");
return 0;
}
else{
cout<<\"You must give vectors between 2 and 15\"<<endl;
}

//system(\"dpause\");
return 0;

}

void get_data()
{
int i;
for(i=0; i<=N-1; i++)
{
cout<<\"enter \"<<i+1<<\"th vectors magnitude: \"; cin>>mag[i];
cout<<\"enter \"<<i+1<< \"th vectors direction: \"; cin>>dir[i]; // I assume direction is in the degrees
}

}

void resultant()
{
for(int i=0;i<=N-1;i++){
M += mag[i] * cos((dir[i] * PI) / 180.0 ); //M holds the horizontal component
K += mag[i] * sin((dir[i] * PI) / 180.0 ); //K holds the vertical component
}
double res_mag, res_dir;
//using pythagorean theorem to find the resultant magnitude
res_mag = sqrt(pow(M, 2) + pow(K, 2));
//The resultant angle is arc tangent of y magnitude divided by x magnitude
res_dir = atan(K / M) * 180 / PI; //converting resultant radians to degrees
cout<<\"The resultant of two vectors is \"<<res_mag<<\"+\"<<\"(\"<<res_dir<<\")\"<<\"i\"<<endl;
}

Please refer to the ideone here : http://ideone.com/nrcTZR (with Sample Output)

I assume that the directions for the vectors will be given in the degrees.

I have commented out system calls please enable if you want.

I have mentioned the detail comments for every line.

WRITE AN INTERACTIVE PROGRAM that allows the user to enter (at least two)....UP-TO 15 vectors that are to be added........display the resultant on the screen st
WRITE AN INTERACTIVE PROGRAM that allows the user to enter (at least two)....UP-TO 15 vectors that are to be added........display the resultant on the screen st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site