Skip to content

Commit

Permalink
Text File handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Aug 2, 2018
1 parent f529eb9 commit 0596a7f
Show file tree
Hide file tree
Showing 28 changed files with 465 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Constructor/Untitled1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<iostream>
using namespace std;
class area_circle{
int r,area;
public:
void read_data(){
cin>>r;
}

void publish_data()
{
cout<<area;
}
};


class volume:public area_circle
{
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;
}
Binary file added Constructor/Untitled1.exe
Binary file not shown.
30 changes: 30 additions & 0 deletions Constructor/constructor-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
#include<string.h>
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 :"<<roll;
cout<<"\n Name :"<<name;
}
};

int main(){
//student s; // constructor function runs at the time of object creation

student s(10,"Manan"); // implicit call

student s1 = student(20,"Ramji"); // explicit call
s.show_data();
s1.show_data();
return 0;
}
Binary file added Constructor/constructor-1.exe
Binary file not shown.
27 changes: 27 additions & 0 deletions Constructor/contructir-with-default-values.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<iostream>
#include<string.h>
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 :"<<roll;
cout<<"\n Name :"<<name;
}
};

int main(){

//student s; // constructor function runs at the time of object creation
student s(30,"Hitesg");
s.show_data();
return 0;
}
Binary file added Constructor/contructir-with-default-values.exe
Binary file not shown.
22 changes: 22 additions & 0 deletions Constructor/destructir-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<iostream>
#include<string.h>
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;
}
Binary file added Constructor/destructir-1.exe
Binary file not shown.
34 changes: 34 additions & 0 deletions Constructor/overloading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
#include<string.h>
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 :"<<roll;
cout<<"\n Name :"<<name;
}
};

int main(){

//student s; // constructor function runs at the time of object creation
student s(40,"rajesh mandal");
s.show_data();
return 0;
}
Binary file added Constructor/overloading.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions File_handling/demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
How to learn and then earn using C++
This is my second line of text
This is third line having tab and another spacing chars
12 changes: 12 additions & 0 deletions File_handling/file_handling-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<fstream>
#include<iostream>
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;
}
12 changes: 12 additions & 0 deletions File_handling/file_read_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<fstream>
#include<iostream>
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 :"<<name;
object.close();
return 0;
}
12 changes: 12 additions & 0 deletions File_handling/file_read_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<fstream>
#include<iostream>
using namespace std;
int main(){
ifstream object;
char name[300];
object.open("demo.txt");
object.getline(name,300);
cout<<"\n Entered Value :"<<name;
object.close();
return 0;
}
18 changes: 18 additions & 0 deletions File_handling/file_read_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<fstream>
#include<iostream>
using namespace std;
int main(){
ifstream object;
char name[300];
object.open("demo.txt");

object.getline(name,300);
cout<<"\n Entered Value :"<<name;
object.getline(name,300);
cout<<"\n Entered Value :"<<name;
object.getline(name,300);
cout<<"\n Entered Value :"<<name;

object.close();
return 0;
}
20 changes: 20 additions & 0 deletions File_handling/file_read_char_eof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// file read char wise + EOF function


#include<fstream>
#include<iostream>
using namespace std;
int main(){
ifstream object;
char ch;
object.open("file_read_eof.cpp");

while(!object.eof())
{
object.get(ch);
cout<<ch;
}

object.close();
return 0;
}
20 changes: 20 additions & 0 deletions File_handling/file_read_eof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// file read and using EOF function


#include<fstream>
#include<iostream>
using namespace std;
int main(){
ifstream object;
char name[300];
object.open("demo.txt");

while(!object.eof())
{
object.getline(name,300);
cout<<name;
}

object.close();
return 0;
}
18 changes: 18 additions & 0 deletions File_handling/file_read_eof_simulta.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// file read char wise + EOF function


#include<fstream>
#include<iostream>
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<<ch;


object.close();
return 0;
}
20 changes: 20 additions & 0 deletions File_handling/file_read_eof_using_object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// file read char wise + EOF function


#include<fstream>
#include<iostream>
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<<ch;
}

object.close();
return 0;
}
17 changes: 17 additions & 0 deletions File_handling/total_words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// program to find out total no of words in a text file
#include<fstream>
#include<iostream>
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 :"<<count;
return 0;
}
7 changes: 6 additions & 1 deletion classes/initialize_class_variable_wrong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class student{
char name[30];

public:
student() // constructor function
{
roll= 10;
strcpy(name,"manan") ;
}
void show_data(){
cout<<"\n Roll no :"<<roll;
cout<<"\n Name :"<<name;
Expand All @@ -15,7 +20,7 @@ class student{


int main(){
student s;
student s; // constructor function runs at the time of object creation
s.show_data();
return 0;
}
35 changes: 35 additions & 0 deletions inheritance/Untitled1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<iostream>
using namespace std;
class area_circle{
int r,area;
public:
void read_data(){
cin>>r;
}

void publish_data()
{
cout<<area;
}
};


class volume:public area_circle // using public
{
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;
}
19 changes: 19 additions & 0 deletions inheritance/Untitled4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<iostream>
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;
}
Loading

0 comments on commit 0596a7f

Please sign in to comment.