0% found this document useful (0 votes)
23 views5 pages

C &C++

The document discusses object-oriented programming concepts like inheritance, polymorphism and copy constructors in C++. It contains code snippets demonstrating class definitions and inheritance between classes like Engine, Bike and Tyre. It also contains examples showing default, parameterized constructors and destructors. The last section demonstrates a copy constructor by copying address objects.

Uploaded by

DHEENATHAYALAN J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

C &C++

The document discusses object-oriented programming concepts like inheritance, polymorphism and copy constructors in C++. It contains code snippets demonstrating class definitions and inheritance between classes like Engine, Bike and Tyre. It also contains examples showing default, parameterized constructors and destructors. The last section demonstrates a copy constructor by copying address objects.

Uploaded by

DHEENATHAYALAN J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<bits/stdc++.

h>
using namespace std;

class Engine
{
public:
long int engine_number;
int milage;
};
class Bike
{
public:
string model_name;
int price;
};
class Tyre : public Engine,public Bike
{
public :
int size;
string tyre_name;
void printValue()
{
cout<<"EngineNumber : "<<engine_number<<endl;
cout<<"Milage : "<<milage<<endl;
cout<<"ModelName : "<<model_name<<endl;
cout<<"price : "<<price<<endl;
cout<<"tyre name : "<<tyre_name<<endl;
cout<<"size : "<<size<<endl<<endl;
}

};
int main()
{
Tyre obj1;
obj1.model_name = "Ct100";
[Link] = 51000;
obj1.engine_number = 12243212;
[Link] = 88;
[Link] = 78;
obj1.tyre_name = "MRF";

Tyre obj2;

obj2.model_name = "Apache";
[Link] = 100000;
obj2.engine_number = 12453342;
[Link] = 45;
[Link] = 78;
obj2.tyre_name = "MRF";

[Link]();
[Link]();
}

#include<iostream>
using namespace std;
class Engine
{
public:
void number(string a)
{
cout << "engine number is : " << a << endl;
}
};
class Bike : public Engine
{
public:
void number(string a)
{
cout << "Bile number is : " << a << endl;
}
};
int main()
{
//getting input
string a;
cout<<"Enter the Number as string : " ;
cin >> a;

//Creating an object for subclass


Bike obj1;
//calling a function called number() with a parameter as a (a)
Bike obj2;
if([Link]() == 12)
{
[Link](a);
}
else
{
[Link] :: number(a);
}
}

#include<iostream>
using namespace std;
class Engine
{
public :
//default constructor.
Engine()
{
int n = 10;
cout << " n = " << n << " default countructor is called when object is
created." << endl;
}
//parameterized constructor.
Engine(int n)
{
cout << " n = " << n << " Parameteriszed constructor is called when an
object is created." << endl;
}
~Engine()
{
cout<<"Destructor is activated : "<<endl;
}
};
int main()
{
Engine obj1(15678);
Engine obj2;
}

[10:26 PM, 7/18/2021] Jega: #include<bits/stdc++.h>


using namespace std;
//class for copy constructor

class Address
{
public:
string doornumber,street,locality,city;
int pincode;
Address(string doornumber , string street ,string locality , string city ,
int pincode)
{
this->doornumber = doornumber;
this->street = street;
this->locality = locality;
this->city = city;
this->pincode = pincode;
}
void display()
{
cout << "The Address is : " << doornumber << "," << street << "," <<
locality << "," << city << "," << pincode << "."<< endl;
}
};
int main()
{
Address swathi_address("13E" , "Thirumalai swami street" , "kadaiveethi" ,
"Namakkal" , 637001);
Address jagan_address = swathi_address;
Address denna_address = jagan_address;
swathi_address.display();
jagan_address.display();
denna_address.display();
}
[10:26 PM, 7/18/2021] Jega: copy constructor
[10:26 PM, 7/18/2021] Jega: #include<iostream>
using namespace std;

class Address
{
public:
string doornumber,street,locality,city;
int pincode;

Address(string door , string srt , string local , string city , int


pincode)
{
doornumber = door;
street = srt;
locality = local;
this -> city = city;
this -> pincode = pincode;
}
void display()
{
cout << "The Address is : " << doornumber << "," << street << "," <<
locality << "," << city << "," << pincode << "."<< endl;
}
};
int main()
{
Address swathi_address("13E" , "Thirumalai swami street" , "kadaiveethi" ,
"Namakkal" , 637001);
swathi_address.display();
}

#include<iostream>
using namespace std;

class deena
{
public:
int deena[100];
int top = -1;
void push(int item)
{
if(top >= 100)
{
cout<<"deena is full or deenaoverflow";
return;
}
else
{
top++;
deena[top] = item;
cout << "deena updated at " << top << " as : " << item << endl ;
}

}
void pop()
{
if(top <= -1)
{
cout<<"deena is empty or stackaunderflow"<<endl;
return;
}
cout << deena[top] << " poped" << endl << endl ;
top--;
}
void peek()
{
cout<<"deena"<<endl;
for(int i = 0 ; i <= top ; i++)
{
cout<<deena[i]<<endl;
}
}
};
int main()
{
deena a;

for(int i = 1 ; i <= 100 ; i++)


{
[Link](i);
}
for(int i = 0 ; i < 90 ; i++)
{
[Link]();
}

[Link]();
}

You might also like