Cs201 Assignment 3 Solution

CS201 Assignment 2 Solution – Due Date 23 – 11 – 2017



Software allowed to develop Assignment

– Dev C++


To enable students to write, compile and execute a program in DevC++. Moreover to familiarize students with the concepts of:
• If else structure
• Loops
• Passing array to a function
• Multidimensional array declaration
• Multidimensional array manipulation

Assignment Submission Instructions

You have to submit only .cpp file on the Assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.


CS201 Assignment 2 Statement

Write a program that will generate random numbers and that numbers will be stored in a two-dimensional array. Then display the generated values on the screen and then also print the even numbers from the generated array elements.

Task 1:

First of all, you are required to generate random numbers from 1 to 500. For this, you are required to create a function named as “generateArray. The generateArray will load two- dimensional array with random numbers from 1to 500. The size of the two-dimensional array will be 7*7.

Task 2:

Defined a function named as “showArray(), which will display the elements of the two- dimensional array on the screen.

Task 3:

The final task is to find the even numbers in this array and display it on the console. For this purpose create a function findEvenNumber().



You can Download CS201 Assignment 2 Solution file from the links given below:


Dowmload Source 1Download Source 2



CS201 assignment, CS201 assignment 2, CS201 assignment 2 2017, CS201 assignment 2 solution, CS201 assignment 2 solution 2017, CS201 assignment 2 2017, CS201 assignment solution, CS201 assignment solution 2017, Introduction to Programming, solution assignment CS201, solution assignment CS201, Introduction to Programming 2 solution fall 2017

Like this:



Download Solution:

Assignment 03 cs201 Full Solution

Please note that graded assignment no. 3 of CS201 has been uploaded. Due date to upload solutions is 10-07-2015 (Friday 10-July-2015).

All the instructions to solve the assignment are there in assignment file, so make sure that you read all these instructions and upload your solutions before due date. 


You need to install Winrar to extract compressed assignment file. You can download Winrar from the following link http://www.rarlab.com/download.htm

For any query related to assignment, contact at: CS201@vu.edu.pk



Instructor CS201

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.


You are required to submit your solution C++ program through LMS i.e. .cpp file

Download Solution:

Assignment 03 cs201 Full Solution


#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); myfile<<mykey; 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; } } } cout<<endl; system("pause"); }
My dev version is 5.6.3. if any Query ask in Comments

0 thoughts on “Cs201 Assignment 3 Solution

Leave a Reply

Your email address will not be published. Required fields are marked *