Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Function with output parameters
- //Add two vectors that are at right angles to each other
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- const double PI=3.14159265358979;
- void addVect (double&,int&,double,double); //use shorter format of prototype
- int main()
- {
- double aVect;
- double bVect;
- double rMag;
- int rDir;
- cout<<"Enter the magnitude of the horizontal vector A : ";
- cin>>aVect;
- cout<<"Enter the magnitude of the vertical vector B : ";
- cin>>bVect;
- addVect(rMag,rDir,aVect,bVect);
- cout<<setiosflags(ios::fixed)<<setprecision(1);
- cout<<"A + B yields resultant vector of magnitude "<<rMag<<endl<<"and direction "<<rDir<<" degrees"<<endl;
- return 0;
- }
- //
- //Add vectors a and b that are at right angles
- //a is horizontal, b is vertical, a>0, b>0
- //Express direction of resultant in whole degrees,
- //
- void addVect(double& rMagnitude, //output-magnitude of resultant
- int& rDirection, //output - direction of resultant in whole degrees
- double a, double b) //input - vectors at right angles
- {
- double rDirRadians; //direction of resultant in radians
- rMagnitude = sqrt(a*b+b*b);
- rDirRadians = atan(b/a);
- rDirection = int (180/PI*rDirRadians+0.5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement