Skip to content

Commit

Permalink
Revision
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghLokesh02 committed Sep 5, 2023
1 parent a73a4f8 commit d863581
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 2 deletions.

This file was deleted.

67 changes: 67 additions & 0 deletions constr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <bits/stdc++.h>
using namespace std;
// /*
// Intrduction of Constructor

// Constructor is a special member function of a class which is used to initialize the objects of its class.

// It is special because its name is the same as the class name.

// It is invoked whenever an object of its associated class is created.

// It is constructor’s responsibility to initialize the object of its class.

// It has no return type, not even void.
// */

class Student
{

int roll;
string name;
int sem;
int total_marks;

public:
Student(){
cout<<"Default Constructor Called"<<endl;
}

Student(int a,int b,int c){
cout<<"The sum of Given Number is : "<<a+b+c<<endl;
}
Student(int roll1, string name1, int sem1, int total_m)
{
roll = roll1;
name = name1;
sem = sem1;
total_marks = total_m;
}
void get_data()
{
cout << "Roll no. : " << roll << endl;
cout << "Name : " << name << endl;
cout << "Semester : " << sem << endl;
cout << "Total Marks : " << total_marks << endl;
}

~Student(){
cout<<"Destructor is called\n";
}
};
int main()
{
// Printing by Normal Method
Student s1;
// s1.set_data(1, "Yash", 3, 100);
// s1.get_data();

// Printing with the help of Constructor
Student s2(1, "Yash", 3, 100);
// s1.set_data(1, "Yash", 3, 100);
s2.get_data();

return 0;
}

// E:\Programming\CODING 2.0\C++\constr.cpp
Binary file added constr.exe
Binary file not shown.
59 changes: 59 additions & 0 deletions destructor2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <bits/stdc++.h>
using namespace std;

// Creating a class

/*
Destructor
It is Just Opposite to Constructor with (~).
It is automatically Invoked when object goes out of scope.
It has No return Type
*/
class Employee
{
string name;
int id;
int salary;

public:
Employee()
{
cout << "This is a default constructor" << endl;
}

Employee(int id, int salary, string name)
{
this->name = name;
this->salary = salary;
this->id = id;
}

void get_data()
{
cout << "The name is : " << name << endl;
cout << "The Id is : " << id << endl;
cout << "The Salary is : " << salary << endl;
}

~Employee(){
cout<<"I'm a Destructor and now I'm called\n";
}
};

// Main Function -> Code Execution Starts here
int main()
{
// Creating Obj
// Class_name obj_name
Employee e1(12, 10000, "Yash");
e1.get_data();

Employee e2;
Employee e3;

return 0;
}
Binary file added destructor2.exe
Binary file not shown.
64 changes: 64 additions & 0 deletions inheritance2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <bits/stdc++.h>
using namespace std;
/*
class <derived_class_name> : <access-specifier> <base_class_name>
{
//body
}
*/
// Single Inheritance
// Base Class
class Parent
{
public:
int a;
int b;
void get_data()
{
cout<<"Enter the value of a and b\n";
cin>>a>>b;
}
void show_data()
{
cout<<"The value of a is : "<<a<<endl;
cout<<"The value of b is : "<<b<<endl;
}
};


// Derived Class

// In Inheritance
/*
If you are Inheriting publicly
-> public member are public
-> protected member private
-> private member can never be Inherited
If you are Inheriting protected way
-> public member are public
-> protected member private
-> private member can never be Inherited
*/
class Child : public Parent{
public:
void sum(){
cout<<"The sum of a and b is : "<<a+b<<endl;
}
};



int main()
{
Child c1;
c1.get_data();
c1.show_data();
c1.sum();
cout<<c1.a<<endl;
return 0;
}
Binary file added inheritance2.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion linked_list_Insertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main()
insertAtTail(head, 89);
insertAtTail(head, 189);
print(head);

insertAtIndex(head, 453, 0);
print(head);
if (search(head, 89))
Expand Down
151 changes: 151 additions & 0 deletions rough1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// #include <bits/stdc++.h>
// using namespace std;

// // Base class - 1
// class parent1
// {
// public:
// int num = 10;
// string name = "Lokesh";

// };

// // Base Class - 2
// class parent2
// {
// public:
// int num1, num2;

// public:
// void get_data()
// {
// cout << "Enter the value of Num1 and Num2 " << endl;
// cin >> num1 >> num2;
// }

// void show_data()
// {
// cout << "The Number1 is : " << num1 << endl;
// cout << "The Number2 is : " << num2 << endl;
// }
// };

// // Child/Derived/Sub class

// class Child1 : public parent1, public parent2
// {
// public:
// void sumParent2()
// {
// cout << "The sum of 2 Numbers of Parent2 class is : " << num1 + num2 << endl;
// }
// void print_data()
// {
// cout << "The name is : " << name << endl;
// cout << "The number is : " << num << endl;
// }
// };

// int main()
// {
// Child1 c1;
// c1.print_data();

// c1.get_data();
// c1.show_data();

// c1.sumParent2();
// return 0;
// }

// Multilevel Inheritance

// #include <bits/stdc++.h>
// using namespace std;
// class Baba
// {
// protected:
// int rupya1 = 1000;
// int rupya2 = 10000;

// Baba(){
// cout<<"I'm the constructor of papa's papa class\n";
// }
// };

// class Papa : protected Baba
// {
// public:
// int dollar = 5000;
// Papa(){
// cout<<"I'm the constructor of papa class\n";
// }
// };

// class hum : public Papa
// {
// public:
// hum(){
// cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
// cout<<"My papa's salary in dollar is : "<<dollar<<endl;
// }
// };
// int main()
// {

// hum h1;

// return 0;
// }



// Hierarchical Inheritance
#include <bits/stdc++.h>
using namespace std;

// Parent class
class Baba
{
protected:
int rupya1 = 1000;
int rupya2 = 10000;

};

// Child - 1
class Papa : protected Baba
{
public:
int dollar = 5000;
Papa(){
cout<<"I'm the constructor of papa class\n";
}

void show_data(){
cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
cout<<"My salary in dollars is : "<<dollar<<endl;
}
};

// Child 2
class hum : public Baba
{
public:
hum(){
cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
}
};

// Main Class
int main()
{
// Child1 Object
hum h1;

// Child2 Object
Papa p;
p.show_data();

return 0;
}
Binary file added rough1.exe
Binary file not shown.
Loading

0 comments on commit d863581

Please sign in to comment.