1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
const double basePower =10;
const double electron = -1.6*pow(10,-19);
const double proton =1.6*pow(10,-19);
double scalarProduct(vector<double> velocity, vector<double> magneticFeild);
int main()
{
double velocityOne;
double magneticFeildMagnitude;
double velocityOneTimePower;
char letterOne,letterTwo, letterThree, letterFour, letterFive,letterSix;
double power;
double answer;
char cont;
vector<double> veca(1);
vector<double> vecb(1);
//#1
cout << "This problem is without deflection,so Fnet = FB + FE=0.";
cout << "\nYou need to find the electric field and the vector. ";
cout << "\nremember FB is the vector of F";
cout << "\nwhich is equal to the q to the charge which is either the electron or proton.";
cout << "and your V is a vector and B is also a vector ";
cout << "\nEnter any letter or symbol to continue: ";
cin >> cont;
cout << endl;
cout << endl;
cout << "please enter the velocity of the electron or proton going in the direction : " << endl;
cin >> velocityOne;
cout << endl;
cout << "please enter the power that you want to use for the velocity, for example 10 to 2 power: ";
cin >> power;
cout << endl;
cout << "please enter magnitude of magnetic field that into the board :";
cin >> magneticFeildMagnitude;
cout << endl;
cout <<"please enter the letter that correspond with the problem in unit vector notation using i,j,k in the direction you wish to make them: ";
cin >> letterOne;
cout << endl;
cout <<"please enter the second letter that correspond with the problem in unit vector notation using i,j,k in the direction you wish to make them: ";
cin >> letterTwo;
switch(letterOne*letterTwo)
{
case 'i'*'j':
letterThree = 'k';
break;
case 'j'*'k':
letterThree = 'i';
break;
case 'k'*'i':
letterThree ='j';
break;
default:
break;
}
if(power > 0)
{
velocityOneTimePower = velocityOne*pow(basePower,power);
}
else if (power == 0)
{
velocityOneTimePower =velocityOne;
}
veca[0] = velocityOneTimePower;
vecb[0] =magneticFeildMagnitude;
answer =scalarProduct(veca,vecb) *electron;
cout << endl;
cout << endl;
cout<<"This give you the solution for FB=q*VxB: "<< answer << "N" << letterThree <<endl;
cout << "\nTo find the electric field with take the electron or proton and divide it by the answer form FB";
cout << "and the electric field is: " << answer/electron << "n/c" << letterThree << endl;
//problem 2
cout << endl;
cout << " Enter two vector point in unit vector notation"
cout << letterFive << letterSix
cout << endl;
switch(letterFive*letterSix)
{
case 'i'*'j':
letterFour = 'k';
break;
case 'j'*'k':
letterFour = 'i';
break;
case 'k'*'i':
letterFour ='j';
break;
default:
break;
}
return 0;
}
double scalarProduct(vector<double> velocity, vector<double> magneticFeild )
{
double product = 0;
if(velocity.size()!=magneticFeild.size()){
cout << "Vectors are not of the same size and hence the scalar product cannot be calculated" << endl;
return -1;
}
for (int i = 0; i < velocity.size(); i++)
{
product = product + velocity[i]*magneticFeild[i];
}
return product;
}
|