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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#include <iostream>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cstdlib>
using namespace std;
//function naming
void choose_equation_1d_or_2d ();
int _1d_equation ();
//void choose_equation_2d ();
int exit ();
void speed_angle_2d ();
double stringconvert(string convert);
void display (double dxdisp,double vidisp,double vfdisp,double adisp,double tdisp);
//equation funtions
double solve_vf_no_dx (double te,double vie,double ae);
double solve_dx_no_vf (double te,double vie,double ae);
double solve_dx_no_vi (double te,double vfe,double ae);
double solve_vi_no_dx (double te,double vfe,double ae);
double solve_dx_no_a (double te,double vie,double vfe);
double solve_a_no_dx (double te,double vie,double vfe);
double solve_dx_no_t (double vie,double vfe,double ae);
double solve_t_no_dx (double vie,double vfe,double ae);
double solve_vi_no_vf (double dxe,double ae,double te);
double solve_vf_no_vi (double dxe,double ae,double te);
double solve_vi_no_a (double dxe,double vfe,double te);
double solve_a_no_vi (double dxe,double vfe,double te);
//start
int main()
{
choose_equation_1d_or_2d ();
return 0;
}
void choose_equation_1d_or_2d ()
{
string check;
cout << "kinematics program", cout << endl;
cout << "by stuart tveter", cout << endl;
cout << "is the problem 1d or 2d", cout << endl;
cin >> check;
if (check == "1d")
_1d_equation ();
else if (check == "2d")
//choose_equation_2d ();
cout << "bla";
else
{
cout << "that is not an option";
exit ();
}
}
int exit()
{
string a;
cout << endl,cout << "do you wish to restart? y/n", cout << endl;
cin >> a;
if (a == "y" || a == "yes")
main ();
else
return 0;
}
int _1d_equation ()
{
string dx,vi,vf,a,t;
double vfd,ad,td,vid,dxd;
cout << "enter know givens, if unknon, put a ?,";
// cout << "if unused, put a null", cout << endl;
cout << "dx=", cin >> dx, cout << endl;
cout << "vi=", cin >> vi, cout << endl;
cout << "vf=", cin >> vf, cout << endl;
cout << "a=", cin >> a, cout << endl;
cout << "t=", cin >> t, cout << endl;
//begin formula sorting
if (dx == "?")
{
if (vf == "?")
{
vid=stringconvert (vi);
ad=stringconvert (a);
td=stringconvert (t);
dxd=solve_dx_no_vf (td,vid,ad);
vfd=solve_vf_no_dx (td,vid,ad);
display (dxd,vid,vfd,ad,td);
}
else if (vi == "?")
{
vid=stringconvert (vf);
ad=stringconvert (a);
td=stringconvert (t);
dxd=solve_dx_no_vf (td,vid,ad);
vfd=solve_vf_no_dx (td,vid,ad);
display (dxd,vid,vfd,ad,td);
}
else if (a == "?")
{
vfd=stringconvert (vf);
vid=stringconvert (vi);
td=stringconvert (t);
dxd=solve_dx_no_a (td,vid,vfd);
ad=solve_a_no_dx (td,vid,vfd);
display (dxd,vid,vfd,ad,td);
}
else if (t == "?")
{
vfd=stringconvert (vf);
vid=stringconvert (vi);
ad=stringconvert (a);
dxd=solve_dx_no_t (ad,vid,vfd);
td=solve_t_no_dx (ad,vid,vfd);
display (dxd,vid,vfd,ad,td);
}
else
cout << "exe error";
}
else if (vi == "?")
{
if (vf == "?")
{
dxd=stringconvert (dx);
ad=stringconvert (a);
td=stringconvert (t);
vid=solve_vi_no_vf (dxd,ad,td);
vfd=solve_vf_no_vi (dxd,ad,td);
display (dxd,vid,vfd,ad,td);
}
else if (a == "?")
{
dxd=stringconvert (dx);
ad=stringconvert (a);
td=stringconvert (t);
vid=solve_vi_no_vf (dxd,ad,td);
vfd=solve_vf_no_vi (dxd,ad,td);
display (dxd,vid,vfd,ad,td);
}
else if (t == "?")
{
vfd=stringconvert (vf);
dxd=stringconvert (dx);
ad=stringconvert (a);
vid=solve_dx_no_t (ad,vid,vfd);
td=solve_t_no_dx (ad,vid,vfd);
display (dxd,vid,vfd,ad,td);
}
else
cout << "exe error";
}
else if (vf == "?")
{
if (a == "?")
{
dxd=stringconvert (dx);
vid=stringconvert (vi);
td=stringconvert (t);
vfd=solve_dx_no_t (dxd,vid,td);
ad=solve_t_no_dx (dxd,vid,td);
display (dxd,vid,vfd,ad,td);
}
else if (t == "?")
{
vfd=stringconvert (vf);
vid=stringconvert (vi);
ad=stringconvert (a);
dxd=solve_dx_no_t (ad,vid,vfd);
td=solve_t_no_dx (ad,vid,vfd);
display (dxd,vid,vfd,ad,td);
}
else
cout << "exe error";
}
else if (a == "?")
{
if (t == "?")
{
vfd=stringconvert (vf);
vid=stringconvert (vi);
dxd=stringconvert (dx);
ad=solve_dx_no_t (ad,vid,vfd);
td=solve_t_no_dx (ad,vid,vfd);
display (dxd,vid,vfd,ad,td);
}
else
{
cout << "exe error";
}
}
else
cout << "exe error";
}
//void choose_equation_2d ()
//{
// cout << "not built yet";
// exit ();
//}
double stringconvert (string convert)
{
double num;
stringstream ss(convert);
ss >> num;
return num;
}
void display (double dxdisp,double vidisp,double vfdisp,double adisp,double tdisp)
{
cout << "dx = ",cout << dxdisp,cout << "m", cout << endl;
cout << "vi = ",cout << vidisp,cout << "m/s", cout << endl;
cout << "vf = ", cout << vfdisp ,cout << "m/s", cout << endl;
cout << "a = ",cout << adisp,cout << "m/s" ,cout << endl;
cout << "t = ",cout << tdisp,cout << "sec", cout << endl;
exit ();
}
|