NAME : UROOJ ASGHAR KHAN
ENROLLMENT: 02-135242-006
Task 1: Backup System
You are tasked with creating a program to back up the library's catalog.
The program should copy
the contents of the main catalog file to a backup file, ensuring that the
library's data is securely
preserved in case of any unforeseen events.
Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
cout << "\nCatalog backup initiated..." << endl<<endl;
cout << "Opening output file \"catalog.txt\"" << endl;
ofstream onFile;
, onFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile << "Book Title, Author, ISBN \nThe Catcher in the Rye, J.D.Salinger,
9780316769488 \nTo Kill a Mockingbird, Harper Lee, 9780061120084";
cout << "Output file opened successfully" << endl;
onFile.close();
ifstream inFile;
string str;
cout << "\nOpening input file \"catalog.txt\"" << endl<<endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
while (getline(inFile, str)){
cout << str << endl;
}
cout << "\nInput file opened successfully" << endl;
inFile.close();
cout << "\nCopying content from output to input" << endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile.open("C:\\Users\\spring2018\\Desktop\\catalog_1.txt");
char ch;
while (inFile.get(ch)){
onFile.put(ch);
}
cout << "Copied successfully!\n " << endl;
cout << "Closing input file" << endl;
inFile.close();
cout << "input file closed successfully!\n\n";
cout << "Closing output file" << endl;
onFile.close();
cout << " output file closed successfully!\n";
system("pause");
return 0;
}
Output:
ENROLLMENT: 02-135242-006
Task 1: Backup System
You are tasked with creating a program to back up the library's catalog.
The program should copy
the contents of the main catalog file to a backup file, ensuring that the
library's data is securely
preserved in case of any unforeseen events.
Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
cout << "\nCatalog backup initiated..." << endl<<endl;
cout << "Opening output file \"catalog.txt\"" << endl;
ofstream onFile;
, onFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile << "Book Title, Author, ISBN \nThe Catcher in the Rye, J.D.Salinger,
9780316769488 \nTo Kill a Mockingbird, Harper Lee, 9780061120084";
cout << "Output file opened successfully" << endl;
onFile.close();
ifstream inFile;
string str;
cout << "\nOpening input file \"catalog.txt\"" << endl<<endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
while (getline(inFile, str)){
cout << str << endl;
}
cout << "\nInput file opened successfully" << endl;
inFile.close();
cout << "\nCopying content from output to input" << endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile.open("C:\\Users\\spring2018\\Desktop\\catalog_1.txt");
char ch;
while (inFile.get(ch)){
onFile.put(ch);
}
cout << "Copied successfully!\n " << endl;
cout << "Closing input file" << endl;
inFile.close();
cout << "input file closed successfully!\n\n";
cout << "Closing output file" << endl;
onFile.close();
cout << " output file closed successfully!\n";
system("pause");
return 0;
}
Output: