I am getting an error of cannot open source file on all my \'.h\' files. Not sur
ID: 3645515 • Letter: I
Question
I am getting an error of cannot open source file on all my '.h' files. Not sure what the problem is. Im using C++ visual studio#include "stdafx.h"
#ifndef SHAPE_H
#define SHAPE_H
class Shape
{
public:
virtual double Area() const = 0;
virtual double Parimeter() const = 0;
private:
};
#endif
#ifndef CIRCLE_H
#define CIRCLE_H
#include "Shape.h"
class Circle: public Shape
{
public:
Circle();
void setRadius(const double r);
double getRadius() const;
virtual double Area() const;
virtual double Parimeter() const;
~Circle();
protected:
double Radius;
};
#endif
#include <iostream>
#include "Circle.h"
using namespace std;
const double PI = 3.14159;
Circle::Circle()
{
}
void Circle::setRadius(const double r)
{
Radius = r;
}
double Circle::getRadius() const
{
return(Radius);
}
double Circle::Area() const
{
return (PI * Radius * Radius);
}
double Circle::Parimeter() const
{
return(2 * PI * Radius);
}
Circle::~Circle()
{
}
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "Shape.h"
class Rectangle: public Shape
{
public:
Rectangle();
void setDimensions(int H, int W);
double getHeight();
double getWidth();
double Area() const;
double Parimeter() const;
~Rectangle();
private:
double Height;
double Width;
double A;
double P;
};
#endif
#include <iostream>
#include "Rectangle.h"
using namespace std;
Rectangle::Rectangle()
{
}
void Rectangle::setDimensions(int W, int H)
{
Width = W;
Height = H;
}
double Rectangle::getHeight()
{
return(Height);
}
double Rectangle::getWidth()
{
return(Width);
}
double Rectangle::Area() const
{
return(Width * Height);
}
double Rectangle::Parimeter() const
{
return((2 * Width) + (2 * Height));
}
Rectangle::~Rectangle()
{
}
//Main.cpp
#include <iostream>
#include "Circle.h"
#include "Rectangle.h"
using namespace std;
//Prototype
void displayMenu(void);
char getMenuSelection(void);
void Cir(void);
void Rec(void);
int main()
{
char action;
double r;
double h;
double w;
Rectangle rec;
Circle cir;
do
{
displayMenu(); //displays the intitial menu
action = getMenuSelection(); //gets the menu selection
if(action == 'c' || action == 'C')
{
cout << "Enter the radius of the circle: ";
cin >> r;
cir.setRadius(r);
cout << "Radius: " << r << endl;
cout << "Area: " << cir.Area() << endl;
cout << "Parimeter: " << cir.Parimeter() << endl;
}
if(action == 'r' || action == 'R')
{
cout << "Enter the height of the rectangle: ";
cin >> h;
cout << "Enter the length of the rectangle: ";
cin >> w;
rec.setDimensions(h, w);
cout << "Dimensions= " << "Hight: " << h << " Width: " << w << endl;
cout << "Area: " << rec.Area() << endl;
cout << "Parimeter: " << rec.Parimeter() << endl;
}
if(action == 'l' || action == 'L')
{
}
}
while(action != 'q' || action != 'Q'); //loop until program has been quit
cin.ignore(2);
}
void displayMenu() //Displays the initial starting menu options
{
cout << "==================================================================" << endl;
cout << "|*************** Enter C to create a circle object **************|" << endl;
cout << "==================================================================" << endl;
cout << "|************** Enter R to create a rectangle object ************|" << endl;
cout << "==================================================================" << endl;
cout << "|****************** Enter L to print array list *****************|" << endl;
cout << "==================================================================" << endl;
cout << "|*********************** Enter Q To quit ************************|" << endl;
cout << "==================================================================" << endl;
}
char getMenuSelection() //Gets the menu selection
{
cout << "Enter your choice and press enter:";
char action;
cin >> action;
switch(action)
{
case 'c':
case 'C':
return action;
break;
case 'r':
case 'R':
return action;
break;
case 'l':
case 'L':
return action;
break;
case 'q':
case 'Q':
exit(0);
break;
default: //if menu selection is not valid let the user know
cout << " Invalid selection: try again" << endl;
displayMenu();
getMenuSelection();
break;
}
return 0;
}
Explanation / Answer
#include "stdafx.h" #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double Area() const = 0; virtual double Parimeter() const = 0; private: }; #endif #ifndef CIRCLE_H #define CIRCLE_H #include "Shape.h" class Circle: public Shape { public: Circle(); void setRadius(const double r); double getRadius() const; virtual double Area() const; virtual double Parimeter() const; ~Circle(); protected: double Radius; }; #endif #include #include "Circle.h" using namespace std; const double PI = 3.14159; Circle::Circle() { } void Circle::setRadius(const double r) { Radius = r; } double Circle::getRadius() const { return(Radius); } double Circle::Area() const { return (PI * Radius * Radius); } double Circle::Parimeter() const { return(2 * PI * Radius); } Circle::~Circle() { } #ifndef RECTANGLE_H #define RECTANGLE_H #include "Shape.h" class Rectangle: public Shape { public: Rectangle(); void setDimensions(int H, int W); double getHeight(); double getWidth(); double Area() const; double Parimeter() const; ~Rectangle(); private: double Height; double Width; double A; double P; }; #endif #include #include "Rectangle.h" using namespace std; Rectangle::Rectangle() { } void Rectangle::setDimensions(int W, int H) { Width = W; Height = H; } double Rectangle::getHeight() { return(Height); } double Rectangle::getWidth() { return(Width); } double Rectangle::Area() const { return(Width * Height); } double Rectangle::Parimeter() const { return((2 * Width) + (2 * Height)); } Rectangle::~Rectangle() { } //Main.cpp #include #include "Circle.h" #include "Rectangle.h" using namespace std; //Prototype void displayMenu(void); char getMenuSelection(void); void Cir(void); void Rec(void); int main() { char action; double r; double h; double w; Rectangle rec; Circle cir; do { displayMenu(); //displays the intitial menu action = getMenuSelection(); //gets the menu selection if(action == 'c' || action == 'C') { cout > r; cir.setRadius(r); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.