C++, how to set information when calling the method of a class?
-
An example of what I'm trying to do is: If we created a method of the class Person and Katie called that method, how would we set Katie’s age to 2 within that method? How would we set Katie’s hair color to red within that method? How would we write the call to the method? How would you do this with c++ code? I'm trying to figure out not only what the code would be, but also what's going on, like if a constructor function, friend function, etc. is being used.
-
Answer:
consider the class class person { private : int Age ; char Haircolor[10]; public void setAge(int p_age ) { Age=p_age ; } public void setHairColor(char[] p_haircolor) { Haircolr = p_haircolor; } } void main() { person Katie ; Katie.setAge(20); Katie.setHairColor("Red"); }
Will at Yahoo! Answers Visit the source
Other answers
So you have a class Person, and an object Katie of class Person. You would create a method setAge(int value); and in that method you set the private data member 'age' of object Katie to age = value. That's one example.
therandomer
Related Q & A:
- How to set the C++ standard in eclipse?Best solution by stackoverflow.com
- How to Set Specific Site Collection as SharePoint Search Scope using C#?Best solution by SharePoint
- How do you know when it is time for a first kiss?Best solution by Yahoo! Answers
- What to say when calling about a job application status?Best solution by Yahoo! Answers
- What do they mean when they say it is a set up job?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.