Whenever I try to display class variables in my program I get weird results that I shouldn't be getting such as "-7.92985e+185" instead of a real number. I'm not sure where the problem is coming from, when the program ran off all functions it worked fine. Any help is appreciated, thanks in advance.
Proto.h
Code:
#ifndef proto_h
#define proto_h
class myArea
{
private:
double length_c;
double width_c;
double height_c;
public:
void setlw(double length, double width);
void setheight(double height);
void setlwh(double length, double width, double height);
void getlw(double length, double width);
void getheight(double height);
void getlwh(double length, double width, double height);
double findfloorarea(void);
double findawallarea(void);
double findvolume(void);
void show_findfloorarea(void);
void show_findwallarea(void);
void show_findvolume(void);
void show_height(void);
};
#endif
myArea.cpp
Code:
#include "proto.h"
#include <iostream>
using namespace std;
void myArea::setlw(double length, double width)
{
if (length_c > 0, width_c > 0)
{
length_c = length;
width_c = width;
}
}
void myArea::setheight(double height)
{
if (height_c > 0)
{
height_c = height;
}
}
void myArea::setlwh(double length, double width, double height)
{
if (length_c > 0, width_c > 0, height_c > 0)
{
length_c = length;
width_c = width;
height_c = height;
}
}
void myArea::getlw(double length, double width)
{
length = length_c;
width = width_c;
}
void myArea::getheight(double height)
{
height = height_c;
}
void myArea::getlwh(double length, double width, double height)
{
length = length_c;
width = width_c;
height = height_c;
}
void myArea::show_findfloorarea(void)
{
cout<<(length_c * width_c)<<endl;
}
void myArea::show_findwallarea(void)
{
cout<<(length_c * height_c)<<endl;
}
void myArea::show_findvolume(void)
{
cout<<(length_c * width_c * height_c)<<endl;
}
void myArea::show_height(void)
{
cout<<height_c<<endl;
}
main.cpp
Code:
#include <iostream>
#include "proto.h"
using namespace std;
void demo(const double & l, const double & w, const double & h);
int main()
{
demo(4,3,5);
demo(5,8,12);
demo(8,3,18);
demo(6,14,9);
demo(7,13,2);
return 0;
}
void demo(const double & l, const double & w, const double & h)
{
myArea area;
cout<<"Using functions: 'setlw()','getlw()' and 'show_findfloorarea()', with the parameters "<<l<<", "<<w<<"."<<endl;
area.setlw(l,w);
area.getlw(l,w);
area.show_findfloorarea();
cout<<"Using functions: 'setheight()','getheight()' and 'show_findwallarea()' with the parameter "<<h<<"."<<endl;
area.setheight(h);
area.getheight(h);
area.show_findwallarea();
cout<<"Using functions: 'setlwh()','getlwh()' and 'show_findvolume()' with the parameters "<<l<<", "<<w<<", "<<h<<"."<<endl;
area.setlwh(l,w,h);
area.getlwh(l,w,h);
area.show_findvolume();
cout<<endl;
}