Here is my code I'm pretty sure the problem has to do with using namespace std and the included header files but I can't figure it out (error string no such file or directory in .h, error iostream no such file or directory in .h,error syntax error before namespace)
box.h:
#ifndef _BOX
#define _BOX
#include <string>
#include <iostream>
using namespace std;
class Box
{
private:
double height, width, depth;
string name;
public:
Box();
Box(double,double,double,string);
void setHeight(double);
void setWidth(double);
void setDepth(double);
void setName(string);
double getHeight();
double getWidth();
double getDepth();
double Area();
double Volume();
void Display(ostream&);
};
#endif
Box.cpp:
#include "Box.h"
#include <string>
#include <iostream>
using namespace std;
Box::Box()
{
height = 0;
width = 0;
depth = 0;
}
Box::Box(double h,double w,double d)
{
height = h;
width = w;
depth = d;
}
void Box::setHeight(double h)
{
height = h;
}
void Box::setWidth(double w)
{
width = w;
}
void Box::setDepth(double d)
{
depth = d;
}
void Box::setName(string n)
{
name = n;
}
double Box::getHeight()
{
return height;
}
double Box::getWidth()
{
return width;
}
double Box::getDepth()
{
return depth;
}
std::string Box::getName()
{
return name;
}
double Box::Area()
{
return 2 * (height * width) + 2 * (width * depth) + 2 * (height * depth);
}
double Box::Volume()
{
return height * width * depth;
}
void Box::Display(ostream &output)
{
output << "Height = " << height << std::endl
<< "Width = " << width << std::endl
<< "Depth = " << depth << std::endl
<< "Name = " << name;
}
boxDriver.cpp:
#include "Box.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "\n\n OUTPUT FROM SAMPLE DRIVER\n\n\n";
Box a(5, 2.3, 10.1);
a.setName("Box 1");
cout << "CALL DISPLAY FUNCTION \n";
a.Display(cout);
cout << endl;
cout << "\n*** END Display Function *** \n\n";
cout << "Area = " << a.Area() << endl;
cout << "Volume = " << a.Volume() << endl;
cout << "\n\n******************* Second Box ***********************\n\n\n";
Box b;
// Set Attributes
b.setHeight(2.7);
b.setWidth(24.05);
b.setDepth(3.22);
b.setName("Box 2");
cout << "CALL DISPLAY FUNCTION \n";
b.Display(cout);
cout << endl;
cout << "\n*** END Display Function *** \n\n";
cout << "Area = " << b.Area() << endl;
cout << "Volume = " << b.Volume() << endl;;
cin.get();
return 0;
}
Thanks