Showing posts with label CS201 Assignment 03 Solution. Show all posts
Showing posts with label CS201 Assignment 03 Solution. Show all posts

CS201 Assignment no 3 Fall 2016

By: // No comments:

CS201 Assignment no 3 Fall 2016

Here we have CS201 - Introduction to Programming Assignment No. 3 Solution and Discussion Fall 2016 Due Date Jan 16, 2017. You Can Also Download Solved Final Term Papers, Short Notes, Assignment Solutions, Lecture Wise Questions Answers Files, Solved MCQs, Solved Quiz , Solved Final Term Subjective Papers , Solved Final Term Objective Papers from Virtual Study Solutions For Preparation of Final Term Papers.


Also Read: CS201 Latest Solved MCQs For Final Term Papers

CS201 Assignment no 3:

XYZ University needs a system for student’s courses and their semester details. A data entry operator needs to enter student’s data in to the system, and then the system will show the report of student semester information. Following data will be used by the system.
  • Course code
  • Course name
  • Semester
The system will allow entering data for five courses at a time and will input course code along with course name, later the system will format the report in a more readable form.

Also Read: CS201 Solved Final Term Past Papers Collection

CS201 Assignment no 3 Question:

Your task is to:
Write a C++ program to implement the above mentioned interface

  1. Your program should provide the user with options to enter data for courses along with course code. e.g.
  2. Enter course name along with course code: CS201 Introduction to Programming
  3. After taking course information from user your program should prompt user to enter semester information.
e.g. Enter Semester: Fall 2016
  • The program should input data for five courses and semester.
  • Use structure name “course” in your program. 
  • Use separate functions for taking user inputs, displaying and formatting outputs. 
e.g. Input Courses(),Display Header(),Display Courses(),Format Course(---) etc.

Note: Use structure to implement above program, no credit will be awarded if structure is not used.

Also Read: Virtual University (VU) Exams Pattern

CS201 Assignment No. 3 Solution:

If you want to Get the Solution Directly in Your Inbox. Subscribe us below and save your self Trouble of Searching Assignment Solution.


CS201 Assignment Solution solved.rar, 72 KB

CS201 - Assignment 03 Solution

By: // 3 comments:
Download 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. 
Note:
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
--
Regards,
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.
Submission
You are required to submit your solution C++ program through LMS i.e. .cpp file



Download Solution:



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