• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Some Basic C++ Help Needed

mjh

Platinum Member
Last homework problem reads: Write a value-returning function that converts the name of a planet given as a string parameter to a value of the enumeration type declared in exercise 12. If the string isn't a propler planet name, return EARTH.

This is the answer I got for exercise 12: enum Planets {MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO};

I am still not exactly sure what I must do. Should I use enum? Should I case it? Do I need to create a list of the possible values?

Any tips would be greatly appreciated!
 
Consider the basic parts of a function and assign the components listed in the hw question to these basic parts of a function.

return_value function_name (input_value) {
...
...
return return_value
}

Put the pieces together.
The control structure within the function is up to your imagination.
 
I hope the help provided a structured direction of thought. Remember that an algebraic function is defined by a black box (cannot see its internal components) and for any specific input, there will only be one possible output.

y = mx + b
For any possible input for x, there will be only one possible y value.

Focus on this aspect. (Input) -> (black box) -> (Output).

Thinking about a problem in this manner provides a structured direction of thought.

For example, consider any possible PCI card that may be handed to you. If you look at the input connection and the output connection, you can deduce the card's unknown function (black box).

This method of thinking, once helped me greatly in a job interview for an software engineering position. I was handed an unmarked PCI card and asked what it does. I had no idea what the green circuit board did, so I looked at the input connection (coaxial), then the output connection (ethernet cable), and correctly deduced the card's purpose was to transfer digital coaxial signals to analog. This was an easy accomplishment due to the structured analytical approach that I used to look at it.
 
Back
Top