OOP - Constructor
OOP - Constructor
By
“Aadie Gupta”
“Darshana Malusare”
“Gaurangi Madankar”
ROLL NO: - 55
56
57
SUBJECT INCHARGE
Mrs. Jyoti Shinde
“CONSTRUCTOR”
is done by
“Aadie Gupta”
“Darshana Malusare”
“Gaurangi Madankar”
is submitted for
for
the diploma in Computer Engineering to the
___________ ____________
Subject In charge Head of Department
By
55 AADIE 2209640226
GUPTA
56 DARSHANA 2209640227
MALUSARE
57 GAURANGI 2209640228
MADANKAR
SUBJECT INCHARGE
Mrs. Jyoti Shinde
VISION
MISSION
M1: To transform students into technically components, socially responsible & ethical
computer science professionals.
M2: To promote a creative teaching-learning process that will strive for academic
excellence in the field of computer engineering.
M3: To enhance the technical expertise of students through workshop & industry-
institute interaction.
COMPUTER ENGINEERING DEPARTMENT
PROGRAMME OUTCOMES
PO1: Basic and Discipline specific knowledge: Apply knowledge of basic
mathematics, science and engineering fundamentals and engineering specialization to
solve the engineering problems.
PO7: Life-long learning: Ability to analyse individual needs and engage in updating
in the context of technological changes.
COMPUTER ENGINEERING DEPARTMENT
PROGRAMME EDUCATIONAL OBJECTIVES
Course Outcomes
Successfully can write/ compile/ debug/ execute simple C++ program using constructors.
Proposed Methodology
First, Search the topic for which you want to make a project, and then propose it to
the Subject In charge.
After finalizing the topic, start gathering the information about your project.
Action Plan
Sr. Detail of activity Plan Start Date Plan Finish Date
No.
Subject In-Charge
(Mrs. Jyoti Shinde)
CONSTRUCTOR
Rationale
Constructors are a crucial aspect of C++ programming, facilitating the creation and proper
initialization of objects. They align with the principles of object-oriented design, such as
encapsulation, and contribute to the overall clarity and reliability of C++ code.
Literature
Constructors are special member functions which performs initialization of every object. The
Compiler call the Constructor whenever the object is created. Constructors initialize values to
variables after storage is allocated to the object.
Syntax:
class className
{
//other members declaration
public:
className (list of parameters)
{
//body of constructor function
}
//other members declaration
};
Constructor Overloading:
Just like other member functions, constructors can also be overloaded. In fact, when you have
both default and parameterized (more than one) constructors defined in your class you are
having Overloaded Constructors, one which no parameters and other with parameter.
Declaring overloaded constructor functions:
Syntax:
class className
{
public:
className () { //Default constructor
//body of default constructor function
}
className (list of parameters) { //Parametrized constructor
//body of parametrized constructor function
}
className (className &obj) { //Copy constructor
//body of copy constructor function
}
};
Resources Required
DEFAULT CONSTRUCTOR
#include<iostream.h>
#include<conio.h>
class circle
{
private:
float r, area, circum, vol;
public:
circle ();
void compute ()
{
area=3.14*r*r;
circum=2*3.14*r;
vol= (4/3) *3.14*r*r*r;
}
void display ()
{
cout<<"\nArea = "<<area;
cout<<"\nCircumference = "<<circum;
cout<<"\nVolume = "<<vol;
}
};
circle :: circle ()
{
cout<<"\nEnter radius: ";
cin>>r;
}
void main ()
{
clrscr();
circle c;
c.compute();
c.display();
getch();
}
Output
PARAMETRIZED CONSTRUCTOR
#include<iostream.h>
#include<conio.h>
class circle
{
private:
float r, area, circum, vol;
public:
circle(float x);
void compute()
{
area= 3.14*r*r;
circum= 2*3.14*r;
vol= (4/3) *3.14*r*r*r;
}
void display()
{
cout<<"\nArea = "<<area;
cout<<"\nCircumference = "<<circum;
cout<<"\nVolume = "<<vol;
}
};
circle :: circle(float x)
{
r=x;
}
void main()
{
float radius;
clrscr();
cout<<"\nEnter radius: ";
cin>>radius;
circle c(radius);
c.compute();
c.display();
getch();
}
Output
COPY CONSTRUCTOR
#include<iostream.h>
#include<conio.h>
#include<math.h>
class Circle {
private:
float radius;
public:
// Default constructor
Circle() {
radius = 0.0;
}
Circle(float r) {
radius = r;
}
float calculateArea() {
return 3.14 * radius * radius;
}
float calculateCircumference() {
return 2 * 3.14 * radius;
}
float calculateVolume() {
return (4.0 / 3.0) * 3.14 * pow(radius, 3);
}
void display()
{
cout << "Radius: " << radius << endl;
cout << "Area: " << calculateArea() << endl;
cout << "Circumference: " << calculateCircumference() << endl;
cout << "Volume: " << calculateVolume() << endl;
}
};
int main()
{
clrscr();
float userRadius;
Circle circle1(userRadius);
Circle circle2 = circle1;
Output
Skill Developed
1. Able to develop Constructor programs.
Applications
Subject In-charge
(Mrs. Jyoti Shinde)