diff options
author | Matthew Strapp <msattr@gmail.com> | 2019-02-20 16:00:41 -0600 |
---|---|---|
committer | Matthew Strapp <msattr@gmail.com> | 2019-02-20 16:00:41 -0600 |
commit | 93ff5f30e854390dc6bb790414e13986144514fa (patch) | |
tree | 3ae048da5dfafaa05f6573fd8a29a402a38a0470 /ee1301 | |
parent | (Screams internally) (diff) | |
download | homework-93ff5f30e854390dc6bb790414e13986144514fa.tar homework-93ff5f30e854390dc6bb790414e13986144514fa.tar.gz homework-93ff5f30e854390dc6bb790414e13986144514fa.tar.bz2 homework-93ff5f30e854390dc6bb790414e13986144514fa.tar.lz homework-93ff5f30e854390dc6bb790414e13986144514fa.tar.xz homework-93ff5f30e854390dc6bb790414e13986144514fa.tar.zst homework-93ff5f30e854390dc6bb790414e13986144514fa.zip |
Finish Lab 3
Diffstat (limited to 'ee1301')
-rw-r--r-- | ee1301/wk3/lab3/RootBabylon2.cpp | 40 | ||||
-rw-r--r-- | ee1301/wk3/lab3/RootBabylonOG.cpp (renamed from ee1301/wk3/lab3/RtBab.cpp) | 10 | ||||
-rw-r--r-- | ee1301/wk3/lab3/fib.cpp | 2 | ||||
-rw-r--r-- | ee1301/wk3/lab3/mysteryBox.cpp | 2 | ||||
-rw-r--r-- | ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp | 41 |
5 files changed, 86 insertions, 9 deletions
diff --git a/ee1301/wk3/lab3/RootBabylon2.cpp b/ee1301/wk3/lab3/RootBabylon2.cpp new file mode 100644 index 0000000..c6daa37 --- /dev/null +++ b/ee1301/wk3/lab3/RootBabylon2.cpp @@ -0,0 +1,40 @@ +#include <iostream> +#include <iomanip> +#include <cmath> +using namespace std; + +double gennewGuess(double n, double old_guess) { + double real, old; + real=sqrt(n); + double new_guess = ( old_guess + n / old_guess ) / 2; + old=new_guess; + if (((new_guess-real)/real)>0.01) { //This will be true if the difference between the real root and guess is more than 1%. + // cout << old << endl; + return gennewGuess(n, old); + } else { + // cout << old << endl; + return new_guess; + } +} +int main () { + double temp; + char cont; + do { + cout << "enter a value: "; + cin >> temp; + int n=temp; + if (temp<=0) { + cout << "Please enter a valid input(Positive Integer)." << endl; + return sqrt(-1); + } + //cout << "Guessing..." << endl; + temp = gennewGuess(temp, 1.0); + cout << fixed << setprecision(0) << "square root of " << n << " is " << temp << endl + << "continue? (y/n): "; + cin >> cont; + if (cont!='n'&&cont!='y') { + return -1; + } +} while (cont!='n'); + // << "Actual Value: " << real << endl; +} diff --git a/ee1301/wk3/lab3/RtBab.cpp b/ee1301/wk3/lab3/RootBabylonOG.cpp index d75bd9e..07c1951 100644 --- a/ee1301/wk3/lab3/RtBab.cpp +++ b/ee1301/wk3/lab3/RootBabylonOG.cpp @@ -3,15 +3,11 @@ using namespace std; double gennewGuess(double n, double old_guess) { - bool WA=true; double real, old; - //if (WA) { - real=sqrt(n); - WA=false; - //} + real=sqrt(n); double new_guess = ( old_guess + n / old_guess ) / 2; old=new_guess; - if (((new_guess-real)/real)>0.01) { + if (((new_guess-real)/real)>0.01) { //This will be true if the difference between the real root and guess is more than 1%. cout << old << endl; return gennewGuess(n, old); } else { @@ -25,7 +21,7 @@ int main () { cin >> temp; if (temp<=0) { cout << "Please enter a valid input(Positive Integer)." << endl; - return -1; + return sqrt(-1); } cout << "Guessing..." << endl; double real=sqrt(temp); diff --git a/ee1301/wk3/lab3/fib.cpp b/ee1301/wk3/lab3/fib.cpp index 7508637..cd3a048 100644 --- a/ee1301/wk3/lab3/fib.cpp +++ b/ee1301/wk3/lab3/fib.cpp @@ -14,4 +14,4 @@ int main() cout << endl; } cout << endl; -}
\ No newline at end of file +} diff --git a/ee1301/wk3/lab3/mysteryBox.cpp b/ee1301/wk3/lab3/mysteryBox.cpp index c1a85a4..c409b7c 100644 --- a/ee1301/wk3/lab3/mysteryBox.cpp +++ b/ee1301/wk3/lab3/mysteryBox.cpp @@ -9,4 +9,4 @@ int main () { sum++; } cout << sum; -}
\ No newline at end of file +} diff --git a/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp b/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp new file mode 100644 index 0000000..6dbd3bc --- /dev/null +++ b/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <string> +using namespace std; +int main () { + int decimal; + cout << "Enter an integer value from 1 to 999: "; + cin >> decimal; + if (decimal<1||decimal>999) { + cout << " Invalid Input. Program terminated." << endl; + return 1453; + } else { + cout << "Roman numeral equivalent: "; + while (decimal!=0) { + if (decimal>900 && decimal<1000) { + cout << "CM"; decimal-=900; } + if (decimal>500 && decimal<900) { + cout << "D"; decimal-=500; } + if (decimal>400 && decimal<500) { + cout << "CD"; decimal-=400; } + if (decimal>100 && decimal<400) { + cout << "C"; decimal-=100; } + if (decimal>90 && decimal<100) { + cout << "XC"; decimal-=90; } + if (decimal>50 && decimal<90) { + cout << "L"; decimal-=50; } + if (decimal>40 && decimal<50) { + cout << "XL"; decimal-=40; } + if (decimal>10 && decimal<40) { + cout << "X"; decimal-=10; } + if (decimal==9) { + cout << "IX"; decimal-=9; } + if (decimal>5 && decimal<9) { + cout << "V"; decimal-=5; } + if (decimal==4) { + cout << "IV"; decimal-=4; } + if (decimal>=1 && decimal<4) { + cout << "I"; decimal-= 1; } + }} + cout << endl; + return 0; +} |