Page 97 - DCAP404 _Object Oriented Programming
P. 97

Object-oriented Programming




                    Notes          4.8 Review Questions

                                   1.  Define class. What is the difference between structures and classes in C++?

                                   2.  How can you pass an object of a C++ class to/from a C function?
                                   3.  Can a method directly access the non-public members of another instance of its class?

                                   4.  What’s the difference between the keywords struct and class?
                                   5.  Write a program to add two numbers defining a member getdata () and display () inside
                                       a class named sum and displaying the result.
                                   6.  How does C++ help with the tradeoff of safety vs. usability?

                                   7.  “The main advantage of using a static member is to declare the global data which should
                                       be updated while the program lives in memory”. Justify your statement.

                                   8.  Write a program to print the score board of a cricket match in real  time. The display
                                       should contain the batsman’s name, runs scored, indication if out, mode by which out,
                                       bowler’s score (overs played, maiden overs, runs given, wickets taken). As and when a
                                       ball is thrown, the score should be updated.
                                       (print: Use separate arrays to store batsmen’s and bowler’s information)

                                   9.  If a member of a class is public, it can be accessed by an external function including a
                                       derived class. Explain with an example.

                                   10.  Write a program in which a class has one private member (properties) and two public
                                       member  (method).
                                   Answers: Self  Assessment


                                   1.  functions                         2.   class
                                   3.  access specifier                  4.   variable
                                   5.  declaration                       6.   defined
                                   7.  class definition                  8.   scope resolution operator

                                   9.  scope                             10.  objects
                                   11.  name                             12.  declaration
                                   13.  external                         14.  private

                                   15.  public


















          90                                LOVELY PROFESSIONAL UNIVERSITY
   92   93   94   95   96   97   98   99   100   101   102