I wrote code in C++ in Xcode and receive:
error: ‘cylinder’ was not declared in this scope
Header file cylinder.h:
#include <iostream>
#ifndef cylinder_h
#define cylinder_h
#endif
#include "stdio.h"
using namespace std;
class cylinder
{
public:
// Constructors
cylinder();
cylinder(double r, double h);
// Accessors
double getRadius();
double getHeight();
void setRadius(double r);
void setHeight(double h);
double area();
double volume();
void write(std::ostream& output);
private:
double radius;
double height;
};
cylinder.cpp :
#include "cylinder.h"
double PI = 3.1415926535898;
#include "stdio.h"
using namespace std;
// Constructors
cylinder::cylinder()
{
radius = 0;
height = 0;
}
cylinder::cylinder(double r, double h)
{
radius = r;
height = h;
}
// Accessors
double cylinder::getRadius()
{
return radius;
}
double cylinder::getHeight()
{
return height;
}
// Setters
void cylinder::setRadius(double r)
{
radius = r;
}
void cylinder::setHeight(double h)
{
height = h;
}
// Calculations
double cylinder::area()
{
return 2 * PI * radius * radius + 2 * PI * radius * height;
}
double cylinder::volume()
{
return PI * radius * radius * height;
}
main.cpp:
#include <iostream>
using namespace std;
#include <string>
#include "cylinder.h"
#include <iomanip>
#include "sphere.h"
#include "prism.h"
#include "cone.h"
#include "pyramid.h"
#include <cstdlib>
int main()
{
double radius, height,sradius,length,width,rheight,cheight,cradius,pheight,plength;
cout << "Enter cylinder height and radius >>> ";
cin >> height >> radius;
cylinder one (radius, height);
cout << "The cylinder volume is " << setprecision(2)<<fixed<<one.volume () << endl;
cout << "The cylinder surface area is " << setprecision(2)<<fixed<<one.area () << endl;
cout <<"CYLINDER: "<<height<<", "<<radius<<endl;
}
I have been stuck for two days. I am so confused. I've already defined cylinder class, and I've tried many ways on the website. Is there anyone who can help me? It's due tonight!