Professional Documents
Culture Documents
Bt19cse008
Code:
////////////////////////////////////////////////////
// //
// Coded by Shivam Bindal //
// //
////////////////////////////////////////////////////
#include<bits/stdc++.h>
#include <climits>
#include <fstream>
using namespace std;
int main(){
cout<<"SLOW ACCESS TIME"<<endl;
ifstream fptr;
string name;
cout<<"Enter file name : ";
cin>>name;
cout<<endl;
fptr.open(name);
if(!fptr){
cout<<"Invalid file name"<<endl;;
return 0;
}
clock_t T= clock();
char str[1000];
while(fptr){
fptr.getline(str, 1000);
if(fptr) cout << str << endl;
}
T = clock()- T;
cout <<"\nfile access time"<<setprecision(10)<<((do
uble)T/CLOCKS_PER_SEC)*(1000000000)<<"ns"<< endl;
fptr.close();
return 0;
}
Shivam Bindal
Bt19cse008
Output:
Shivam Bindal
Bt19cse008
Code:
////////////////////////////////////////////////////
// //
// Coded by Shivam Bindal //
// //
////////////////////////////////////////////////////
#include<bits/stdc++.h>
#include <climits>
#include <fstream>
using namespace std;
void print_file(string file){
ifstream fptr;
fptr.open(file);
if(!fptr) {
cout <<"Inavlid file name\n";
return;
}
char str[1000];
while(fptr) {
fptr.getline(str, 1000);
if(fptr) cout << str << endl;
}
fptr.close();
}
int main(){
cout<<"ATOMICITY"<<endl;
cout<<"DATA before changing anything:\n";
string ff = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/C/u2.txt";
string sf = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/DBMS/u2.txt";
cout <<"CONTENTS OF FIRST FILE - ODD/C/U2:"<<endl;
print_file(ff);
cout <<"\nCONTENTS OF SECOND FILE - ODD/DBMS/U2:"<<
endl;
print_file(sf);
Shivam Bindal
Bt19cse008
cout <<"EDITING is in progress............\n";
ofstream change;
change.open(ff);
if(!change){cerr << "Error" << endl;
return -1;
}
string changedContent = "Shivam Bindal\nBT19CSE008\
nCSE\nAGRA";
change << changedContent<< endl;
change.close();
cout <<"DATA AFTER CHANGING\n";
cout <<"CONTENTS OF FIRST FILE"<<endl;
print_file(ff);
cout <<"\nCONTENTS OF SECOND FILE"<<endl;
print_file(sf);
cout<<"\nTHERE IS A LACK OF ATOMICITY BECAUSE CHANG
ING U2 IN C DOESNT CHANGE IT IN DBMS DIRECTORY\n";
return 0;
}
Output:
Shivam Bindal
Bt19cse008
Code:
////////////////////////////////////////////////////
// //
// Coded by Shivam Bindal //
// //
////////////////////////////////////////////////////
#include<bits/stdc++.h>
#include <climits>
#include <fstream>
using namespace std;
void print_file(string file){
ifstream fptr;
fptr.open(file);
if(!fptr) {
cout <<"File Not Found\n";
return;
}
char str[1000];
while(fptr) {
fptr.getline(str, 1000);
if(fptr) cout << str << endl;
}
fptr.close();
}
int main(){
cout <<"INTEGRITY"<<endl;
cout<<"DATA before changing anything:\n";
string ff = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/Ns/u3.txt";
string sf = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/DBMS/u3.txt";
cout <<"CONTENTS OF FIRST FILE - ODD/Ns/U3:"<<endl;
print_file(ff);
cout <<"\nCONTENTS OF SECOND FILE - ODD/DBMS/U3:"<<
endl;
Shivam Bindal
Bt19cse008
print_file(sf);
cout <<"Editing in progress.....\n";
ofstream change;
change.open(ff);
if(!change){cerr<<"Error"<<endl;
return -1;
}
string changedContent = "Shivam Bindal\nBT19CSE008\
nCSE\nAGRA";
change << changedContent<< endl;
change.close();
cout <<"DATA AFTER CHANGING\n";
cout <<"CONTENTS OF FIRST FILE"<<endl;
print_file(ff);
cout <<"\nCONTENTS OF SECOND FILE"<<endl;
print_file(sf);
cout<<"\nTHERE IS A LOSS OF INTEGRITY BECAUSE BOTH
THE FILES SHOULD HAVE HAD SAME DATA BUT IT IS DIFFERENT
\n";
return 0;
}
Output:
Shivam Bindal
Bt19cse008
change << changedContent<< endl;
change.close();
cout <<"\ncorrupted data\n";
print_file(ff);
cout <<"\nit is difficult to access the corrupted d
ata"<<endl;
return 0;
}
Output:
Shivam Bindal
Bt19cse008
////////////////////////////////////////////////////
// //
// Coded by Shivam Bindal //
// //
////////////////////////////////////////////////////
#include<bits/stdc++.h>
#include <climits>
#include <fstream>
using namespace std;
void print_file(string file){
ifstream fptr;
fptr.open(file);
if(!fptr) {
cout <<"File Not Found\n";
return;
}
char str[1000];
while(fptr) {
fptr.getline(str, 1000);
if(fptr) cout << str << endl;
}
fptr.close();
}
int main(){
cout <<"DATA REDUNDANCY"<<endl;
string ff = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/Ns/u1.txt";
string sf = "C:/Users/Dell/Desktop/Nituk/Department
/CSE/Odd/DBMS/u1.txt";
cout <<"CONTENTS OF FIRST FILE"<<endl;
print_file(ff);
cout <<"\nCONTENTS OF SECOND FILE"<<endl;
print_file(sf);
cout <<"\nthe data is redundant because both file c
ontain same data\n"<<endl;
Shivam Bindal
Bt19cse008
return 0;
}
Output: