diff --git a/Constructor/Untitled1.cpp b/Constructor/Untitled1.cpp new file mode 100644 index 0000000..deceb5d --- /dev/null +++ b/Constructor/Untitled1.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +class area_circle{ + int r,area; + public: + void read_data(){ + cin>>r; + } + + void publish_data() + { + cout< +#include +using namespace std; +class student{ + private: + int roll; + char name[30]; + + public: + student(int x, char y[]) // parameterized constructor function + { + roll= x; + strcpy(name,y) ; + } + void show_data(){ + cout<<"\n Roll no :"< +#include +using namespace std; +class student{ + private: + int roll; + char name[30]; + + public: + student(int x=10, char y[]="Sumit Singh") // parameterized constructor with default values + { + roll= x; + strcpy(name,y) ; + } + void show_data(){ + cout<<"\n Roll no :"< +#include +using namespace std; +class student{ + public: + student(){ + cout<<"\n I am constructor" ; + } + ~student(){ + cout<<"\n Inside destrctor"; + } +}; + +int main(){ + + student s; + { + student s1; + } + student s2; + return 0; +} diff --git a/Constructor/destructir-1.exe b/Constructor/destructir-1.exe new file mode 100644 index 0000000..57205b0 Binary files /dev/null and b/Constructor/destructir-1.exe differ diff --git a/Constructor/overloading.cpp b/Constructor/overloading.cpp new file mode 100644 index 0000000..e0e4211 --- /dev/null +++ b/Constructor/overloading.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; +class student{ + private: + int roll; + char name[30]; + + public: + + student(){ + roll=20; + strcpy(name,"Rakesh"); + } + + student(int x, char y[]) // parameterized constructor with default values + { + roll= x; + strcpy(name,y) ; + } + + void show_data(){ + cout<<"\n Roll no :"< +#include +using namespace std; +int main(){ + ofstream handa; + handa.open("demo.txt"); + handa<<"How to learn and then earn using C++"; + handa<<"\nThis is my second line of text"; + handa<<"\n This is third line having \t tab and another spacing chars"; + handa.close(); + return 0; +} diff --git a/File_handling/file_read_1.cpp b/File_handling/file_read_1.cpp new file mode 100644 index 0000000..be34259 --- /dev/null +++ b/File_handling/file_read_1.cpp @@ -0,0 +1,12 @@ +#include +#include +using namespace std; +int main(){ + ifstream object; + char name[300]; + object.open("demo.txt"); + object>>name; // read one word at a time + cout<<"\n Entered Name :"< +#include +using namespace std; +int main(){ + ifstream object; + char name[300]; + object.open("demo.txt"); + object.getline(name,300); + cout<<"\n Entered Value :"< +#include +using namespace std; +int main(){ + ifstream object; + char name[300]; + object.open("demo.txt"); + + object.getline(name,300); + cout<<"\n Entered Value :"< +#include +using namespace std; +int main(){ + ifstream object; + char ch; + object.open("file_read_eof.cpp"); + + while(!object.eof()) + { + object.get(ch); + cout< +#include +using namespace std; +int main(){ + ifstream object; + char name[300]; + object.open("demo.txt"); + + while(!object.eof()) + { + object.getline(name,300); + cout< +#include +using namespace std; +int main(){ + ifstream object; + char ch; + object.open("file_read_eof.cpp"); + + while( object.get(ch)) // checking end of file using file object + cout< +#include +using namespace std; +int main(){ + ifstream object; + char ch; + object.open("file_read_eof.cpp"); + + while(object) // checking end of file using file object + { + object.get(ch); + cout< +#include +using namespace std; +int main(){ + ifstream fin; + fin.open("demo.txt"); + char word[100]; + int count=0; + while(fin){ + fin>>word; + count++; + } + fin.close(); + cout<<"\nTotal words :"< +using namespace std; +class area_circle{ + int r,area; + public: + void read_data(){ + cin>>r; + } + + void publish_data() + { + cout< +using namespace std; +class mukul +{ + private: + int a; + public: + int b; + protected: + int c; +}; + +int main(){ + mukul obj; + obj.a=10; + obj.b=20; + obj.c=30; + return 0; +} diff --git a/inheritance/private_inheritance.cpp b/inheritance/private_inheritance.cpp new file mode 100644 index 0000000..ce19d3a --- /dev/null +++ b/inheritance/private_inheritance.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; +class area_circle{ + int r,area; + public: + void read_data(){} + void publish_data(){} +}; +class volume:private area_circle // using private +{ + int x; + public: + void get_data(){} + void show_data(){} +}; + +int main(){ + volume B; + B.get_data(); + B.show_data(); + B.read_data(); + B.publish_data(); + return 0; +} diff --git a/inheritance/private_members.cpp b/inheritance/private_members.cpp new file mode 100644 index 0000000..7748f28 --- /dev/null +++ b/inheritance/private_members.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; +class area_circle{ + int r,area; + void calculate(); + public: + void read_data(){ + cin>>r; + } + void publish_data(){} +}; +class volume:public area_circle // using private +{ + int x; + public: + void get_data(){ + cin>>r; + } + void show_data(){} +}; + +int main(){ + area_circle A; + A.read_data(); + + volume B; + B.calculate(); + B.get_data(); + return 0; +} diff --git a/inheritance/protect_member_inheritance.cpp b/inheritance/protect_member_inheritance.cpp new file mode 100644 index 0000000..a0e3406 --- /dev/null +++ b/inheritance/protect_member_inheritance.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +class area_circle{ + protected: + int r,area; + void calculate(); + public: + void read_data(){ + cin>>r; + } + void publish_data(){} +}; + +class volume:public area_circle // using private +{ + int x; + + public: + void get_data(){ + cin>>r; + } + void show_data(){} +}; + +int main(){ + area_circle A; + A.read_data(); + + volume B; + B.get_data(); + return 0; +} diff --git a/inheritance/protect_member_inheritance.exe b/inheritance/protect_member_inheritance.exe new file mode 100644 index 0000000..fe7e26d Binary files /dev/null and b/inheritance/protect_member_inheritance.exe differ diff --git a/inheritance/protected_member_classs.cpp b/inheritance/protected_member_classs.cpp new file mode 100644 index 0000000..19d5d7f --- /dev/null +++ b/inheritance/protected_member_classs.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +class mukul +{ + private: + int a; + public: + int b; + protected: + int c; +}; + +int main(){ + mukul obj; + obj.a=10; + obj.b=20; + obj.c=30; + return 0; +}