diff --git a/.cph/.rough_contest.cpp_c13a02bc6e2422c122e328e79eeddc51.prob b/.cph/.rough_contest.cpp_c13a02bc6e2422c122e328e79eeddc51.prob deleted file mode 100644 index 48e6108..0000000 --- a/.cph/.rough_contest.cpp_c13a02bc6e2422c122e328e79eeddc51.prob +++ /dev/null @@ -1 +0,0 @@ -{"name":"Local: rough_contest","url":"e:\\Programming\\CODING 2.0\\C++\\rough_contest.cpp","tests":[{"id":1689949454352,"input":"7\n5 1\n1 2 4 5 6\n1 2\n10\n8 3\n17 3 1 20 12 5 17 12\n4 2\n2 4 6 8\n5 3\n2 3 19 10 8\n3 4\n1 10 5\n8 1\n8 3 1 4 5 10 7 3","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"e:\\Programming\\CODING 2.0\\C++\\rough_contest.cpp","group":"local","local":true} \ No newline at end of file diff --git a/constr.cpp b/constr.cpp new file mode 100644 index 0000000..66e6738 --- /dev/null +++ b/constr.cpp @@ -0,0 +1,67 @@ +#include +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"< +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; +} \ No newline at end of file diff --git a/destructor2.exe b/destructor2.exe new file mode 100644 index 0000000..061650a Binary files /dev/null and b/destructor2.exe differ diff --git a/inheritance2.cpp b/inheritance2.cpp new file mode 100644 index 0000000..c61ff8f --- /dev/null +++ b/inheritance2.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; +/* +class : +{ + //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 : "< 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 : "< +// 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 +// 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 "< +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 "< It is a collection of data member and member Functions + +Data Member -> Variables(Container to store values/data) +Ex - int a = 10; + +Member Functions -> function(Group of code that perform specific task) + +void add(int a,int b){ + cout< Real world Entity/ Copy of class + +Encapsulation -> Class is an Example of encapsulation + + + +*/ + +#include +using namespace std; + +// class class_name{ + +// } + +class IRCTC +{ + // data member +private: + string name; + int id; + int salary; + +public: + // Setter + void set_data(string name1, int id1, int salary1) + { + name = name1; + id = id1; + salary = salary1; + } + // Getter + void get_data() + { + cout << "The name is : " << name << endl; + cout << "The Id is : " << id << endl; + cout << "The salary is : " << salary << endl; + } + void get_data1() + { + cout << "The name is : " << name << endl; + cout << "The Id is : " << id << endl; + } +}; + +// Main function +int main() +{ + + // Creating Objects + // Syntax + // Class_name object_name; + + // Obj - 1 + IRCTC yash; + yash.set_data("Yash", 69, 100000); + yash.get_data(); + + + cout<<"The size of obj Yash : "<