| [ |
mood |
| |
confused |
] |
Heyas.
Ok, I'm currently a console C++ programmer (blame school). I need help with something though.
First is, I've read numerous books. looked at code, etc, and I just can't figure out classes. I have an idea, but I'd like some more information. Resources or a tutorial posted here would be magnificent.
For now, the program at hand.
This program is designed to accept user input for a shape (square, triangle, trapezoid, etc.), and then prompt for base/height, or a side, or length/width, etc.
At first, I was going to make one function for each object, then I decided against it.
What I'm trying to figure out, is if I can make a function call out of the contents of a variable.
say, the user inputs 'square' into a varable char shape[];
I was trying to call void shape();, but I knew that would work. So then I started screwing with parameters, passing the contents of char shape to a function that would do stuff :P.
That's where I'm hung up, I think I got an idea, but I hit wall, and I need help.
If the user enters square, I need the function to see that I have the variable side defined for it. But, if the user enters triangle, I need the function to that I have the variables base, and height defined for it.
I was thinking that I could do this with structs (although I want to use classes, but as stated above, I need help still), but my question is...is there a way to just call the variable name?
Is there anyway I could do something to the effect of:
cout << "Please enter the " << shape << "\'s " << svar1 << ": "; cin >> ****** <-- that's where I'm hung up.
Is there anyway that I could say that shape.svar1 is square.side? (side defined as an unsigned or long integer) But if the user enters rectangle, it would prompt for svar2 (more for other shapes), as well, so it would store data to rectangle.length and rectangle.width?
|