#include<iostream>
#include<conio.h>
#include <fstream>
using namespace std;
/*
####################################################
# Parent Class #
# #
# Class Read Date In File #
# #
####################################################
*/
class File
{
protected:
string name;
int roll;
public:
void setName(string n)
{
name=n;
}
void setRoll(int r)
{
roll=r;
}
};
/*
####################################################
# Drived Class #
# #
# Class Get Data From User... #
# #
####################################################
*/
class GetData:public File
{
public:
string getName()
{
return name;
}
int getroll()
{
return roll;
}
};
/*
####################################################
# Drived Class #
# #
# Class Read Date In File #
# #
####################################################
*/
class Write_in_FIle:public File,GetData
{
public:
void File()
{
GetData d;
string name;
int roll;
cout << "Enter student name.... ";
cin >> name;
cout << "Enter student roll Number....";
cin >> roll;
d.setName(name);
d.setRoll(roll);
ofstream myfile;
myfile.open ("new.txt",ios::app);
myfile << "Name of the student is = "<<d.getName() << endl<< "Roll number of the student is = "<< d.getroll()<< endl;
myfile.close();
}
};
/*
####################################################
# Drived Class #
# #
# Class Read Date From File #
# #
####################################################
*/
class Read_Date:public Write_in_FIle,File,GetData
{
public:
void Read_Data_From_File()
{
string line;
ifstream myfile;
string name;
myfile.open ("new.txt");
while(getline(myfile,line)!=NULL)
{
cout <<"................................."<< endl;
cout <<endl<<line << endl;
cout <<"................................."<< endl;
}
myfile.close();
}
};
/*
####################################################
# Drived Class #
# #
# Class Search Date From File #
# #
####################################################
*/
class Search_Data:public File,GetData, Write_in_FIle, Read_Date
{
public:
void Search_Data_From_File()
{
GetData d;
string line;
string name;
//int position;
size_t position;
ifstream myfile;
string name_std;
myfile.open ("new.txt");
cout << endl<<"enter Name for Seach...";
cin >> name_std;
while(getline(myfile,line)!=NULL)
{
size_t position=line.find(name_std);
if(position!=string::npos)
{
cout << "Position pof this file is : "<< position << endl;
}
}
myfile.close();
}
};
int main()
{
Write_in_FIle wrt;
wrt.File();
Read_Date rd;
rd.Read_Data_From_File();
Search_Data srch;
srch.Search_Data_From_File();
getch();
return 0;
}
#include<conio.h>
#include <fstream>
using namespace std;
/*
####################################################
# Parent Class #
# #
# Class Read Date In File #
# #
####################################################
*/
class File
{
protected:
string name;
int roll;
public:
void setName(string n)
{
name=n;
}
void setRoll(int r)
{
roll=r;
}
};
/*
####################################################
# Drived Class #
# #
# Class Get Data From User... #
# #
####################################################
*/
class GetData:public File
{
public:
string getName()
{
return name;
}
int getroll()
{
return roll;
}
};
/*
####################################################
# Drived Class #
# #
# Class Read Date In File #
# #
####################################################
*/
class Write_in_FIle:public File,GetData
{
public:
void File()
{
GetData d;
string name;
int roll;
cout << "Enter student name.... ";
cin >> name;
cout << "Enter student roll Number....";
cin >> roll;
d.setName(name);
d.setRoll(roll);
ofstream myfile;
myfile.open ("new.txt",ios::app);
myfile << "Name of the student is = "<<d.getName() << endl<< "Roll number of the student is = "<< d.getroll()<< endl;
myfile.close();
}
};
/*
####################################################
# Drived Class #
# #
# Class Read Date From File #
# #
####################################################
*/
class Read_Date:public Write_in_FIle,File,GetData
{
public:
void Read_Data_From_File()
{
string line;
ifstream myfile;
string name;
myfile.open ("new.txt");
while(getline(myfile,line)!=NULL)
{
cout <<"................................."<< endl;
cout <<endl<<line << endl;
cout <<"................................."<< endl;
}
myfile.close();
}
};
/*
####################################################
# Drived Class #
# #
# Class Search Date From File #
# #
####################################################
*/
class Search_Data:public File,GetData, Write_in_FIle, Read_Date
{
public:
void Search_Data_From_File()
{
GetData d;
string line;
string name;
//int position;
size_t position;
ifstream myfile;
string name_std;
myfile.open ("new.txt");
cout << endl<<"enter Name for Seach...";
cin >> name_std;
while(getline(myfile,line)!=NULL)
{
size_t position=line.find(name_std);
if(position!=string::npos)
{
cout << "Position pof this file is : "<< position << endl;
}
}
myfile.close();
}
};
int main()
{
Write_in_FIle wrt;
wrt.File();
Read_Date rd;
rd.Read_Data_From_File();
Search_Data srch;
srch.Search_Data_From_File();
getch();
return 0;
}