This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19607c7
commit 47722c3
Showing
21 changed files
with
691 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Binary alogorithm by Jerred Shepherd | ||
|
||
#include <iostream> | ||
#include <math.h> | ||
|
||
using namespace std; | ||
|
||
void main() { | ||
int p, num; | ||
char a; | ||
|
||
cout << "Convert a number to binary? "; | ||
cin >> a; | ||
|
||
while (a == 'y') { | ||
cout << "Input: "; | ||
cin >> num; | ||
|
||
p = 0; | ||
|
||
while (pow(2, p) <= num) { | ||
p++; | ||
} | ||
|
||
p--; | ||
|
||
while (p >= 0) { | ||
if (num >= pow(2, p)) { | ||
cout << "1"; | ||
num = num - pow(2, p); | ||
} else { | ||
cout << "0"; | ||
} | ||
|
||
p--; | ||
} | ||
|
||
cout << endl << "Convert a number to binary? "; | ||
cin >> a; | ||
} | ||
|
||
system("pause"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Decimal to hexidecimal alogorithm by Jerred Shepherd | ||
|
||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
void main() { | ||
int n, p, d; | ||
|
||
cout << "Input n "; | ||
cin >> n; | ||
|
||
p = 1; | ||
|
||
while (p < n) { | ||
p = p * 16; | ||
} | ||
|
||
p = p / 16; | ||
|
||
do { | ||
if (n >= p) { | ||
d = n / p; | ||
n = n - d * p; | ||
|
||
if (d <= 9) { | ||
cout << d; | ||
} else { | ||
if (d == 10) { | ||
cout << "A"; | ||
} else if (d == 11) { | ||
cout << "B"; | ||
} else if (d == 12) { | ||
cout << "C"; | ||
} else if (d == 13) { | ||
cout << "D"; | ||
} else if (d == 14) { | ||
cout << "E"; | ||
} else if (d == 15) { | ||
cout << "F"; | ||
} | ||
} | ||
|
||
} else { | ||
cout << "0"; | ||
} | ||
|
||
p = p / 16; | ||
|
||
} while (p > 0); | ||
|
||
cout << endl; | ||
|
||
system("pause"); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Decimal to hexidecimal alogorithm by Jerred Shepherd | ||
|
||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
void main() { | ||
int n, p, d; | ||
|
||
cout << "Input n "; | ||
cin >> n; | ||
|
||
p = 1; | ||
|
||
while (p < n) { | ||
p = p * 16; | ||
} | ||
|
||
p = p / 16; | ||
|
||
do { | ||
if (n >= p) { | ||
d = n / p; | ||
n = n - d * p; | ||
|
||
if (d <= 9) { | ||
cout << d; | ||
} else { | ||
switch (d) { | ||
case 10: cout << "A"; | ||
break; | ||
case 11: cout << "B"; | ||
break; | ||
case 12: cout << "C"; | ||
break; | ||
case 13: cout << "D"; | ||
break; | ||
case 14: cout << "E"; | ||
break; | ||
case 15: cout << "F"; | ||
} | ||
} | ||
|
||
} | ||
else { | ||
cout << "0"; | ||
} | ||
|
||
p = p / 16; | ||
|
||
} while (p > 0); | ||
|
||
cout << endl; | ||
|
||
system("pause"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Factorial alogorithm by Jerred Shepherd | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
void main() { | ||
int n, a; | ||
|
||
cout << "What is N? "; | ||
cin >> n; | ||
|
||
a = 1; | ||
|
||
while (n > 1) { | ||
a = a * n; | ||
n = n - 1; | ||
} | ||
|
||
cout << "The answer is " << a << endl; | ||
|
||
system("pause"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Jerred Shepherd, findbal homework | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
void FindBal(int id[], float bal[], int idtofind, int &found, float &result) { | ||
|
||
for (int counter = 0; counter != 5; counter++) { | ||
|
||
if (id[counter] == idtofind) { | ||
|
||
found = 1; | ||
result = bal[counter]; | ||
|
||
return; | ||
|
||
} | ||
|
||
found = 0; | ||
|
||
} | ||
|
||
} | ||
|
||
void main() | ||
{ | ||
int id[5] = { 123, 234, 333, 401, 500 }; | ||
float bal[5] = { 0.0, 100.0, 250.0, 50.0, 1225.0 }; | ||
float result; | ||
int idtofind, found; | ||
|
||
cout << "ID to find? "; | ||
cin >> idtofind; | ||
|
||
while (idtofind > 0) | ||
{ | ||
FindBal(id, bal, idtofind, found, result); | ||
if (found) | ||
cout << "The balance is " << result << endl; | ||
else | ||
cout << "Not found"; | ||
|
||
cout << "ID to find? "; | ||
cin >> idtofind; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Jerred Shepherd | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int gcd(int x, int y) { | ||
|
||
int t; | ||
|
||
t = x % y; | ||
|
||
while (t != 0) { | ||
|
||
x = y; | ||
y = t; | ||
|
||
t = x % y; | ||
|
||
} | ||
|
||
return y; | ||
|
||
} | ||
|
||
int lcm(int x, int y) { | ||
|
||
int cnt, ans; | ||
|
||
if (x > y) { | ||
|
||
cnt = x; | ||
|
||
} | ||
else { | ||
|
||
cnt = y; | ||
|
||
} | ||
|
||
ans = 0; | ||
|
||
while (ans == 0) { | ||
|
||
if (cnt % x == 0 && cnt % y == 0) { | ||
|
||
ans = cnt; | ||
|
||
} | ||
else { | ||
|
||
cnt++; | ||
|
||
} | ||
|
||
} | ||
|
||
return ans; | ||
|
||
} | ||
|
||
void reduce(int &num, int &den) { | ||
|
||
int divisor; | ||
|
||
divisor = gcd(num, den); | ||
|
||
num = num / divisor; | ||
den = den / divisor; | ||
|
||
} | ||
|
||
void common_den(int &num1, int &den1, int &num2, int &den2) { | ||
|
||
int cden; | ||
|
||
cden = lcm(den1, den2); | ||
|
||
num2 *= cden / den2; | ||
num1 *= cden / den1; | ||
|
||
den1 = cden; | ||
den2 = cden; | ||
|
||
} | ||
|
||
void main() | ||
{ | ||
int num1, den1, num2, den2, newnum, newden; | ||
char slash1, slash2, op; | ||
|
||
cout << "\nFraction Calculator\n\n"; | ||
cout << "Add, subtract, multiply & divide - positive fractions only\n"; | ||
cout << "Enter '0/0 + 0/0' to quit.\n"; | ||
|
||
// Input will be assumed to be in correct form for simplification | ||
// Input data before loop in case they want to exit right away | ||
|
||
cout << "\n> "; | ||
cin >> num1 >> slash1 >> den1 >> op >> num2 >> slash2 >> den2; | ||
while (num1 + den1 + num2 + den2 > 0) | ||
{ | ||
// Reduce both fractions to keep integers as small as possible | ||
reduce(num1, den1); | ||
reduce(num2, den2); | ||
switch (op) { | ||
case '+': | ||
// Find common denominator and add | ||
common_den(num1, den1, num2, den2); | ||
newnum = num1 + num2; | ||
newden = den1; | ||
break; | ||
case '-': | ||
// Find common denominator and subtract | ||
common_den(num1, den1, num2, den2); | ||
newnum = num1 - num2; | ||
newden = den1; | ||
break; | ||
case '*': | ||
// Multiply numerators and multiply denominators | ||
newnum = num1 * num2; | ||
newden = den1 * den2; | ||
break; | ||
case '/': | ||
// Invert and multiply | ||
newnum = num1 * den2; | ||
newden = den1 * num2; | ||
} | ||
// Reduce the answer to lowest terms | ||
reduce(newnum, newden); | ||
|
||
// Output the results | ||
cout << num1 << "/" << den1 << " " << op << " "; | ||
cout << num2 << "/" << den2 << " = "; | ||
cout << newnum << "/" << newden << endl; | ||
|
||
// Input data for next iteration of loop | ||
cout << "\n> "; | ||
cin >> num1 >> slash1 >> den1 >> op >> num2 >> slash2 >> den2; | ||
} | ||
|
||
system("pause"); | ||
|
||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.