C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 3, Problem 3.5E

(Default Constructor) What's a default constructor? How are an object's data members initialized if a class has only a default constructor defined by the compiler?

Expert Solution & Answer
Check Mark
To determine

Program Plan:

Default Constructor:

Constructor is the first function which is automatically called by the compiler when object is created. Its main purpose is make initializations for the class. Default constructors are the one which take no arguments or parameters, and even if they have parameters, they have default value. By default value we mean initial blank value which variable can take.

Syntax

Classname();
Classname(datatype=default value);

Example

Let us see following example:

#include<iostream>
using namespace std;
class A
{
     int x;
     float y;
public:
     A(){};				// default constructor
     void disp()
    {
            cout<<"\nx = "<<x;
            cout<<"\ny = "<<y;
     }
};

int main()
{
A a;				// making object of class A
a.disp();			// call to disp() function 
}

Explanation of Solution

C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition), Chapter 3, Problem 3.5E , additional homework tip  1

A(){} is the default constructor which initialize the variable x and y with default value 0 as evident from the output.

If user does not define any default constructor then compiler itself perform the same working, by automatically initializing the variable of the class on object creation.
Example:

#include<iostream>
using namespace std;
class A
{
    int x;
    float y;
public:
    void disp()
    {
        cout<<"\nx = "<<x;
        cout<<"\ny = "<<y;
    }
};

int main()
{
A a;
a.disp();
}

C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition), Chapter 3, Problem 3.5E , additional homework tip  2

Above piece of code does not have default constructor, but when object is created for class A, its data members are automatically initialized to value 0. Thus its quite evident that even if we do not create any default constructor, complier itself will initialize every data member.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Level-0 Diagram for this: A customer sends in an order form containing details of their order and their membership number.  A check is made to verify that they are a member.  When their order is verified, a check is made to validate that the items ordered are produced by the company.  Next, the valid order is used to update the daily order file, and then used to create a shipping list and invoice, which are sent on to the Order Fulfilment System.
In this assignment, you will use all of the graphics commands you have learned to create an animated scene. Your program should have a clear theme and tell a story. You may pick any school-appropriate theme that you like. The program must include a minimum of: 5 circles 5 polygons 5 line commands 2 for loops 1 global variable You may wish to use the standard code for simplegui graphics below: import simplegui def draw_handler(canvas): frame = simplegui.create_frame('Testing', 600, 600) frame.set_canvas_background("Black") frame.set_draw_handler(draw_handler) frame.start() Submit Your Code After you write your code here in the programming environment, you will check it and submit it as usual. However, the grader will only perform basic checks against some requirements. If your code passes, you should submit your work, and your teacher will manually grade your submitted work using a rubric.
1. What is the difference between a relative cell reference and an absolute cell reference and give an example of when you would use each.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY