In: Computer Science
I am getting the fallowing error when I compile my application:
mingw32-g++.exe -Wall -fexceptions -g -c E:\vmmar\Area\area\main.cpp -o obj\Debug\main.o
E:\vmmar\Area\area\main.cpp: In function 'int main()':
E:\vmmar\Area\area\main.cpp:41:15: error: 'setRadius' was not declared in this scope
setRadius(rad);
^
E:\vmmar\Area\area\main.cpp:42:15: error: 'setShapeId' was not declared in this scope
setShapeId(id);
^
E:\vmmar\Area\area\main.cpp:43:23: error: 'setUnitOfMeasure' was not declared in this scope
setUnitOfMeasure(unit);
^
E:\vmmar\Area\area\main.cpp:44:23: error: 'setShapeType' was not declared in this scope
setShapeType("Circle");
^
E:\vmmar\Area\area\main.cpp:45:41: error: 'getArea' was not declared in this scope
cout << "Area of Circle : " << getArea() << endl;
^
E:\vmmar\Area\area\main.cpp:46:10: error: 'display' was not declared in this scope
display();
^
E:\vmmar\Area\area\main.cpp:57:13: error: 'setLength' was not declared in this scope
setLength(l);
^
Process terminated with status 1 (0 minute(s), 0 second(s))
7 error(s), 0 warning(s) (0 minute(s), 0 second(s))
######################################################################################################################
The following is my entire application:
#ifndef SHAPE_H_INCLUDED
#define SHAPE_H_INCLUDED
#include <iostream>
using namespace std;
const float PI = 3.1415926;
class Shape{
private:
string shapeType;
string shapeId;
string unit_of_measure;
public:
Shape(){}
Shape(string id){
shapeId = id;
}
Shape(string Id, string type, string unit){
shapeId = Id;
shapeType = type;
unit_of_measure= unit;
}
string getShapeType(){
return shapeType;
}
string getSgapeId(){
return shapeId;
}
string getUnitOfMeasure(){
return unit_of_measure;
}
void setShapeType(string type){
shapeType = type;
}
void setShapeId(string id){
shapeId = id;
}
void setUnitOfMeasure(string unit){
unit_of_measure = unit;
}
virtual float getArea() = 0;
};
#endif // SHAPE_H_INCLUDED
###############################################################################################################################
#ifndef AREACIRCLE_H_INCLUDED
#define AREACIRCLE_H_INCLUDED
#include "Shape.h"
using namespace std;
/* Circle Class */
class Circle:public Shape
{
private:
float radius;
public:
/* set value for radius */
void setRadius(float rad)
{
radius = rad;
}
/* get the value of radius */
float getRadius()
{
return radius;
}
// float radius;
}; //float areaCircle;
#endif // AREACIRCLE_H_INCLUDED
###############################################################################################################################
#ifndef AREASQUARE_H_INCLUDED
#define AREASQUARE_H_INCLUDED
#include "Shape.h"
using namespace std;
class Square:public Shape
{
private:
float sidelen;
public:
/* get the value of length */
float getLength()
{
return sidelen;
}
/* set value for length */
void setLength(float l)
{
sidelen = l;
}
};
#endif // AREASQUARE_H_INCLUDED
################################################################################################################################
#include <iostream>
#include "Circle.h"
#include "Shape.h"
using namespace std;
/* Constructor */
Circle():Shape()
{
{
radius = 0;
}
/* Copy Constructor, which takes a parameter */
Circle(string id, float rad):Shape(id)
{
radius = rad;
}
Circle(string id, string type, string unit, float rad):
Shape(id, type, unit){
radius = rad;
}
/* Method to calculate the area of circle */
float getArea()
{
return PI*radius*radius;
}
void display(){
cout<<"Shape Id: "<<getSgapeId()<<endl;
cout<<"Shape Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
}
#################################################################################################################################
#include <iostream>
#include "Square.h"
#include "Shape.h"
using namespace std;
Square():Shape()
{
{
sidelen = 0;
}
/* Copy Constructor, which takes a parameter */
Square(string id, float l):Shape(id)
{
sidelen = l;
}
Square(string id, string type, string unit, float l): Shape(id,
type, unit)
{
sidelen = l;
}
/* Method to calculate the area of circle */
float getArea()
{
return sidelen * sidelen;
}
void display()
{
cout<<"Shape Id: "<<getSgapeId()<<endl;
cout<<"Shape Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
}
####################################################################################################################################
#include <iostream>
#include "Square.h"
#include "Circle.h"
#include "Shape.h"
using namespace std;
int main()
{
/*Circle = circle1;
Square = square1;
*/
float rad;
float l ;
int menuOption;
string id, type, unit;
do
{ // Starting of while loop
cout << endl << "=========CALCULATE
AREA================" << endl;
cout<< endl
<< "Select an Object" << endl
<< " 1: Circle" << endl
<< " 2: Square" << endl
<< " 0: Exit" << endl
<< " Enter Your Choice: ";
cin >> menuOption;
switch(menuOption)
{
case 1:
cout<<"Enter shape id: ";
cin>>id;
cout<<"Enter unit of measure: ";
cin>>unit;
cout<< "Enter radius of the circle : ";
// float rad;
cin >> rad;
setRadius(rad);
setShapeId(id);
setUnitOfMeasure(unit);
setShapeType("Circle");
cout << "Area of Circle : " << getArea() <<
endl;
display();
break;
case 2:
cout<<"Enter shape id: ";
cin>>id;
cout<<"Enter unit of measure: ";
cin>>unit;
cout<< "Enter length of one side of the square : ";
//float l ;
cin >> l;
setLength(l);
setShapeId(id);
setShapeType("Square");
setUnitOfMeasure(unit);
display();
cout << "Area of Square : " << getArea() <<
endl;
break;
}
} while(menuOption!=0);
{
cout << endl<< endl <<
"============== THANK YOU ===================" <<
endl<< endl;
return 0;
}
}
##############################################################################################################################
// Here is compilable code. There were multiple mistake and it is difficult to highlisht them. Use some diff tool to see exact changes.
// Shape.h
#ifndef SHAPE_H_INCLUDED
#define SHAPE_H_INCLUDED
#include <iostream>
using namespace std;
const float PI = 3.1415926;
class Shape{
private:
string shapeType;
string shapeId;
string unit_of_measure;
public:
Shape(){}
Shape(string id){
shapeId = id;
}
Shape(string Id, string type, string unit){
shapeId = Id;
shapeType = type;
unit_of_measure= unit;
}
string getShapeType(){
return shapeType;
}
string getSgapeId(){
return shapeId;
}
string getUnitOfMeasure(){
return unit_of_measure;
}
void setShapeType(string type){
shapeType = type;
}
void setShapeId(string id){
shapeId = id;
}
void setUnitOfMeasure(string unit){
unit_of_measure = unit;
}
virtual float getArea() = 0;
};
#endif // SHAPE_H_INCLUDED
// Circle.h
#ifndef AREACIRCLE_H_INCLUDED
#define AREACIRCLE_H_INCLUDED
#include "Shape.h"
using namespace std;
/* Circle Class */
class Circle:public Shape
{
private:
float radius;
public:
Circle();
Circle(string id, float rad);
Circle(string id, string type, string unit, float rad);
float getArea();
void display();
/* set value for radius */
void setRadius(float rad)
{
radius = rad;
}
/* get the value of radius */
float getRadius()
{
return radius;
}
// float radius;
}; //float areaCircle;
#endif // AREACIRCLE_H_INCLUDED
// Circle.cpp
#include <iostream>
#include "Circle.h"
#include "Shape.h"
#include <math.h>
using namespace std;
/* Constructor */
Circle::Circle():Shape()
{
radius = 0;
}
/* Copy Constructor, which takes a parameter */
Circle::Circle(string id, float rad):Shape(id)
{
radius = rad;
}
Circle::Circle(string id, string type, string unit, float rad):
Shape(id, type, unit){
radius = rad;
}
/* Method to calculate the area of circle */
float Circle::getArea()
{
return M_PI*radius*radius;
}
void Circle::display(){
cout<<"Shape Id: "<<getSgapeId()<<endl;
cout<<"Shape Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
// Square.h
#ifndef AREASQUARE_H_INCLUDED
#define AREASQUARE_H_INCLUDED
#include "Shape.h"
using namespace std;
class Square:public Shape
{
private:
float sidelen;
public:
Square();
Square(string id, float rad);
Square(string id, string type, string unit, float rad);
float getArea();
void display();
/* get the value of length */
float getLength()
{
return sidelen;
}
/* set value for length */
void setLength(float l)
{
sidelen = l;
}
};
#endif // AREASQUARE_H_INCLUDED
//Square.cpp
#include <iostream>
#include "Square.h"
#include "Shape.h"
using namespace std;
Square::Square():Shape()
{
sidelen = 0;
}
/* Copy Constructor, which takes a parameter */
Square::Square(string id, float l):Shape(id)
{
sidelen = l;
}
Square::Square(string id, string type, string unit, float l):
Shape(id, type, unit)
{
sidelen = l;
}
/* Method to calculate the area of circle */
float Square::getArea()
{
return sidelen * sidelen;
}
void Square::display()
{
cout<<"Shape Id: "<<getSgapeId()<<endl;
cout<<"Shape Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
// main.cpp
#include <iostream>
#include "Square.h"
#include "Circle.h"
#include "Shape.h"
using namespace std;
int main()
{
/*Circle = circle1;
Square = square1;
*/
float rad;
float l ;
int menuOption;
string id, type, unit;
do
{ // Starting of while loop
cout << endl << "=========CALCULATE
AREA================" << endl;
cout<< endl
<< "Select an Object" << endl
<< " 1: Circle" << endl
<< " 2: Square" << endl
<< " 0: Exit" << endl
<< " Enter Your Choice: ";
cin >> menuOption;
Square sq = Square();
Circle c = Circle();
switch(menuOption)
{
case 1:
cout<<"Enter shape id: ";
cin>>id;
cout<<"Enter unit of measure: ";
cin>>unit;
cout<< "Enter radius of the circle : ";
// float rad;
cin >> rad;
//Circle c = Circle();
c.setRadius(rad);
c.setShapeId(id);
c.setUnitOfMeasure(unit);
c.setShapeType("Circle");
cout << "Area of Circle : " << c.getArea() <<
endl;
c.display();
break;
case 2:
cout<<"Enter shape id: ";
cin>>id;
cout<<"Enter unit of measure: ";
cin>>unit;
cout<< "Enter length of one side of the square : ";
//float l ;
cin >> l;
//Square sq = Square();
sq.setLength(l);
sq.setShapeId(id);
sq.setShapeType("Square");
sq.setUnitOfMeasure(unit);
sq.display();
cout << "Area of Square : " << sq.getArea() <<
endl;
break;
}
} while(menuOption!=0);
cout << endl<< endl << "============== THANK YOU
===================" << endl<< endl;
return 0;
}
// Here is link for code https://goo.gl/lkxddo
sh-4.2$ g++ *.cpp *.h
sh-4.2$