aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Spears <[email protected]>2024-01-22 20:23:08 -0800
committerArthur Spears <[email protected]>2024-01-22 20:23:08 -0800
commitd00fd38a6200723d6178895b587b3f61014fa8fb (patch)
treee5647eeef42e826f39be80301b75af1512d97638
parentimplemented exercise 5 functions (diff)
downloadin-class-exercise-5-arthurtspears-main.tar.xz
in-class-exercise-5-arthurtspears-main.zip
other exercises and start of hw3HEADmain
-rw-r--r--Exercise5/Exercise5/helpers.h29
-rw-r--r--Exercise5/Exercise5/program.cpp152
2 files changed, 128 insertions, 53 deletions
diff --git a/Exercise5/Exercise5/helpers.h b/Exercise5/Exercise5/helpers.h
index 0fcb072..8fc59a6 100644
--- a/Exercise5/Exercise5/helpers.h
+++ b/Exercise5/Exercise5/helpers.h
@@ -3,22 +3,35 @@
#define MY_HEADER_FILE_H
// Content of the header file
-int returnInt();
+//int returnInt();
+//
+//int sum(int a, int b);
+//
+//int sum(int a, int b, int c, int d);
+//
+//int sum(float a);
+//
+//float percentage(int a, int b);
+//
+//float FtoC(int fah);
+//
+//float CtoF(int cel);
-int sum(int a, int b);
-
-float percentage(int a, int b);
-
-float FtoC(int fah);
-
-float CtoF(int cel);
+//int math_func();
+//
+//int math_func(int square);
+//
+//int math_func(int a, int b);
+//
+//int math_func(int A, int B, int C, int x = 2);
+//long factorial_worker(int a);
long factorial(int a);
diff --git a/Exercise5/Exercise5/program.cpp b/Exercise5/Exercise5/program.cpp
index 45bfff6..3aeaed0 100644
--- a/Exercise5/Exercise5/program.cpp
+++ b/Exercise5/Exercise5/program.cpp
@@ -7,71 +7,133 @@
#include "helpers.h"
+void thisIsRecursive(int a) {
+ std::cout << "The number is now " << a << std::endl;
+ if(a == 0) return;
+
+ thisIsRecursive(a-1);
+}
-int main()
-{
- std::cout << sum(15,30) << std::endl;
- std::cout << returnInt() << std::endl;
+int main()
+{
+ //thisIsRecursive(6);
+ //std::cout << sum(15,30) << std::endl;
+ /*std::cout << returnInt() << std::endl;
std::cout << percentage(10,100) << "%" << std::endl;
std::cout << percentage(25,100) << std::endl;
std::cout << percentage(30,300) << std::endl;
std::cout << percentage(780,100) << std::endl;
-
int i;
std::cin >> i;
std::cout << FtoC(i) << std::endl;
- std::cout << CtoF(i) << std::endl;
+ std::cout << CtoF(i) << std::endl;*/
+ //std::cout << sum(10, 15, 32, 56);
+ //std::cout<< sum(15);
+ //sum(sum1, sum(65, 25));
- return 0;
-}
+ /*std::cout << math_func() << std::endl;
-int sum(int a, int b)
-{
- int sum = 0;
+ std::cout << math_func(2) << std::endl;
- sum = a + b;
+ std::cout << math_func(2, 4)<< std::endl;
- return sum;
-}
-
-int returnInt() {
-
- return 10;
-}
+ std::cout << math_func(5, 7, 8) << std::endl;*/
-float percentage(int a, int b) {
+ std::cout << factorial(300);
- float perc = (static_cast<float>(a) / b) * 100;
-
- return perc;
-}
-
-float FtoC(int fah) {
- // -32*5/9
-
- float num = (fah - 32) * (5.0 / 9.0);
-
- return num;
-}
-
-float CtoF(int cel) {
- // 9/5+32
-
- float num = (cel * (9.0 / 5.0)) + 32;
-
- return num;
+ return 0;
}
-
-
+//int math_func() {
+// return 1;
+//}
+//
+//int math_func(int square) {
+// return square * square;
+//}
+//
+//int math_func(int a, int b) {
+// return a + b;
+//}
+//
+//int math_func(int A, int B, int C, int x){
+// return (A * x * x) - (B * x) + C;
+//}
+
+
+
+
+
+
+
+
+
+
+
+
+//
+//int sum(float a) {
+// return a * 10;
+//}
+//
+//int sum(int a, int b)
+//{
+// int sum = 0;
+//
+// sum = a + b;
+//
+// return sum;
+//}
+//
+//int sum(int a, int b, int c, int d) {
+// //int add = a + b + c + d;
+//
+// return a + b + c + d;
+//}
+//
+//
+//int returnInt() {
+//
+// return 10;
+//}
+//
+//float percentage(int a, int b) {
+//
+// float perc = (static_cast<float>(a) / b) * 100;
+//
+// return perc;
+//}
+//
+//float FtoC(int fah) {
+// // -32*5/9
+//
+// float num = (fah - 32) * (5.0 / 9.0);
+//
+// return num;
+//}
+//
+//float CtoF(int cel) {
+// // 9/5+32
+//
+// float num = (cel * (9.0 / 5.0)) + 32;
+//
+// return num;
+//}
+//
+//long factorial_worker(int a, int b) {
+// //recursive work
+//}
+
+//long factorial(int a) {
+// return factorial_worker(a, 1);
+//}
long factorial(int a)
{
- if (a == 0 || a == 1)
- return 1; //base case returns solid data
- else
- return a * factorial(a - 1); //recursive case: a! = a * (a-1)!
+ if (a == 0 || a == 1) return 1; //base case returns solid data
+
+ return a * factorial(a - 1); //recursive case: a! = a * (a-1)!
}