We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>
+ Link For Assignments, GDBs & Online Quizzes Solution |
+ Link For Past Papers, Solved MCQs, Short Notes & More |
Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion
How to Add New Discussion in Study Group ? Step By Step Guide Click Here.
Please read the following instructions carefully before submitting assignment.
It should be clear that your assignment will not get any credit if:
Objective
The objective of this assignment is:
Guidelines
Assignment Description
In this assignment, you are required to write c++ code that will protect the provided text file using the protection mechanism given in guidelines. It will also check the security of file and if any change is made in the contents of protected file, it will point out the file as changed.
Protection mechanism:
The program will protect the file by generating a protection key on the basis of contents of the file. The key will be saved at the end of the file with “%” symbol as prefix. This key will be used to detect either the file contents are changed or not e.g. if file contents are changed the new key generated will not match the existing one, leading to conclusion that file contents have been changed.
Solution guidelines
The program should operate in following sequence.
Important note
A text file (data.txt) is attached with assignment, use it for protection checking. Video file (Output-Demo.mp4) of desired function is also attached with assignment. Watch the demo video carefully to understand the required functionality (output) of program. Your program should work as per functionality performing in demo video file. You do not need to send text file with your solution. Just upload .cpp file from your LMS account. For any query related to assignment no. 3 contact us at cs201@vu.edu.pk.
Submission
You are required to submit your solution C++ program through LMS i.e. .cpp file.
Tags:
+ How to Follow the New Added Discussions at Your Mail Address?
+ How to Join Subject Study Groups & Get Helping Material? + How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators? + VU Students Reserves The Right to Delete Your Profile, If?.
+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)
+ Click Here to Search (Looking For something at vustudents.ning.com?) + Click Here To Join (Our facebook study Group)#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
int GenerateKey(string file){
int key = 0;
ifstream myfile();
//int val = 0;
if (myfileis())
{
string line = "";
while (getline(myfile, line))
{
key += line.length();
}
return key;
}
}
bool findKey(string);
int ProtectFile(string filename){
int key = GenerateKey(filename);
string mykey = "%";
ofstream myfile;
myfile.open(filename,ios::out |ios::app);
mykey += to_string(key);
myfilemykey;
myfile.close();
return key;
}
int getfileLength(string);
int GetKey(string);
int displayMenu(string filename){
bool check = false;
int key = 0;
int msg = 1;
check = findKey(filename);
int getval = 0;
cout"\nOperations on text file\n";
cout"1. Protect my text file\n";
cout"2. Check Security of my text file\n\n";
cout"Enter your choice (1/2): ";
cin>>getval;
if(check == false && getval == 2){
msg = 1;
}else if(check == false && getval == 1){
key = ProtectFile(filename);
msg = 2;
}
else if(check == true && getval == 1){
//checkForChange();
msg = 3;
}
else if(check == true && getval ==2){
if( GetKey(filename)==getfileLength(filename)){
msg = 4;
}
else if(getfileLength(filename)!=GetKey(filename)){
msg = 5;
}
}
return msg;
}
bool findKey(string filename){
bool check = false;
string key = "%";
string line = "";
ifstream myfile;
myfile.open(filename, ios::in);
size_t pos;
while(myfile.good())
{
getline(myfile,line);
pos=line.find(key);
if(pos!=string::npos)
{
check = true;
break;
}
}
return check;
}
int getfileLength(string filename){
ifstream myfile (filename);
int val = 0;
int key = 0;string line;
if (myfile.is_open())
{
while (getline(myfile, line))
{
size_t pos = line.find('%');
if (pos != string::npos)
{
line = line.substr(0,pos);
}
val += line.length();
}
}
myfile.close();
return val;
}
int GetKey(string filename){
ifstream myfile (filename);
int val = 0;
int key = 0;string line;
if (myfile.is_open())
{
while (getline(myfile, line))
{
size_t pos = line.find('%');
if (pos != string::npos)
{
line = line.substr(pos+1);
}
}
}
myfile.close();
return atoi(line.c_str());
}
int main(){
string filename = "";
int key = 0;
bool choice = false;
int msg = 1;
ifstream myfile;
cout"Enter the name of text file in current directory: ";
cin>>filename;
myfile.open(filename);
if(!myfile){
cout"\nSorry the name of file "filename" you entered is not exist in current directory!";
return 0;
}else{
while(msg == 1){
msg = displayMenu(filename);
if(msg == 1)
cout"Your text file is not protected, first protect it by using option \"1\"\n\n";
if(msg == 2){
cout"\nYour text file is protected now!";
break;
}
else if(msg == 3){
cout"\nYour text file is already protected!";
break;
}
else if(msg == 4){
cout"The content of file are not changed after protection.";
break;
}else if(msg == 5){
cout"Alert! The content of file are changed after protection.";
break;
}
}
}
coutendl;
system("pause");
}
where is if myfileis() function is declared?
#include
#include
using namespace std;
int get_key(string a_lines)
{ int key = 0;
key += a_lines.length();
return key; }
bool findkey(string a_lines)
{ int answer = a_lines.find("%");
if(answer >= 0)
{ return 1; }
else
{ return 0; } }
bool readkey(string a_lines)
{
}
main()
{ ifstream infile;
ofstream outfile;
char fName[100];
string line;
string lines;
int option;
cout "Enter the name of text file in current directory:";
cin >> fName;
infile.open(fName, ios::in); // opening file in input mode
bool jump = true;
bool answer;
if(!infile)
{ cout "file not found choose 1"; }
else
{ while(!infile.eof())
{ getline(infile, line);
lines += line; }
infile.close();
do
{ cout "\nOperations on text file";
cout "\n1.Protect my text file";
cout "\n2.check security of my text file";
cout "\n1.Enter your choice (1/2)";
cin >> option;
switch(option)
{ case 1:
if(findkey(lines))
{ cout "already protected";
cout " and return " findkey(lines);
infile.close();
jump = false;
break; }
else
{ outfile.open(fName, ios::app);
outfile "%";
outfile get_key(lines);
cout "key added";
cout "and return " findkey(lines);
jump = false;
outfile.close();
break; }
case 2:
if(findkey(lines))
{ cout "file is protected using option 2";
cout "and return " findkey(lines);
jump = false;
break; }
else
{ cout "file is not protected please protect file";
cout "and return " findkey(lines);
jump=false;
break; } } }
while(jump == true);
system("pause");
} }
tarik bai ye complet assignment hai???
© 2019 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
VU Students reserves the right to delete profile, which does not show any Activity at site nor has not activity more than 01 month.
We are user-generated contents site. All product, videos, pictures & others contents on vustudents.ning.com don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com or Contact us at contact Page with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post