No need to download it. Please just do it from scratch. I need three files . THI
ID: 3839112 • Letter: N
Question
No need to download it. Please just do it from scratch. I need three files .
THIS IS THE CODE WE NEED TO EXTEND PLEASE.
//Assignment : GeometricAreas
//GeometricArea.h
#pragma once
#ifndef GeometricArea
#define GeometricArea
float getArea(int numSides, float side1);
float getArea(int numSides, float side1, float side2, float side3);
float getArea(int numSides, float side1, float side2, float side3, float side4);
#endif GeometricArea
=============================================
// //Assignment : GeometricAreas
#include <iostream>
#include <cmath>
#include "GeometricArea.h"
using namespace std;
float getArea(int numSides, float side1)
{
float area = 0.0;
const float PI = 3.14;
area = PI * pow(side1, 2.0);
return area;
}
float getArea(int numSides, float side1 , float side2, float side3)
{
float s, area;
s = (side1 + side2 + side3)/2;
area = sqrt(s * (s-side1) * (s-side2) * (s-side3));
return area;
}
float getArea(int numSides, float side1 , float side2, float side3, float side4)
{
float length, width, area;
if (side1 == side2){
length = side1;
width = side3;
} else if (side1 == side3){
length = side1;
width = side2;
} else if (side1 == side4){
length = side1;
width = side3;
}
area = length * width;
return area;
}
==========================================================
// Date : 02 / 28/ 2017
//Assignment : GeometricAreas
// GeometricArea_test.cpp
#include <iostream>
#include <string>
#include <cmath>
#include "GeometricArea.h"
using namespace std;
int main()
{
int numSides;
float first, second, third, fourth;
char response;
response = 'y';
while (response == 'y') {
cout << "Enter the number sides:";
cin >> numSides;
if (numSides == 1) {
cout << "Enter the radius: ";
cin >> first;
cout << "Area is: " << getArea(numSides, first) << endl;
}
else if (numSides == 3) {
cout << "Enter the dimension of side 1: ";
cin >> first;
cout << "Enter the dimension of side 2: ";
cin >> second;
cout << "Enter the dimension of side 3: ";
cin >> third;
cout << "Area is: " << getArea(numSides, first, second, third) << endl;
}
else if (numSides == 4) {
cout << "Enter the dimension of side 1: ";
cin >> first;
cout << "Enter the dimension of side 2: ";
cin >> second;
cout << "Enter the dimension of side 3: ";
cin >> third;
cout << "Enter the dimension of side 4: ";
cin >> fourth;
cout << "Area is: " << getArea(numSides, first, second, third, fourth) << endl;
}
else {
cout << "Sorry, the area can not be calculated." << endl;
}
cout << "Go again? (y/n)";
cin >> response;
}
return 0;
}
PLEASE NOTE ::: Requested files: GeometricArea.cpp, SpecificationException.h, SpecificationException_test.cpp
Maximum number of files: 4;
Dont post earlier answer I need separate files as requested , thanks.
Update:: Please do it from scratch there is no code available.
Please use C++ Language. And please provide comment about your codes thanks.
GeometricArea.cpp and SpecificationException.cpp
Requested files: GeometricArea.cpp, SpecificationException.h, SpecificationException_test.cpp (Download)
Maximum number of files: 4
Type of work: Individual work
Extend the GeometricArea.cpp program you wrote to use an exception to handle user input where the parameters entered do not meet specifications, or that simply don't make sense. In the case of GeometricArea this occurs when the number of sides is two (2).
You should create a class SpecificationException that is thrown whenever your program encounters a specification that does not make sense. For example, if your program is asked to compute the area of a 2 sided polygon, You should throw a SpecificationException, because the fewest number of sides a polygon can have is 3..
You can create this class using only an interface (or header) file called SpecificationException.h. Simply include this header file in your GeometricArea.cpp source code and you can use that exception object..
The test driver for this program is named SpecificationException_test.cpp because it is supposed to call GeometricArea functions with values that trigger an exception.
Explanation / Answer
//SpecificationException.h
#include <exception>
using namespace std;
class SpecificationException : public exception
{
public:
SpecificationException();
virtual const char* what() const throw();
};
-----------------------------------------------------------------------------------------------------------------------------
//SpecificationException.cpp
#include"SpecificationException.h"
const char* SpecificationException::what() const throw()
{
return "Exception occured: negetive user input" ;
}
SpecificationException::SpecificationException()
{
}
--------------------------------------------------------------------------------------------------------
//Chenged SpecificationException_test.cpp, u can find the changed under name //chegg EA
#include <iostream>
#include <string>
#include <cmath>
#include"SpecificationException.h"
#include "GeometricArea.h"
using namespace std;
int main()
{
int numSides;
float first, second, third, fourth;
char response;
response = 'y';
//checgg EA declared object e of SpecificationException
SpecificationException e;
while (response == 'y') {
cout << "Enter the number sides:";
//checgg EA , to check for negetive input
try
{
cin >> numSides;
if (numSides < 0)
throw e;
}
catch (SpecificationException & e)
{
cout << e.what() << endl;
}
if (numSides == 1) {
cout << "Enter the radius: ";
cin >> first;
//checgg EA , to check for negetive input
try
{
if (first < 0)
throw e;
}
catch (SpecificationException & e)
{
cout << e.what() << endl;
return -1;
}
cout << "Area is: " << getArea(numSides, first) << endl;
}
else if (numSides == 3) {
cout << "Enter the dimension of side 1: ";
cin >> first;
cout << "Enter the dimension of side 2: ";
cin >> second;
cout << "Enter the dimension of side 3: ";
cin >> third;
//Checgg EA
try
{
if (first < 0 || second < 0 || third < 0)
throw e;
}
catch (SpecificationException & e)
{
cout << e.what() << endl;
return -1;
}
cout << "Area is: " << getArea(numSides, first, second, third) << endl;
}
else if (numSides == 4) {
cout << "Enter the dimension of side 1: ";
cin >> first;
cout << "Enter the dimension of side 2: ";
cin >> second;
cout << "Enter the dimension of side 3: ";
cin >> third;
cout << "Enter the dimension of side 4: ";
cin >> fourth;
//Chech EA
try
{
if (first < 0 || second < 0 || third < 0 || fourth < 0)
throw e;
}
catch (SpecificationException & e)
{
cout << e.what() << endl;
return -1;
}
cout << "Area is: " << getArea(numSides, first, second, third, fourth) << endl;
}
else {
cout << "Sorry, the area can not be calculated." << endl;
}
cout << "Go again? (y/n)";
cin >> response;
}
return 0;
}
----------------------------------
//output
Enter the number sides:1
Enter the radius: -1
Exception occured: negetive user input
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.