We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ 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:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)

 

 

Objective

 

The objective of this assignment is:

  • Learn to code, edit, compile and execute C++ program.
  • Learn to manipulate and navigate through text files.
  • Learn to create and use user defined functions.
  • Learn to use string manipulation functions.

Guidelines

 

  • Code should properly be indented and well commented.
  • Follow C/C++ naming conventions while using variables, functions etc.
  • Use only Dev-C++ for this assignment. If you are using any other tool then mention it at top of your code file as comments.

 

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.

  • Program will prompt the user to enter the file name in current directory.
  • System will show a menu with two options:
    • Protect the file
    • Check security status
  • In case user selects the first option (i.e. protect the file), the system will perform the following steps:
    • Read the file
    • Check if the file is already protected or not.
    • In case if file is not protected, program will protect it by the protection mechanism defined above.
    • If file is already protected, system will display appropriate message and exit.
  • If user selects the second option (i.e. check security status), the system will perform following steps:
    • Read the entire file and if key does not exist (i.e. file is not already protected), program will display the message to protect the file first and display menu.
    • If file is already protected, the system will read the contents along with the already existing key. On the basis of contents read, a new key will be generated. If this new key and the existing one (read from the file) do not match, it means that the contents of protected file are changed and vice versa.

 

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. 


+ 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)


Views: 7155

Replies to This Discussion

#include <iostream> #include <string> #include <cstring> #include <fstream>  using namespace std;   int GenerateKey(string file){       int key = 0; ifstream myfile(file);     //int val = 0; if (myfile.is_open()) {    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");         }

again the same error 

plz help me number of errors appear in code

is code me bht sy error aa ry hn

please use the dropbox or google drive to upload the assignment file 

Please tell me how to protect a file and check its security status. ?

Important: Related to Assignment 03 Dated: Jul 06, 15
Dear students,

I hope you are doing well. This announcement is related to the key generation process in assignment no. 3. Here is a sample program in which we are using the simplest technique to generate the security key. You may copy and paste it into your Dev C++, and can see the results by entering any string. For example, We are Muslims.

#include

#include

using namespace std;

main() {

char data[1000]; // array to hold string entered from user

int securitykey = 0; // variable to hold generated security key

cout"Input any string as data: "; cin.getline(data,1000, '\n'); // getline function allows to enter space between words while getting input from user. for (int i = 0; data[i] != '\0'; i++){ // iterate through array unless reached at "null character" securitykey += (int)data[i]; // converting each character in array to ASCII code and adding in securitykey } cout"Security Key: "/p>

Note:

We have been using arrays to store characters; students are not bound to use the same technique. They might use any technique of their own for the desired output.

Good Luck!

#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"); 
}

. Here is a sample program in which we are using the simplest technique to generate the security key. You may copy and paste it into your Dev C++, and can see the results by entering any string. For example, We are Muslims.

#include <iostream>

#include <stdlib.h>

using namespace std;

main() {

                char data[1000];  // array to hold string entered from user

                int securitykey = 0; // variable to hold generated security key    

                cout"Input any string as data: ";

                cin.getline(data,1000, '\n'); // getline function allows to enter space between words while getting input from user.               

                for (int i = 0; data[i] != '\0'; i++){ // iterate through array unless reached at "null character"

                                securitykey += (int)data[i];  // converting each character in array to ASCII code and adding in securitykey

                }             

                cout"Security Key: "securitykey;  // printing security key on console

                system("pause");

}

The mechanism is so simple, ASCII code of each character is generated and added up into a variable named ‘securitykey’ using the statement:  securitykey += (int)data[i]; (int) has been converting the character into it's ASCII code.

 Note: 

         We have been using arrays to store characters; students are not bound to use the same technique. They might use any technique of their own for the desired output. 

ye lo solution kya yaad krogy ap log settings krny ki zarurat nai paregi..........

Attachments:

This solution not showing case 5 when changing in text file how this will show that security alert after protecting the file

zain nasar es main to errors hen

RSS

Latest Activity

Saqib replied to +M.Tariq Malik's discussion CS508 Assignment 01 Fall 2020 Solution / Discussion in the group CS508 Modern Programming Languages
3 hours ago
Saqib joined +M.Tariq Malik's group
3 hours ago
Musawar Ahmed replied to +M.Tariq Malik's discussion CS603 Assignment 01 Fall 2020 Solution / Discussion Due Date: 26-11-2020 in the group CS603 Software Architecture and Design
3 hours ago
Musawar Ahmed joined +M.Tariq Malik's group
3 hours ago
Pooja kumari replied to +M.Tariq Malik's discussion ENG501 Online Quiz No 01 Fall 2020 Solution / Discussion in the group ENG501 History of English Language
3 hours ago
+!!! ❤️ Shadow Girl❤️!!! liked ++!!Zuni Khan(Am Cyco)'s discussion Kitna Mushkil Hai Aziyat Ye Gawara Karna
4 hours ago
UZMA replied to +M.Tariq Malik's discussion Don't Worry About Your Assignments, GDBs & Online Quizzes
5 hours ago
Profile IconFatima and MUHAMMAD NAJEEB joined +M.Tariq Malik's group
5 hours ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion MGT601 GDB No 01 Fall 2020 Solution / Discussion Last Date: 27-11-2020 in the group MGT601 SME Management
6 hours ago
+ " Şinger " and + "ραℓωαѕнα" are now friends
6 hours ago
+ " Şinger " replied to Pooja kumari's discussion quiz discussion
6 hours ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion EDU654 Assignment 01 Fall 2020 Solution / Discussion in the group EDU654 Addressing problems of learning through technology and pedagogy
6 hours ago

Looking For Something? Search Here

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.