Solved

Question for C++

Posted on 2004-04-22
9
891 Views
Last Modified: 2012-06-21
Hi, can someone help me with these 5 questions. I could not find the answers. The questions are multiple-choice.

1. Which statement is true about classes?
A) The class declaration should be contained in a .cpp file.
B) An error will occur if the function is written within the class declaration.
C) The class function definitions (source code) should be placed in the .cpp file.
D) Class declarations and definitions (source code) should be placed in the .cpp file.

2. An overloaded operator member class member function is convenient for:
A) Comparing two objects of the same class
B) Initializing variables in an object
C) Ensuring that data hiding has been performed
D) Adding two objects that are not related

3. If class A contains an overloaded binary operator function, what is not true?
A) The operator function must have a data type A as an input.
B) The operator function must have a return data type.
C) The operator function will have a void return type.
D) All of these statements are true.

4. The use of classes is an example of which principle of object oriented language?
A) Encapsulation
B) Modularity
C) Abstraction
D) Polymorphism

5. Where are class variables initialized?
A) Only in a function
B) Only in a constructor
C) In a function or a constructor
D) In the variable declaration


Thanks,
mocca23
0
Comment
Question by:mocca23
9 Comments
 

Accepted Solution

by:
denago earned 20 total points
ID: 10895538
1: C
2: A
3: A
4: A
5: C
0
 

Expert Comment

by:titan203
ID: 10895934
1:C
2:B
3:B
4:D
5:C
0
 

Author Comment

by:mocca23
ID: 10896178
Which one of you have correct answers?
Thanks,
mocca23
0
 
LVL 1

Assisted Solution

by:hensz
hensz earned 20 total points
ID: 10896885
1: C (you can put the class definition in the header or the cpp file, but usually you should put it in the cpp file. the header should contain the declaration. An exception to this rule is that template classes are usually declared and defined in the header)

2: A (this question is not very good. You can perform nearly everything with overloaded operators. Any programmer has a different sense of what is convenient for him ;-)

3: A may not true if the operator is no member but a friend e.g. friend value& operator-(const value&), which can also be formulated as value& operator-()
   B is true
   C is not true.
   D is of course not true

4: This is a really academic question. Is it from an exercise or a diploma? Normally you should have a lesson in which you learn some definition that is asked for here.
With some knowledge of C++ I would say that all four answers are correct - under certain circumstances:
  A can be true, a class can encapsulate a certain behaviour (e.g. if you write a class containing only static functions)
  B is true, using classes you have modules you can reuse later
  C is true, if you use abstract classes and inherit from them later
  D is true, because you can only have abstraction if you use classes and inherit new classes.

5: C is true - but D can be true if you have static const member variables. These can be initialized during the variable declaration.

Before you ask again which answers are correct: Where did you get these questions from? As you can see, with some argumentation there are more than one possible answers.

I hope this helped.
CU, Torsten
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:hensz
ID: 10897425
1: C (you can put the class definition in the header or the cpp file, but usually you should put it in the cpp file. the header should contain the declaration. An exception to this rule is that template classes are usually declared and defined in the header)

2: A (this question is not very good. You can perform nearly everything with overloaded operators. Any programmer has a different sense of what is convenient for him ;-)

3: A may not true if the operator is no member but a friend e.g. friend value& operator-(const value&), which can also be formulated as value& operator-()
   B is true
   C is not true.
   D is of course not true

4: This is a really academic question. Is it from an exercise or a diploma? Normally you should have a lesson in which you learn some definition that is asked for here.
With some knowledge of C++ I would say that all four answers are correct - under certain circumstances:
  A can be true, a class can encapsulate a certain behaviour (e.g. if you write a class containing only static functions)
  B is true, using classes you have modules you can reuse later
  C is true, if you use abstract classes and inherit from them later
  D is true, because you can only have abstraction if you use classes and inherit new classes.

5: C is true - but D can be true if you have static const member variables. These can be initialized during the variable declaration.

Before you ask again which answers are correct: Where did you get these questions from? As you can see, with some argumentation there are more than one possible answers.

I hope this helped.
CU, Torsten
0
 

Author Comment

by:mocca23
ID: 10902408
These questions are from my C++ test. The questions are kinda tricky.
Guys, thanks a lot for the answers.

mocca23
0
 
LVL 1

Expert Comment

by:hensz
ID: 10916233
What C++ test? A multiple choice - one answer is correct - test, or some oral test where you should comment your answers?

If these questions are from a "only one answer is correct" test I consider the test more than bad. Perhaps the answers were given in a previos lesson, but if only those are permitted the test suppresses thinking... but I think this won't help you much ;-)

CU, Torsten
0
 

Author Comment

by:mocca23
ID: 10923785
I am taking C++ online. The test was multiple choice-only one answer. I had 20 questions on the test. Most of the questions were very similar to these and very unclear. Actually all the tests from the beginning were very confusing. Also, the hardest part of this course are programs. I need to finish my last program until next Tuesday, but I am stuck on the main program.  I have no idea how to finish. This course drives me crazy. I am so glad that this semester is almost over. This is one of the hardest courses that I have ever had.

mocca23
0
 

Author Comment

by:mocca23
ID: 10933429
The correct answers for questions are
1: C
2: A
3: C
4: B
5: C

mocca23
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now