Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Q1. Consider the following program segment.

1 class A {

2 private:

3 int a = 1, b, c, d, *ptr;

4 public:

5 A() { int pr = new int[10];)

6 A (int b = 0) : this -> b(b) {}

7 void seta(int x) const {a = x;}

8 void setB(int x) {this.b = x ;}

9 void setC() {this -> C = ptr {0} ; }

10 void setD(int x) {d = x;}

11 -A(int *A) {

12 delete ptr;

13 ptr = x;

14 }

15

16 void main () {

17 const A a1;

18 A a2(1, 2, 3);

19 a1.setD(6);

20 cout << a1.ptr[1] << end 1;

1.a What's wrong with lint 3?

1.b What's wrong with the constructors?

1.c What's wrong with member function setA()?

1.d What's wrong with the function setB()?

1.e What's wrong with the function setC()?

1.f What's wrong with the destructor?

1.g What's wrong with the class itself?

1.h What's wrong with line 18?

1.i What's wrong with line 19?

1.j What's wrong with line 20?

Q2. State True or False for each of the following statements about friend function

i. Friend function is a member function.

ii. Friend function is declared, not defined, in a class.

iii. Friend function has the right to access the public and private members of the class in which it is declared.

iv. Friend function is inherited.

v. Friend function of a class can be a member function of another class.

Q3. Write the function header of the default copy constructor for a class called A.

Q4. Write one default constructor prototype of a class called A.

Q5. Write a destructor of class B that deletes the object pointed by the pointer ptr.

Q6. Write the class headier of a class called B that use protected inheritance to inherit class J.

Q7. Write a statement that dynamically mate object of class B;

Q8. Fill in the blanks.

a. _________ is a form of software reuse in which new classes absorb the data and behaviors of existing classes and embellish these classes with new capabilities.

b. A function that is not defined in a class is called _________.

c. C++ provides for _________, which allows a derived class to inherit from many base classes, even if the base classes are unrelated.

d. When an object of a derived class is instantiated, the base class's _________ is called implicitly or explicitly to do any necessary initialization of the base class data members in the derived class object.

e. When a variable is declared in {}, it has a _________ scope.

f. A variable that maintains its value when the program execution exist the block where the variable was declared is a _________        variable.

g. The capability of a nonmember function having full access to a class's members is called a _________ of the class.

h. Friend function is _________, not inherited.

i. Inheritance is an _________ relationship between the base and derived classes.

j. Member functions of a derived class can access the _________ and _________ members of the base class.

k. Data members are commonly declared as private, called _________, which is good software engineering.

l. Public member functions provide the _________ with the outside world through their parameter lists and the returned data.

m. Dynamically created object (using the new operator) can only be destroy by using the _________ operator.

Q9. A derived class represents a _________ with respect to its base class

i. more generalized object

ii. more specialized object

iii. less generalized object

iv. less specialized object

Q10. Which two of the following statements about inheritance are true?

i. An object of the base class is also an object of its derived class.

ii. An Object of the base class is not an object of it derived class.

iii. An object of the derived class is also an object of its base class.

iv. An object of the derived class is not an object of its base class.

Q11. Which one of the following statements about inheritance is false?

i. When a nonmember function is passed an object of a derived class, the nonmember function cannot access any of the base class's members if the inheritance is either protected or private.

ii. A private member function of a class cannot access the public members of the class.

iii. When a nonmember function is passed an object of a derived class, the nonmember function can access any of the base class's members via an object of the derived class, if the inheritance is public.

iv. A protected member function of a class can access all members of the class.

Q12. Which one of the following statements about inheritance is false?

i. A friend function of a derived class can access the public members of the based class.

ii. A friend function of a derived class cannot access the protected members of the based class.

iii. A member function of a derived class cannot access the private member of the based class.

iv. A member function of a derived class cannot access the private member of the based class.

Q13. A derived class can inherit from a _________ base class.

i. public, protected, or private

ii. public and protected only

iii. pubic only

iv. protected only

All the remaining questions are points each.

Q14. Consider the following program segment:

1 class A {

2 private :

3 B * bObjPtr ; //assume class B is defined with a default constructor

4 public :

5 A() {

6 bObjPtr = new B;

7 }

8 B get_BObj (){

9 return *bObjPtr;

10 }

11 }

Write a destructor for class A to destroy the B object.

Q15. Consider the following program segment:

1 class A {

2 private :

3 B *bObjPtr ; //assume class B is defined with a default constructor

4 public

5 A () {

6 bObjPtr = new B ;

7 }

8 B get_BObj () {

9 return *bObjPtr ;

10 }

11 } ;  

Write a copy constructor.

Q16. Refer 'to Question 15. Write the copy constructor that copies the dynamically created object of class B.

Q17. Write a declaration statement that does not allow a pointer, of type, double, to be modified once it is initialized and also does not allow the data pointed by the pointer to be modified.

Q18. Consider the following function:

1 void myfunction () {

2 Time *timePtr = new Time (12,  0,  30);

3 cout << "A new Time object is just created\n";

4 }

Anything wrong with this function'? Explain.

Q19. Modify the following function definition to support return-by-reference using pointer.

1 Time getTime () {

2 Time *myttime = new Time (3,  0, 0);

3 return *mytime;

4 }

Q20. Consider the following program segment:

1 double add (double x, double y)

2 {

3 return x + y ;

4 }

Write a function template for the above function.

Q21. Explain how the constructor of the base class is executed when an object of its derived class is instantiated?

Attachment:- Assignment Files.zip

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92394456

Have any Question?


Related Questions in Programming Language

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As