<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CS201 Assignment 3 Solution and Discussion]]></title><description><![CDATA[<p dir="auto">Assignment No.  3<br />
Semester: Fall 2019<br />
CS201 – Introduction to Programming	Total Marks: 20<br />
Due Date: 15-01-2020</p>
<p dir="auto">Instructions<br />
Please read the following instructions carefully before submitting assignment:<br />
It should be clear that your assignment will not get any credit if:</p>
<p dir="auto">o	Assignment is submitted after due date.<br />
o	Submitted assignment does not open or file is corrupt.<br />
o	Assignment is copied (From internet/students).</p>
<p dir="auto">Software allowed to develop Assignment</p>
<ul>
<li>Dev C++</li>
</ul>
<p dir="auto">Objectives:<br />
In this assignment, the students will learn:<br />
•	How to make Class while dealing with real life problems<br />
•	How to associate functions with Class.<br />
•	How to implement switch statement for Class based functions.<br />
•	How to deal with file handling.<br />
•	How to manipulate already created file.</p>
<p dir="auto">Assignment Submission Instructions<br />
You are required to submit only .cpp file on the assignments interface of CS201 at VU-LMS.<br />
Assignment submitted in any other format will not be accepted and will be graded with zero marks.</p>
<p dir="auto">Problem Statement<br />
Write a console-based employee management system through binary File Handling (In order to observe data security, we use binary file format so that data cannot be read directly from the TXT file) which will perform management actions of Employee by taking input from user by showing following three options:</p>
<ol>
<li>Press 1 to ADD AN EMPLOYEE.</li>
<li>Press 2 to DISPLAY FILE DATA.</li>
<li>Press 3 to INCREASE EMPLOYEE SALARY.<br />
After dealing with each option, show prompt to user and continue the program until user press other than ‘y’</li>
</ol>
<p dir="auto">Instructions to write C++ program:</p>
<p dir="auto">	Use Class Employee to declare all Employee’s belongings.<br />
	Make a EMPLOYEE.TXT file for saving Employee records<br />
	Each time program runs, check and delete EMPLOYEE.TXT file if already exists.<br />
	Switch statement will be implemented to perform multiple conditions and to perform different actions based on the conditions. i.e. Option 1, 2 and 3.<br />
	Write functions to perform tasks given in options.<br />
Screenshots for Guidance:</p>
<p dir="auto">1	Initially when program executes, following screen will show to user to get input from the user.<br />
<img src="https://i.imgur.com/ETGqZqX.png" alt="25701577-8346-420e-9cc7-b1919d746c36-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">2	If user press any other option then 1 at the first time i.e. without creating any file for Employees, then show error to user.<br />
<img src="https://i.imgur.com/xIAoexi.png" alt="3c3a2e34-67c5-4664-a901-538a25232780-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">3	If User press 1, then take Employee credentials from user using prompt statements as follows and save that data in binary file named EMPLOYEE:<br />
<img src="https://i.imgur.com/VLq7g9F.png" alt="5ed9479d-a069-41ce-876d-0dd1134499e7-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">4	If User Press 2, then show all Employee Records to user by reading data from the file, which is depicted as follows:<br />
<img src="https://i.imgur.com/d5qkY8I.png" alt="47232660-fab8-4841-ae80-684149d84f89-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">5	If User press 3, then ask Employee code from user and then take amount of salary to be increased and update record of that Employee. depicted as follows:<br />
<img src="https://i.imgur.com/Kk2vTWe.png" alt="5392f488-b92c-41ea-b53d-23c2a7061a4c-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Good Luck!</p>
<p dir="auto">Lectures Covered:  This assignment covers Lecture # 15-30.<br />
Deadline: The deadline to submit your assignment solution is 15-01-2020. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date.</p>
]]></description><link>https://community.secnto.com//topic/931/cs201-assignment-3-solution-and-discussion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 21:39:55 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/931.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Jan 2020 14:31:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Mon, 13 Jan 2020 06:00:37 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Ideas Solution 2:</strong></p>
<pre><code>#include&lt;iostream&gt;

#include&lt;fstream&gt;

#include&lt;stdio.h&gt;




using namespace std;

class Employee{

    private:

        int code;

        char name[20];

        float salary;

    public:

        void read();

        void display();

       

        int getEmpCode()            { return code;}

       

        int getSalary()             { return salary;}

       

        void updateSalary(float s)  { salary=s;}

};







void Employee::read(){

    cout&lt;&lt;"Enter employee code: ";

    cin&gt;&gt;code;

    cout&lt;&lt;"Enter name: ";

    cin.ignore(1);

    cin.getline(name,20);

    cout&lt;&lt;"Enter salary: ";

    cin&gt;&gt;salary;

}







void Employee::display()

{

    cout&lt;&lt;code&lt;&lt;" "&lt;&lt;name&lt;&lt;"\t"&lt;&lt;salary&lt;&lt;endl;

}







fstream file;




void deleteExistingFile(){

    remove("EMPLOYEE.DAT");

}




void appendToFille(){

    Employee    x;

    

    x.read();

    

    file.open("EMPLOYEE.DAT",ios::binary|ios::app);

    if(!file){

        cout&lt;&lt;"ERROR IN CREATING FILE\n";

        return;

    }

    file.write((char*)&amp;x,sizeof(x));

    file.close();

    cout&lt;&lt;"Record added sucessfully.\n";

}




void displayAll(){

    Employee    x;

    

    file.open("EMPLOYEE.DAT",ios::binary|ios::in);

    if(!file){

        cout&lt;&lt;"ERROR IN OPENING FILE \n";

        return;

    }

    while(file){

    if(file.read((char*)&amp;x,sizeof(x)))

        if(x.getSalary()&gt;=10000 &amp;&amp; x.getSalary()&lt;=20000)

            x.display();

    }

  file.close();

}




void searchForRecord(){

    Employee    x;

    int c;

    int isFound=0;




    cout&lt;&lt;"Enter employee code: ";

    cin&gt;&gt;c;







    file.open("EMPLOYEE.DAT",ios::binary|ios::in);

    if(!file){

        cout&lt;&lt;"ERROR IN OPENING FILE \n";

        return;

    }

    while(file){

        if(file.read((char*)&amp;x,sizeof(x))){

            if(x.getEmpCode()==c){

                cout&lt;&lt;"RECORD FOUND\n";

                x.display();

                isFound=1;

                break;

            }

        }

    }

    if(isFound==0){

        cout&lt;&lt;"Record not found!!!\n";

    }

    file.close();

}




void increaseSalary(){

    Employee    x;

    int c;

    int isFound=0;

    float sal;




    cout&lt;&lt;"enter employee code \n";

    cin&gt;&gt;c;







    file.open("EMPLOYEE.DAT",ios::binary|ios::in);

    if(!file){

        cout&lt;&lt;"ERROR IN OPENING FILE \n";

        return;

    }

    while(file){

        if(file.read((char*)&amp;x,sizeof(x))){

            if(x.getEmpCode()==c){

                cout&lt;&lt;"Salary hike? ";

                cin&gt;&gt;sal;

                x.updateSalary(x.getSalary()+sal);

                isFound=1;

                break;

            }

        }

    }

    if(isFound==0){

        cout&lt;&lt;"Record not found!!!\n";

    }

    file.close();

    cout&lt;&lt;"Salary updated successfully."&lt;&lt;endl;

}




void insertRecord(){

    Employee    x;

    Employee newEmp;

    

    newEmp.read();




    fstream fin;

    file.open("EMPLOYEE.DAT",ios::binary|ios::in);

    fin.open("TEMP.DAT",ios::binary|ios::out);




    if(!file){

        cout&lt;&lt;"Error in opening EMPLOYEE.DAT file!!!\n";

        return;

    }

    if(!fin){

        cout&lt;&lt;"Error in opening TEMP.DAT file!!!\n";

        return;

    }

    while(file){

        if(file.read((char*)&amp;x,sizeof(x))){

            if(x.getEmpCode()&gt;newEmp.getEmpCode()){

                fin.write((char*)&amp;newEmp, sizeof(newEmp));

            }

   

            fin.write((char*)&amp;x, sizeof(x));

        }

    }




    fin.close();

    file.close();

    

    rename("TEMP.DAT","EMPLOYEE.DAT");

    remove("TEMP.DAT");

    cout&lt;&lt;"Record inserted successfully."&lt;&lt;endl;

}




int main()

{

     char ch;




     deleteExistingFile();




     do{

     int n;




     cout&lt;&lt;"ENTER CHOICE\n"&lt;&lt;"1.ADD AN EMPLOYEE\n"&lt;&lt;"2.DISPLAY\n"&lt;&lt;"3.SEARCH\n"&lt;&lt;"4.INCREASE SALARY\n"&lt;&lt;"5.INSERT RECORD\n";

     cout&lt;&lt;"Make a choice: ";

     cin&gt;&gt;n;




     switch(n){

          case 1:

            appendToFille();

            break;

          case 2 :

            displayAll();

            break;

          case 3:

            searchForRecord();

            break;

        case 4:

            increaseSalary();

            break;

        case 5:

            insertRecord();

            break;




          default :

                cout&lt;&lt;"Invalid Choice\n";

     }




     cout&lt;&lt;"Do you want to continue ? : ";

     cin&gt;&gt;ch;




     }while(ch=='Y'||ch=='y');

    

    return 0;

}
</code></pre>
]]></description><link>https://community.secnto.com//post/2626</link><guid isPermaLink="true">https://community.secnto.com//post/2626</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Mon, 13 Jan 2020 06:00:37 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Mon, 13 Jan 2020 05:59:18 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Ideas Solution:</strong></p>
<pre><code>#include&amp;lt;iostream&amp;gt;
#include&amp;lt;fstream&amp;gt;
#include&amp;lt;string.h&amp;gt;

using namespace std;
void addemployee();
void showemployee();

class employee {

int employee_id;
string employee_name;
int employee_salary;
public:
employee(){

}
void setid(int id){
employee_id=id;
}
void setname(string name){
employee_name=name;
}

void setsalary(int salary){
employee_salary=salary;
}
int getid(){
return this-&amp;gt;employee_id;
}
string getname(){
return this-&amp;gt;employee_name;
}
int getsalary(){
return this-&amp;gt;employee_salary;
}
};
employee anEmployee;
void addemployee(){
int id;
cout&amp;lt;&amp;lt;&amp;quot;enter employee ID: &amp;quot;;
cin&amp;gt;&amp;gt;id;
anEmployee.setid(id);
cout&amp;lt;&amp;lt;&amp;quot;enter employee Name: &amp;quot;;
string name;
cin&amp;gt;&amp;gt;name;
anEmployee.setname(name);
int salry;

cout&amp;lt;&amp;lt;&amp;quot;enter employee Salary: &amp;quot;;
cin&amp;gt;&amp;gt;salry;
anEmployee.setsalary(salry);
ofstream empfile(&amp;quot;employee.txt&amp;quot;,ios::binary|ios::app);

if(!empfile) {
cout &amp;lt;&amp;lt; &amp;quot;Cannot open file!&amp;quot; &amp;lt;&amp;lt; endl;
return ;
}
empfile.write((char*)&amp;amp;anEmployee, sizeof(employee));
//cout&amp;lt;&amp;lt;anEmployee.getid()&amp;lt;&amp;lt;&amp;quot; &amp;quot;&amp;lt;&amp;lt;anEmployee.getname()&amp;lt;&amp;lt;&amp;quot;
&amp;quot;&amp;quot;&amp;quot;&amp;lt;&amp;lt;anEmployee.getsalary();
empfile.close();
if(!empfile.good()) {
cout &amp;lt;&amp;lt; &amp;quot;Error occurred at writing time!&amp;quot; &amp;lt;&amp;lt; endl;
return ;
}
cout &amp;lt;&amp;lt; &amp;quot;Employee Recored added Sucessfully!&amp;quot; &amp;lt;&amp;lt; endl;
}

void displayRecord() {
// employee anEmployee;
ifstream file(&amp;quot;employee.txt&amp;quot;,ios::binary);
if(!file) {

cout&amp;lt;&amp;lt;&amp;quot;Error in opening file.\n&amp;quot;;
return;
} else {
cout&amp;lt;&amp;lt;&amp;quot;ID&amp;quot;&amp;lt;&amp;lt;&amp;quot; &amp;quot;&amp;lt;&amp;lt;&amp;quot;Name&amp;quot;&amp;lt;&amp;lt;&amp;quot;\t&amp;quot;&amp;lt;&amp;lt;&amp;quot;Salary&amp;quot;&amp;lt;&amp;lt;endl;
cout&amp;lt;&amp;lt;&amp;quot;=======================================================&amp;quot;&amp;lt;&amp;lt;en
dl;
while(file.read((char*)&amp;amp;anEmployee,sizeof(employee))) {

cout&amp;lt;&amp;lt;anEmployee.getid()&amp;lt;&amp;lt;&amp;quot;
&amp;quot;&amp;lt;&amp;lt;anEmployee.getname()&amp;lt;&amp;lt;&amp;quot;\t&amp;quot;&amp;lt;&amp;lt;anEmployee.getsalary();
cout&amp;lt;&amp;lt;endl;
}
file.close();
}
}

// function to show employee data
void updateSalary() {
fstream file(&amp;quot;employee.txt&amp;quot;,ios::binary|ios::in|ios::out);
if(!file) {
cout&amp;lt;&amp;lt;&amp;quot;Error in opening file.\n&amp;quot;;
return;
}
int eCode,sHike;

cout&amp;lt;&amp;lt;&amp;quot;Enter employee code\n&amp;quot;;
cin&amp;gt;&amp;gt;eCode;
cout&amp;lt;&amp;lt;&amp;quot;Salary hike? &amp;quot;;
cin&amp;gt;&amp;gt;sHike;
file.seekg(sizeof(anEmployee)*(eCode-1),ios::beg);
file.read((char*)&amp;amp;anEmployee,sizeof(employee));
anEmployee.setsalary(sHike+anEmployee.getsalary());
file.seekp(sizeof(anEmployee)*(eCode-1),ios::beg);
file.write((char*)&amp;amp;anEmployee,sizeof(employee));
cout&amp;lt;&amp;lt;&amp;quot;Salary updated successfully.\n&amp;quot;;
}
main()
{
ifstream file(&amp;quot;employee.txt&amp;quot;);
if(file) {
file.close();
remove(&amp;quot;employee.txt&amp;quot;);
}
int programOption;
while(true){

cout&amp;lt;&amp;lt;&amp;quot;\n\n\n&amp;quot;;
cout&amp;lt;&amp;lt;&amp;quot;Please select the option Below,.\n&amp;quot;;
cout&amp;lt;&amp;lt;&amp;quot;Please enter 1 To ADD AN EMPLOYEE.\n&amp;quot;;

cout&amp;lt;&amp;lt;&amp;quot;Please enter 2 To DISPLAY FILE DATA..\n&amp;quot;;
cout&amp;lt;&amp;lt;&amp;quot;Please enter 3 To INCREASE EMPLOYEE SALARY..\n&amp;quot;;
cout&amp;lt;&amp;lt;&amp;quot;Please enter 4 To Exit Program..\n&amp;quot;;

cout&amp;lt;&amp;lt;&amp;quot;============================================================
======\n&amp;quot;;
cout&amp;lt;&amp;lt;&amp;quot;Please enter program option :&amp;quot;;
cin&amp;gt;&amp;gt;programOption;

switch(programOption){
case 1 :
cout&amp;lt;&amp;lt;&amp;quot;ADD AN EMPLOYEE DATA.\n&amp;quot;;
addemployee();
break;
case 2 :
cout&amp;lt;&amp;lt;&amp;quot;Showing Employee Data.\n&amp;quot;;
displayRecord();
break;
case 3 :
cout&amp;lt;&amp;lt;&amp;quot;Update salary .\n&amp;quot;;
updateSalary();
break;
case 4 :
cout&amp;lt;&amp;lt;&amp;quot;Shuting Down the Program......\n&amp;quot;;

exit(1);
break;

}
}
}
</code></pre>
]]></description><link>https://community.secnto.com//post/2625</link><guid isPermaLink="true">https://community.secnto.com//post/2625</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Mon, 13 Jan 2020 05:59:18 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Sat, 11 Jan 2020 13:32:35 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://www.youtube.com/watch?v=OOt9H1X-oCI" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.youtube.com/watch?v=OOt9H1X-oCI</a></p>
]]></description><link>https://community.secnto.com//post/2616</link><guid isPermaLink="true">https://community.secnto.com//post/2616</guid><dc:creator><![CDATA[cyberian]]></dc:creator><pubDate>Sat, 11 Jan 2020 13:32:35 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Sat, 11 Jan 2020 13:02:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zareen" aria-label="Profile: zareen">@<bdi>zareen</bdi></a><br />
Here you can Also discuss regarding error and code issue!.<br />
happy to learn smartly!<br />
Thanks</p>
]]></description><link>https://community.secnto.com//post/2615</link><guid isPermaLink="true">https://community.secnto.com//post/2615</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Sat, 11 Jan 2020 13:02:22 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Sat, 11 Jan 2020 12:49:28 GMT]]></title><description><![CDATA[<p dir="auto">Full Code File Available Soon!<br />
If you have any Problem regarding code issue you can discuss <a class="plugin-mentions-user plugin-mentions-a" href="/user/cyberian" aria-label="Profile: cyberian">@<bdi>cyberian</bdi></a> !<br />
<img src="https://i.imgur.com/1Vb94pk.png" alt="d65e9782-4113-40ce-9a0e-c3bbeb8d7351-image.png" class=" img-fluid img-markdown" /><img src="https://i.imgur.com/qXnnhpc.png" alt="7a028af0-68ef-41c8-85fc-7a0d0042bd8a-image.png" class=" img-fluid img-markdown" /><img src="https://i.imgur.com/UIuyv2M.png" alt="72c02202-ea67-4ab4-a9db-ee0d5aa40f1f-image.png" class=" img-fluid img-markdown" /><img src="https://i.imgur.com/RO9idVJ.png" alt="69a27478-0836-4dcc-a65e-38ae99a1e481-image.png" class=" img-fluid img-markdown" /><img src="https://i.imgur.com/vQSapQt.png" alt="8269fc0e-7c8f-4f1f-936b-dfe5a1f66399-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://i.imgur.com/8sc7vSs.png" alt="6bcae402-bf1e-4d18-861d-cf3cd60cdb37-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.secnto.com//post/2614</link><guid isPermaLink="true">https://community.secnto.com//post/2614</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Sat, 11 Jan 2020 12:49:28 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 3 Solution and Discussion on Sat, 11 Jan 2020 11:04:23 GMT]]></title><description><![CDATA[<p dir="auto">Solution will be available soon!</p>
]]></description><link>https://community.secnto.com//post/2613</link><guid isPermaLink="true">https://community.secnto.com//post/2613</guid><dc:creator><![CDATA[zaasmi]]></dc:creator><pubDate>Sat, 11 Jan 2020 11:04:23 GMT</pubDate></item></channel></rss>