Solved

Question for C++

Posted on 2004-04-22
9
893 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 165
C# DataGridView_RowsAdded event not firing 1 75
Math Equation 23 87
ASP/VB email question 4 35
This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

773 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