From 97a53b9a9c8a4e19c167ff50eeb473b005e1d89c Mon Sep 17 00:00:00 2001 From: Arthur Spears Date: Mon, 22 Jan 2024 19:18:31 -0800 Subject: implemented exercise 5 functions --- Exercise5/Exercise5/helpers.h | 14 +++++++++++++ Exercise5/Exercise5/program.cpp | 46 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Exercise5/Exercise5/helpers.h b/Exercise5/Exercise5/helpers.h index c6a1241..0fcb072 100644 --- a/Exercise5/Exercise5/helpers.h +++ b/Exercise5/Exercise5/helpers.h @@ -3,8 +3,22 @@ #define MY_HEADER_FILE_H // Content of the header file +int returnInt(); + int sum(int a, int b); +float percentage(int a, int b); + +float FtoC(int fah); + +float CtoF(int cel); + + + + + + + long factorial(int a); diff --git a/Exercise5/Exercise5/program.cpp b/Exercise5/Exercise5/program.cpp index bafa30c..45bfff6 100644 --- a/Exercise5/Exercise5/program.cpp +++ b/Exercise5/Exercise5/program.cpp @@ -8,12 +8,22 @@ #include "helpers.h" +int main() +{ + 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; -int main() -{ return 0; } @@ -26,6 +36,38 @@ int sum(int a, int b) return sum; } +int returnInt() { + + return 10; +} + +float percentage(int a, int b) { + + float perc = (static_cast(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(int a) { if (a == 0 || a == 1) -- cgit v1.2.3