void TestCircle::testPerimeter() { this->testInit(__func__); Point origin = Point(100, 100); double radius = 100; Circle circle = Circle(origin, radius); if (circle.getPerimeter() != (2 * M_PI * circle.getRadius())) { this->testFailed(); } this->testInterpret(); }
int main() { Circle dayra; string CircleColor = "blue" ; dayra.setColor(CircleColor); cout<< dayra.getColor()<<" "<< dayra.isfilled()<<" before set "<< "\n"; dayra.setfilled() ; cout<< dayra.isfilled()<<"\n" ; dayra.setRadius(5); Rectangle mostatel; mostatel.setWidth(5); mostatel.setLength(5); mostatel.setColor(CircleColor); cout << dayra.getArea()<< " area "<<mostatel.getArea() << "\n" ; cout << dayra.getPerimeter() << " prmtr " << mostatel.getPerimeter() << "\n" ; dayra.toString(); cout << "\n" ; mostatel.toString() ; return 0; }
void printPerimeter(Circle c) { cout << "The perimeter is: " << c.getPerimeter(); }
int main( int argc, char* argv[] ) { // get input/output image file names from command line if (argc != 3) { std::cout << "Usage instructions: " << std::endl; std::cout << "> hw5.exe inputFileName.bmp coloredOutputFileName.bmp" << std::endl; return -1; } std::string inputFileName(argv[1]); std::string coloredOutputFileName(argv[2]); // read image from input file std::cout << "Reading input image: " << inputFileName << std::endl; Image myImage; bool success = myImage.readFromBMPFile(inputFileName); if (! success) { std::cout << "Error reading input image." << std::endl; return -1; } //The rest of your code goes here... int seedpixel = 0; //stores the value returned from markConnectedComponent int numCircles = 0; //stores number of circles int numSquares = 0; //stores number of squares int rows; //stores the image's row number int cols; //stores the image's column number int ccLabel = 0; //Connected Component Label //Pixel markers pixelLocation foundLoc; foundLoc.r = 0; foundLoc.c = 0; Circle circleObj; //Circle class object cSquare squareObj; //Square class object std::vector<Circle> cVect1; //Circle vector std::vector<cSquare> sqVect1; //Square vector int cVect2[100]; int sqVect2[100]; //Get number of rows and cols in Image rows = myImage.getNumRows(); cols = myImage.getNumCols(); //sorts through the image to find the circles and squares while(findPixelLocationWithGivenValue(myImage, 255, foundLoc.r, foundLoc.c) && ccLabel<100) { ccLabel++; seedpixel = markConnectedComponent(myImage, foundLoc.r, foundLoc.c, 100); if( seedpixel >= CIRCLE) { circleObj.setRadiusFromArea(seedpixel); cVect2[numCircles] = circleObj.getPerimeter(); cVect1.push_back(circleObj); myImage.setAllPixelsWithOldValToNewVal(100, LABELCIRCLE); numCircles++; } else{ squareObj.setSideLengthFromArea(seedpixel); sqVect2[numSquares] = squareObj.getPerimeter(); sqVect1.push_back(squareObj); myImage.setAllPixelsWithOldValToNewVal(100, LABELSQUARE); numSquares++; } } //Writes the resulting labeled-shape image to a file, assigning each label a random color myImage.switchToRandomColorMapping(); myImage.writeToBMPFile("My Mona Lisa"); //Output of the number of circles found and each circle's estimated Perimeter (Radius) pairs std::cout << "Number of CIRCLES: " << numCircles << std::endl; std::cout << "Circle Perimeters (Radius): " << std::endl; for(int i = 0; i < numCircles ; i++) { std::cout << cVect2[i] << " " << cVect2[i]/(2*3.14159) << std::endl; } //Output of the number of squares found and each square's estimated Perimeter (Side Length) pairs std::cout << "Number of SQUARES: " << numSquares << std::endl; std::cout << "Square Perimters (Side Length):" << std::endl; for(int j = 0; j < numSquares ; j++) { std::cout << sqVect2[j] << " " << sqVect2[j]/4 << std::endl; } return 0; }