Question: Hello, it is a c++ assignment but it has error when i run it. please see the error message as bolded. // File Name: GeometricArea.cpp
Hello, it is a c++ assignment but it has error when i run it. please see the error message as bolded.
// File Name: GeometricArea.cpp #include
// Function to calculate area of a polygon double polygonArea(double pointX[], double pointY[], int len) { // Initializes area to zero double area = 0.0;
// Calculate value of shoelace formula int pos = len - 1; for (int c = 0; c < len; c++) { area += (pointX[pos] + pointX[c]) * (pointY[pos] - pointY[c]); // pos is previous vertex to c pos = c; }// End of for loop
// Return absolute value return abs(area / 2.0); }// End of function
-----------------------------------------------------------------------------
// File Name: SpecificationException.cpp #ifndef SPECIFICATIONEXCEPTION_H #define SPECIFICATIONEXCEPTION_H #include
// Defines a class SpecificationException to handle polygon exception class SpecificationException { public: // Parameterized constructor definition SpecificationException(string message) { // Displays error message cout< -------------------------------------------------------------------------------- // File Name: SpecificationException_test.cpp #include // main function definition int main() { // Variable to store sides int sides; // Accepts sides from the user cout<<" Enter number of sides: "; cin>>sides; // Checks if sides is less than or equals to 2 then throws an exception if(sides <= 2) throw new SpecificationException("Error: Fewest number of sides of polygon can have 3."); // Otherwise valid sides // To store x and y coordinate values double pointX[sides]; double pointY[sides]; cout<<" Enter the x and y coordinate values: "; // Loops till number of sides and accept x and y coordinate values for(int c = 0; c < sides; c++) { cout<<" X = "; cin>>pointX[c]; cout<<" Y = "; cin>>pointY[c]; }// End of for loop // Calls the function to calculate area and displays it cout <<" Area of Polygon having "<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
