Write the function header of the default copy constructor

Assignment Help Programming Languages
Reference no: EM131585742

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

Reference no: EM131585742

Questions Cloud

Demonstrate the golden rule when working with clients : How can a counselor with Christian beliefs demonstrate the golden rule when working with clients who have diverse worldviews
Rules govern a typical arbitration proceeding : What general procedures or rules govern a typical arbitration proceeding?
Describe type of trauma : Select one type of trauma and describe the effects it may potentially have on the body, mind, and spirit of an individual.
Corporate stockholders are exposed to unlimited liability : Large corporations are taxed more favorably than proprietorships. Corporate stockholders are exposed to unlimited liability.
Write the function header of the default copy constructor : Write the function header of the default copy constructor for a class called A. Write one default constructor prototype of a class called A
Prove that the graph shown in given figure is non-planar : The girth of a graph is the length of its smallest cycle. Use this to generalize the statements and proofs of Theorems I and II.
What psychological factors contribute to subjective : What psychological factors do you think contribute to subjective well-being when all of the pieces seemingly are in place but one does not have a sense
Statements would most people in business agree : With which of the following statements would most people in business agree?
What did you find most interesting or surprising : What did you find most interesting or "surprising" about chpter 1?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd