I know that private class data is only accessible within the class; however, the examples that I have read show similar use of private members in their program code. I am attempting to use functions to access and manipulate the private class members, but it is not working. What am I doing incorrectly? I have tried substituting the Data.SelectionF() function for Data.selection after the first cin and for all instances of the use of the selection member variables without success. I also tried the same approach for all instances of the value member variable. Thanks
#include <iostream>
#include <iomanip>
using namespace std;
class allData {
private:
char selection;
double r;
double centimeter;
double value;
public:
double ConvertC (double value);
double ConvertR (double value);
double valueF (double value);
char selectionF (char selection);
allData Data ();
} Data;
int main() {
cout << "Enter C for converting your Feet to Centimeters.\n"
"Enter R for converting your Inches to Centimeters.\n";
cin >> Data.selection;
cout << "\nYou selected to convert to: " <<
Data.selectionF(Data.selection) << ".\n\n";
cout << "Enter your starting value to two decimal places, and press
ENTER.\n\n";
cin >> Data.value;
cout << "\nYou entered a starting value of: " <<
Data.valueF(Data.value) << ".\n\n";
//switch to decide which conversion function to use from the structure
switch (Data.selectionF(Data.selection)) {
case 'c': { Data.ConvertC(Data.value);
cout << "Your Feet converted to Centimeters is: " <<
Data.ConvertC(Data.value) << "\n\n";
break;
}
case 'C': { Data.ConvertC(Data.value);
cout << "Your Feet converted to Centimeters is: " <<
Data.ConvertC(Data.value) << "\n\n";
break;
}
case 'r': { Data.ConvertR(Data.value);
cout << "Your Inches converted to Centimeters is: " <<
Data.ConvertR(Data.value) << "\n\n";
break;
}
case 'R': { Data.ConvertR(Data.value);
cout << "Your Inches converted to Centimeters is: " <<
Data.ConvertR(Data.value) << "\n\n";
break;
}
default: {cout << "You entered an invalid selection for your conversion"
"choice.\n";
break;
}
}
return 0;
}
//Function definitions
double allData::ConvertC (double value) {
centimeter = value * 30.48;
return centimeter;
}
double allData::ConvertR (double value) {
r = value * 2.54;
return r;
}
double allData::valueF (double value) {
return value;
}
char allData::selectionF (char selection) {
return selection;
}
//End of program.