diff --git a/File_handling/duplicate.txt b/File_handling/duplicate.txt new file mode 100644 index 0000000..9f241c6 --- /dev/null +++ b/File_handling/duplicate.txt @@ -0,0 +1,10 @@ +This is my first attempt in c++ +hello world +thiis is my third line +and fourth line +and fifth line +and +so +on +this ia again + diff --git a/File_handling/duplicate_text_file.cpp b/File_handling/duplicate_text_file.cpp new file mode 100644 index 0000000..fa3ac41 --- /dev/null +++ b/File_handling/duplicate_text_file.cpp @@ -0,0 +1,22 @@ +// program to create duplicate of sameer.txt file +#include +#include +using namespace std; +int main() +{ + ifstream object; + ofstream object1; + char ch; + object.open("sameer.txt"); // member function of ofstream class + object1.open("PRN"); + while(!object.eof()) + { + object.get(ch); + object1< +#include +using namespace std; +int main() +{ + ifstream object; + char ch; + object.open("sameer.txt"); // member function of ofstream class + while(!object.eof()) + { + object.get(ch); + cout< +#include +using namespace std; +int main() +{ + ofstream object; + object.open("sameer.txt",ios::app); // file modes + object<<"hello world"; + object.close(); //member function of ofstream class + return 0; + +} diff --git a/File_handling/file1.cpp b/File_handling/file1.cpp new file mode 100644 index 0000000..82aee1d --- /dev/null +++ b/File_handling/file1.cpp @@ -0,0 +1,12 @@ +#include +#include +using namespace std; +int main() +{ + ofstream object; + object.open("sameer.txt"); // member function of ofstream class + object<<"hello world"; + object.close(); //member function of ofstream class + return 0; + +} diff --git a/File_handling/file_read_text_file.cpp b/File_handling/file_read_text_file.cpp new file mode 100644 index 0000000..2923b3c --- /dev/null +++ b/File_handling/file_read_text_file.cpp @@ -0,0 +1,14 @@ +#include +#include +using namespace std; +int main() +{ + ifstream object; + char str[900]; + object.open("sameer.txt"); // member function of ofstream class + object>>str; + cout< +#include +using namespace std; +int main() +{ + ifstream object; + char str[900]; + object.open("sameer.txt"); // member function of ofstream class + object.getline(str,900); // read a line + cout< +#include +using namespace std; +int main() +{ + ifstream object; + char ch; + int count =0; + object.open("sameer.txt"); // member function of ofstream class + while(!object.eof()) + { + object.get(ch); + if(ch==' ') + count++; + else + count=0; + if(count<=1) + cout< +#include +#include + +#define random(num) rand()%num + +using namespace std; +int main(){ + int a[10]={10,20,30,40,60}; + + // output phase + for(int i=0;i<10;i++) + cout< +#include +#include + +using namespace std; +int main(){ + int a[10]; + int i; + //input phase + for(i=0;i<10;i++) + { + cout<<"\n Enter a["<>a[i]; + } + + //processing phase + int sum =0; + for(i=0;i<10;i++) + sum = sum+a[i]; + + // output phase + cout<<"\n Entered array :"; + for(i=0;i<10;i++) + cout< #include +#include -#define random(num) rand()%100 +#define random(num) rand()%num using namespace std; int main(){ int a[10],i; //input phase for(i=0;i<10;i++) - a[i] = random(100); + a[i] = random(10); // output phase for(i=0;i<10;i++) cout< +#include +#include + +using namespace std; + +int fun_add(int a){ + a = a+10; + return(a); +} + +int main(){ + int a[10]; + int i; + + //input phase + for(i=0;i<10;i++) + { + cout<<"\n Enter a["<>a[i]; + } + + //processing phase + + for(i=0;i<10;i++) + a[i] = fun_add(a[i]); + + // output phase + + cout<<"\n Modified array :"; + for(i=0;i<10;i++) + cout< +#include +#include + +using namespace std; + +void fun_add(int a[10]){ + int i; + for(i=0;i<10;i++) + a[i] = a[i]+10; + +} + +int main(){ + int a[10]; + int i; + + //input phase + for(i=0;i<10;i++) + { + cout<<"\n Enter a["<>a[i]; + } + + //processing phase + + fun_add(a); + + // output phase + + cout<<"\n Modified array :"; + for(i=0;i<10;i++) + cout< +#include +#include + +using namespace std; +int main(){ + int a[10]; + int i; + //input phase + for(i=0;i<10;i++) + { + cout<<"\n Enter a["<>a[i]; + } + + //processing phase + + for(i=0;i<10;i++) + a[i]+=10; //shortand operator a[i] = a[i]+10 + + + // output phase + + cout<<"\n Modified array :"; + for(i=0;i<10;i++) + cout< +#include +#include + +using namespace std; +int main(){ + int a[10]; + int i; + //input phase + for(i=0;i<10;i++) + { + cout<<"\n Enter a["<>a[i]; + } + + //processing phase + int sum =0; + for(i=0;i<10;i++) + sum = sum+a[i]; + + // output phase + cout<<"\n Entered array :"; + for(i=0;i<10;i++) + cout<