1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
//
// main.cpp
// QuadraticProjct
//
// Created by WIlliam on 5/9/17.
// Copyright © 2017 WIlliam. All rights reserved.
//
#include <iostream>
#include <cmath>
using namespace std;
int SqrtTest(int, int, int);
int QuadFnX1(int, int, int);
int QuadFnX2(int, int, int);
int SqrtTest(int ATest, int BTest, int CTest)
{
int SqrtMath;
SqrtMath = ((BTest * BTest)-(4*ATest*CTest));
if ( SqrtMath < 0)
{
return true;
}
else
{
return false;
}
}
int QuadFnX1(int A, int B, int C)
{
int SqrtMath, BSqrtMath, A2, XPlus;
SqrtMath = sqrt((B*B) - (4*A*C));
cout<<SqrtMath<<endl;
BSqrtMath = (-B + SqrtMath);
cout<<BSqrtMath<<endl;
A2 = (2*A);
cout<<A2<<endl;
XPlus = (BSqrtMath / A2);
cout<<XPlus<<endl;
return XPlus;
}
int QuadFnX2(int A, int B, int C)
{
int SqrtMath, BSqrtMath, A2, XMinus;
SqrtMath = sqrt((B*B) - (4*A*C));
BSqrtMath = (-B - SqrtMath);
A2 = (A * 2);
XMinus = (BSqrtMath / (A2));
return XMinus;
}
int main()
{
int A, B, C;
cout<<"A : ";
cin>> A;
cout<<endl<<"B : ";
cin>>B;
cout<<endl<<"C : ";
cin>>C;
if (SqrtTest(A, B, C) == true)
{
cout<<"sorry"<<endl;
return 0;
}
else
if (SqrtTest(A, B, C) == false)
{
int X1, X2;
X1 = QuadFnX1(A, B, C);
X2 = QuadFnX2(A, B, C);
cout<<" ( X + "<<X1<<" )( X + "<<X2<<" )"<<endl;
return 0;
}
return 0;
}
|