Added support for circles

parent f255a66c
area.exe
test.exe
# CPTR 245 - Lab Repository
This is a repo with the (presumably one) project for CPTR 245 to be built throughout the quarter
\ No newline at end of file
This is a repo with the (presumably one) project for CPTR 245 to be built throughout the quarter
To compile the tests, use
`g++ -o test areaFunction.cpp areaFunction.h areaTest.cpp`
To compile the program, use
`g++ -o area areaFunction.cpp areaFunction.h areaMain.cpp`
The main program's syntax is "./area %d" where %d is any integer.
......@@ -6,4 +6,8 @@
int areaOfSquareWithSides(int side){
return side*side;
}
float areaOfCircleWithRadius(double radius){
return (3.14 * (radius * radius));
}
\ No newline at end of file
......@@ -4,4 +4,6 @@
//Lab 01: Testing a Function
// areaFunction.h. Prototypes the funciton areaOfSquareWithSides implemented in areaFunction.cpp
int areaOfSquareWithSides(int side);
\ No newline at end of file
int areaOfSquareWithSides(int side);
float areaOfCircleWithRadius(double radius);
\ No newline at end of file
......@@ -12,7 +12,7 @@ using namespace std;
int main(int argc, char *argv[]){
if (argc < 2){
cout << "You must provide at least two arguments in the form of \"./area 5\"" << endl;
cout << "You must provide at least two arguments in the form of \"./area %d\"" << endl;
return 1;
}
else{
......@@ -22,8 +22,10 @@ int main(int argc, char *argv[]){
cout << "Value must be an integer above 0" << endl;
return 1;
}
int result = areaOfSquareWithSides(argument);
cout << "The area of a square with sides of " << argv[1] << " units is " << result << " units." << endl;
int squareArea = areaOfSquareWithSides(argument);
float circleArea = areaOfCircleWithRadius(argument);
cout << "The area of a square with sides of " << argv[1] << " units is " << squareArea << " units." << endl;
cout << "The area of a circle with a radius of " << argv[1] << " units is " << circleArea << " units." << endl;
return 0;
}
......
......@@ -5,25 +5,51 @@
//areaTest.cpp. Contains the testing done to the areaOfSquareWithSides function implemented in areaFunction.cpp
#include <iostream>
#include <vector>
#include "areaFunction.h"
using namespace std;
int main(){
bool testPasses = true;
//This string logs which tests fail, and is for debugging purposes. A more sophisticated system will come later
string testsFailed = "";
/*Test 1*/
if (areaOfSquareWithSides(3) != 9){
testsFailed += "1 ";
testPasses = false;
}
/*Test 2*/
if (areaOfSquareWithSides(5) != 25){
testsFailed += "2 ";
testPasses = false;
}
/*Test 3*/
if (areaOfSquareWithSides(4) != 16){
testsFailed += "3 ";
testPasses = false;
}
//Test 4 - Circle
//"float a" exists to force a type conversion in the comparisons. Test were
//failing when the secondary value's type was not declared, as the function
//was spitting out a float and trying to compare to a default double in the tests.
float a = 153.86;
if (areaOfCircleWithRadius(7) != a){
cout << areaOfCircleWithRadius(7) << endl;
testsFailed += "4 ";
testPasses = false;
}
//Test 5 - Circle
a = 3.7994;
if (areaOfCircleWithRadius(1.1) != a){
cout << areaOfCircleWithRadius(1.1) << endl;
testsFailed += "5 ";
testPasses = false;
}
......@@ -32,7 +58,8 @@ int main(){
cout << "Test succeeded" << endl;
return 0;
} else {
cout << "Test Failed" << endl;
cout << "Tests Failed: " << testsFailed << endl;
return 1;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment