Can anyone please tell me what have I done wrong in the program below? :
// C++-Assignment2.cpp
#include <iostream.h>
#include <conio.h>
class fahrenheit
{
private:
int fah;
public:
fahrenheit()
{
fah=0;
}
void fget();
void fdisp();
};
class celsius: public fahrenheit
{
private:
int cel;
public:
void calc();
void cdisp();
};
void fahrenheit::fget()
{
cout<<"\n Enter temperature value in Fahrenheits:";
cin>>fah;
}
void fahrenheit::fdisp()
{
cout<<"\n Temperature in Fahrenheits: "<<fah;
}
void celsius::calc()
{
cel=5*(fah-32)/9;
}
void celsius::cdisp()
{
cout<<"\n Temperature in Celsius:"<<cel;
}
void main()
{
clrscr();
celsius c1;
c1.fget();
c1.fdisp();
c1.calc();
c1.cdisp();
getch();
}
I'm sorry if it was asked before, but I couldn't find a question in which the user mentioned that they included a constructor (like how I did). Also, I do understand this program does not really make that much sense (considering how I framed those two units and such). Still a beginner, so not really into 'perfecting' semantics at the moment.
Errors:
Compiling 2-ASSIGN.CPP:
Error 2-ASSIGN.CPP 36: 'fahrenheit::fah' is not accessible in function celsius::calc()
Error 2-ASSIGN.CPP 36: 'fahrenheit::fah' is not accessible in function celsius::calc()