Created
September 23, 2012 07:22
-
-
Save ieve-rothe/3769198 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // File: Project_1A_CCarroll.cpp | |
| // Author: Cameron Carroll | |
| // Date: September 11, 2012 | |
| // CSIS 138, Project 1 Part A | |
| #include "Project_1A_CCarroll.hpp" | |
| #include <cmath> | |
| double convert_f_to_c(double fahrenheit_temperature) { | |
| double celsius_temperature = (5.0/9.0) * (fahrenheit_temperature - 32.0); | |
| return celsius_temperature; | |
| } | |
| double convert_c_to_f(double celsius_temperature) { | |
| double fahrenheit_temperature = (9.0/5.0) * celsius_temperature + 32.0; | |
| return fahrenheit_temperature; | |
| } |
This file contains hidden or 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
| // File: Project_1A_CCarroll.hpp | |
| // Author: Cameron Carroll | |
| // Date: September 11, 2012 | |
| // CSIS 138, Project 1 Part A | |
| // Using UUID for include guard name suggested by this post: | |
| // http://stackoverflow.com/a/1744302/191470 | |
| #ifndef INCLUDE_GUARD_d7c08102_fc81_11e1_82ea_e89d8750d021 | |
| #define INCLUDE_GUARD_d7c08102_fc81_11e1_82ea_e89d8750d021 | |
| double convert_f_to_c(double fahrenheit_temperature); | |
| double convert_c_to_f(double celsius_temperature); | |
| #endif |
This file contains hidden or 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
| // File: Project_1A_CCarroll_Test.cpp | |
| // Author: Cameron Carroll | |
| // Date: September 11, 2012 | |
| // CSIS 138, Project 1 Part A | |
| // Relative float comparison formula from: | |
| // http://realtimecollisiondetection.net/blog/?p=89 | |
| #include "Project_1A_CCarroll.hpp" | |
| #include <iostream> | |
| #include <cmath> | |
| using namespace std; | |
| #define EPSILON 0.1 | |
| double values_equal(double value_a, double value_b) { | |
| if (value_a == value_b) { | |
| return true; | |
| } | |
| else { | |
| return false; | |
| } | |
| } | |
| void assert_equal(double value_a, double value_b) { | |
| if (values_equal(value_a, value_b)) { | |
| cout << "EQUALITY: " << value_a << " == " << value_b << endl; | |
| } | |
| else { | |
| cout << "INEQUALITY: " << value_a << " != " << value_b << endl; | |
| } | |
| return; | |
| } | |
| void assert_equal_relative(double value_a, double value_b, double epsilon) { | |
| if (abs(value_a - value_b) <= epsilon * max(abs(value_a), abs(value_b))) { | |
| cout << "RELATIVE EQUALITY: " << value_a << " +- " << epsilon << " ~= " << value_b << endl; | |
| return; | |
| } | |
| else { | |
| cout << "RELATIVE INEQUALITY: " << value_a << " +- " << epsilon << " != " << value_b << endl; | |
| return; | |
| } | |
| } | |
| int main() { | |
| cout << "CS138 Project 1A (Temperature Conversion) Test" << endl; | |
| // Celsius inputs, fahrenheit outputs | |
| double c_temp_in_1 = 100.0; double f_temp_ex_1 = 212.0; | |
| double c_temp_in_2 = 0.0; double f_temp_ex_2 = 32.0; | |
| double c_temp_in_3 = -273.0; double f_temp_ex_3 = -459.4; | |
| // Fahrenheit inputs, celsius outputs | |
| double f_temp_in_1 = 100.0; double c_temp_ex_1 = 37.8; | |
| double f_temp_in_2 = -100.0; double c_temp_ex_2 = -73.3; | |
| double f_temp_in_3 = -40.0; double c_temp_ex_3 = -40.0; | |
| cout << "Calculated Temperature =? Expected Value" << endl; | |
| cout << "-----------------------------------------" << endl; | |
| assert_equal_relative(convert_c_to_f(c_temp_in_1), f_temp_ex_1, EPSILON); | |
| assert_equal_relative(convert_c_to_f(c_temp_in_2), f_temp_ex_2, EPSILON); | |
| assert_equal_relative(convert_c_to_f(c_temp_in_3), f_temp_ex_3, EPSILON); | |
| assert_equal_relative(convert_f_to_c(f_temp_in_1), c_temp_ex_1, EPSILON); | |
| assert_equal_relative(convert_f_to_c(f_temp_in_2), c_temp_ex_2, EPSILON); | |
| assert_equal_relative(convert_f_to_c(f_temp_in_3), c_temp_ex_3, EPSILON); | |
| cout << "Enter any value to exit..." << endl; | |
| int endme; | |
| cin >> endme; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment