Guest_imported
New member
- Jan 1, 1970
- 0
I'm not sure how to properly use classes and header files and then implementing the class in another file. So let'S say I have two files. Formulas.h and then Formulas.cc. Formulas.h is my header file and .cc is where I implement the information. This is just an example so I can reference when I start writing my program. Thanks
Following Criteria:
User enters two integers. The two integers are then added together to get let's say the "Pie Value" (these are not the formulas but just for purposes of learning) the two integers are also subtracted to get the "Quad Value." My problem I am having is I"m not sure if I"m writin the class and implementing it correctly. This was what I was thinking but I"m not sure.
***************************************************
//Formula.h
Class Formula{
private:
int pie, quad;
int AddSub();
public:
Formula(int const a, int const b); // constructor
};
//Formula.cc
Formula::Formula(int a, int b) : pie(a), quad(b) {AddSub()};
int Formula::AddSub(){
double pieval, addval;
Formula A;
cin >> A.pie >> A.quad;
pieval = A.pie + A.quad;
quadval = A.pie - A.quad;
cout << pieval << '\n' << quadval;
};
***************************************************
This is the only way to do this (with a .h and a .cc file because the program I am going to create needs these two files and I am not sure how either should look)
Following Criteria:
User enters two integers. The two integers are then added together to get let's say the "Pie Value" (these are not the formulas but just for purposes of learning) the two integers are also subtracted to get the "Quad Value." My problem I am having is I"m not sure if I"m writin the class and implementing it correctly. This was what I was thinking but I"m not sure.
***************************************************
//Formula.h
Class Formula{
private:
int pie, quad;
int AddSub();
public:
Formula(int const a, int const b); // constructor
};
//Formula.cc
Formula::Formula(int a, int b) : pie(a), quad(b) {AddSub()};
int Formula::AddSub(){
double pieval, addval;
Formula A;
cin >> A.pie >> A.quad;
pieval = A.pie + A.quad;
quadval = A.pie - A.quad;
cout << pieval << '\n' << quadval;
};
***************************************************
This is the only way to do this (with a .h and a .cc file because the program I am going to create needs these two files and I am not sure how either should look)