Created
May 18, 2014 10:27
-
-
Save morontt/9781dad172ea3ce3bdbb to your computer and use it in GitHub Desktop.
salazar 3
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
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
float F(float a, float b, float c, float x, bool is_int) { | |
float result; | |
if (x < 0.0 && b != 0.0) { | |
result = -1.0 * a * x * x + b; | |
} else if (x > 0.0 && b == 0.0) { | |
result = x / (x - c) + 5.5; | |
} else { | |
result = -1.0 * x / c; | |
} | |
if (is_int) { | |
result = floor(result); | |
} | |
return result; | |
} | |
int main() { | |
float x1, x2, dx, x; | |
float a, b, c; | |
int ia, ib, ic; | |
char lett; | |
bool is_int; | |
cout << "a = "; | |
cin >> a; | |
cout << "b = "; | |
cin >> b; | |
cout << "c = "; | |
cin >> c; | |
cout << "x1 = "; | |
cin >> x1; | |
cout << "x2 = "; | |
cin >> x2; | |
cout << "dx = "; | |
cin >> dx; | |
ia = floor(a); | |
ib = floor(b); | |
ic = floor(c); | |
is_int = true; | |
if ((~ (ia | ib | ic)) != 0) { | |
is_int = false; | |
} | |
x = x1; | |
while (x <= x2) { | |
cout << "x: " << x << "\tF: " << F(a, b, c, x, is_int) << endl; | |
x += dx; | |
} | |
cout << endl << "Enter a letter to end the program" << endl; | |
cin >> lett; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment