1st Constructor –
no parameters. Initialize all String variables to empty string, all int and float variables to 0.
2nd Constructor –
5 parameters. Initialize all attribute variables to the parameter’s values respectively.
then there is another method computeCivicIndex() which calculates the civilization based on the 5 values which are gotten from user input from the main menu.
My question is how do i get the values from the user input and call the values in the computeCivicIndex() method.
I used a couple of get and set methods to get the values
Ask the user for the input, call the set methods accordingly (or create a dynamic instance, passing the inputs to the constructor parameter) then, presuming computerCivicIndex is a function of that calls, call it to perform the functionality needed. If it's in the same class, it'll be aware of the variables, which will have been populated in the prior steps.
If it's part of the class that has the values for the parameters stored in it already there's no real need to pass anything into it. Consider this small example (note, I've made everything public so I can easily assign values for example purposes):
class MyClass
{
public:
int a, b, c;
int Add(); // Function to add three elements
}
int MyClass::Add() // No need for params, function is aware of a,b and c.
{
return a+b+c;
}
// in main...
MyClass thing;
thing.a = 1;
thing.b = 2;
thing.c = 3;
int result;
result = thing.Add();
cout << result; // result = 6