Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ Test 3: Inheritance/Object-Orientation

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Qvazzler
Advanced Cheater
Reputation: 0

Joined: 02 Jan 2007
Posts: 68

PostPosted: Sun Oct 21, 2007 5:30 am    Post subject: C++ Test 3: Inheritance/Object-Orientation Reply with quote

Might aswell skip the second test, I underestimated alot of people on here. Smile
Also, don't go on thinking it's my homework that needs to be done again. If I would want the right answers asap I would go to someone else. Fortunately I had this test last friday and I aced it, so I guess most of you pro's will be able to ace this one aswell. I hope it hasn't been too rubbishly written, I have to translate it from swedish after all. Wink

1. What do you call a variable created by a class?

2. What is true about reachability (internally) of private attributes that a class inherits from?

  • The class that inherits cannot have any attributes
  • It's not possible to inherit from a class with private attributes
  • The class that inherits can only reach public attributes
  • The class that inherits can reach all private attributes
  • the inheriting class can only read private attributes that are variables
  • a class cannot have private attributes at all

3. Describe the term "Base class" (this is used as a professional term)

4. Describe the term "Sub class" (this is also used as a professional term)

5. In a class called 'Color', we have the following constructor:

Code:

Color (float Red = 0.0, float Blue = 0.0, float Green = 0.0);

- Which of the following statements are true? (only 1 is correct)
  • It's not possible to create an object of Color because all the
  • values are 0
  • You can add up to 3 strings as an argument
  • You have to use 3 float-types as parameters
  • You can use up to 3 float-types as parameters

6. How do you write it so that a class inherits from another class in C++?
  • class Banana inherits Fruit
  • Banana->Fruit
  • public override Fruit : Banana
  • class Banana : Fruit
  • class Banana extends Fruit

7. We've declared a method called "calculate(int val1, int val2);" in a header-file for our class called "Calculator". What do we have to write to implement this function into the class? Choose the correct alternative:
  • int Calculator::calculate(int val1, int val2)
  • int Calculator extends calculate(int val1, int val2)
  • int Calculator overrides calculate(int val1, int val2)
  • int Calculator->calculate(int val1, int val2)
  • int Calculator => calculate(int val1, int val2)
  • Calculator::int calculate(int val1, int val2)
  • void Calculator calculate(int val1, int val2)
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Oct 21, 2007 11:49 am    Post subject: Reply with quote

1. An object.
2. "The class that inherits can only reach public attributes"
3. Base class is another way of saying 'superclass'. "A class of which another class is an extension, and hence defines properties that are inherited by the other class"
4. The extension class that is used with the base class.
5. "You can use up to 3 float-types as parameters"
6. class Banana : Fruit
7. int Calculator::calculate(int val1, int val2)
Back to top
View user's profile Send private message Visit poster's website
Qvazzler
Advanced Cheater
Reputation: 0

Joined: 02 Jan 2007
Posts: 68

PostPosted: Sun Oct 21, 2007 12:02 pm    Post subject: Reply with quote

Although the correct answer on the second question was:

The class that inherits can reach all private attributes.

That was still Surprised

You guys are far more skillful than I am. Laughing
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Oct 21, 2007 12:03 pm    Post subject: Reply with quote

Qvazzler wrote:
Although the correct answer on the second question was:

The class that inherits can reach all private attributes.

That was still Surprised

You guys are far more skillful than I am. Laughing


Really? When I've done some classes setup to inherit others, I couldn't touch the private members. Just as if you tried reaching them normally from a single class.
Back to top
View user's profile Send private message Visit poster's website
Qvazzler
Advanced Cheater
Reputation: 0

Joined: 02 Jan 2007
Posts: 68

PostPosted: Sun Oct 21, 2007 12:08 pm    Post subject: Reply with quote

That's what my teacher told me.. He's been (learning about) programming since he was 8 and he's 25 now. Razz You don't have to take my/his word for it though, as I am lacking good arguments to tell you why you're wrong.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Oct 21, 2007 12:18 pm    Post subject: Reply with quote

Qvazzler wrote:
That's what my teacher told me.. He's been (learning about) programming since he was 8 and he's 25 now. Razz You don't have to take my/his word for it though, as I am lacking good arguments to tell you why you're wrong.


Just tested it again, and yea.. I get told I can't access it:

Code:
error C2248: 'SubClass::SubValue' : cannot access private member declared in class 'SubClass'
Back to top
View user's profile Send private message Visit poster's website
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sun Oct 21, 2007 1:02 pm    Post subject: Reply with quote

It's real easy to access a private member from another class. All you have to do is make sure they are friends.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Oct 21, 2007 1:05 pm    Post subject: Reply with quote

killersamurai wrote:
It's real easy to access a private member from another class. All you have to do is make sure they are friends.


Ah, true. His questions didn't pertain to include anything of friend classes so I didn't even think of them Mad
Back to top
View user's profile Send private message Visit poster's website
TheSorc3r3r
I post too much
Reputation: 0

Joined: 06 Sep 2006
Posts: 2404

PostPosted: Mon Oct 22, 2007 3:36 pm    Post subject: Reply with quote

Wiccaan/Qvazzler: protected is the keyword you're both looking for.

Only a subclass can access its parent class's protected members.

_________________


Don't laugh, I'm still learning photoshop!
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Oct 22, 2007 6:19 pm    Post subject: Reply with quote

TheSorc3r3r wrote:
Wiccaan/Qvazzler: protected is the keyword you're both looking for.

Only a subclass can access its parent class's protected members.


The protected section of a class wasn't what we were talking about. The question at hand was directly focused on the private section of a class.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
nox
Expert Cheater
Reputation: 0

Joined: 09 Apr 2007
Posts: 227
Location: brooklyn

PostPosted: Mon Oct 22, 2007 9:47 pm    Post subject: Reply with quote

what kind of teacher teaches obj-o on the second day Confused
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites