From 93ff5f30e854390dc6bb790414e13986144514fa Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Wed, 20 Feb 2019 16:00:41 -0600 Subject: Finish Lab 3 --- ee1301/wk3/lab3/RootBabylon2.cpp | 40 +++++++++++++++++++++ ee1301/wk3/lab3/RootBabylonOG.cpp | 32 +++++++++++++++++ ee1301/wk3/lab3/RtBab.cpp | 36 ------------------- ee1301/wk3/lab3/fib.cpp | 2 +- ee1301/wk3/lab3/mysteryBox.cpp | 2 +- .../wk3/lab3/strap012_lab3_decimal_roman_conv.cpp | 41 ++++++++++++++++++++++ 6 files changed, 115 insertions(+), 38 deletions(-) create mode 100644 ee1301/wk3/lab3/RootBabylon2.cpp create mode 100644 ee1301/wk3/lab3/RootBabylonOG.cpp delete mode 100644 ee1301/wk3/lab3/RtBab.cpp create mode 100644 ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp (limited to 'ee1301/wk3/lab3') 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 +#include +#include +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/RootBabylonOG.cpp b/ee1301/wk3/lab3/RootBabylonOG.cpp new file mode 100644 index 0000000..07c1951 --- /dev/null +++ b/ee1301/wk3/lab3/RootBabylonOG.cpp @@ -0,0 +1,32 @@ +#include +#include +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, temp2; + cout << "Enter the Number to find square root: "; + cin >> temp; + if (temp<=0) { + cout << "Please enter a valid input(Positive Integer)." << endl; + return sqrt(-1); + } + cout << "Guessing..." << endl; + double real=sqrt(temp); + temp2=temp; + temp = gennewGuess(temp, 1.0); + cout << "The Final Guess: " << temp << endl + << "Actual Value: " << real << endl; +} diff --git a/ee1301/wk3/lab3/RtBab.cpp b/ee1301/wk3/lab3/RtBab.cpp deleted file mode 100644 index d75bd9e..0000000 --- a/ee1301/wk3/lab3/RtBab.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -using namespace std; - -double gennewGuess(double n, double old_guess) { - bool WA=true; - double real, old; - //if (WA) { - real=sqrt(n); - WA=false; - //} - double new_guess = ( old_guess + n / old_guess ) / 2; - old=new_guess; - if (((new_guess-real)/real)>0.01) { - cout << old << endl; - return gennewGuess(n, old); - } else { - cout << old << endl; - return new_guess; - } -} -int main () { - double temp, temp2; - cout << "Enter the Number to find square root: "; - cin >> temp; - if (temp<=0) { - cout << "Please enter a valid input(Positive Integer)." << endl; - return -1; - } - cout << "Guessing..." << endl; - double real=sqrt(temp); - temp2=temp; - temp = gennewGuess(temp, 1.0); - cout << "The Final Guess: " << temp << endl - << "Actual Value: " << real << endl; -} 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 +#include +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; +} -- cgit v1.2.3