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

CS201 Assignment No 03 Fall 2019 Solution & Discussion


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

Replies to This Discussion

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

Students having same subject can start discussion here to solve assignment, GDB & Quiz and can clear their concepts until solution is provided. 

 

P.S:    Please always try to add the discussion in proper format title like “CS101 Assignment / GDB No 01 Solution & Discussion Due Date: ___________”

Then copy Questions from assignment file and paste in Discussion.

 

http://bit.ly/vucodes (For Assignments, GDBs & Online Quizzes Solution)

http://bit.ly/papersvu (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)

AA.cpp

. there is mistake in code 

this code add record but not show the record any one can help.

wesy yh cpp file correct hay complete hay ya incomplete

Found this video link

zahid bhai is assignment ki video ke alwa solution file men hy to plz send kar den

code link ni mila may be available in video.

AoA plz send me solution file.

AOA send solution fileplz

CS201 Introduction to Programming Assignment 3 Solution & Discussion Fall 2019


Solution idea: 

 

#include<iostream>

#include<fstream>

#include<stdio.h>




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"Enter employee code: ";

cin>>code;

cout"Enter name: ";

cin.ignore(1);

cin.getline(name,20);

cout"Enter salary: ";

cin>>salary;

}







void Employee::display()

{

coutcode" "name"\t"salaryendl;

}







fstream file;




void deleteExistingFile(){

remove("EMPLOYEE.DAT");

}




void appendToFille(){

Employee x;



x.read();



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

if(!file){

cout"ERROR IN CREATING FILE\n";

return;

}

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

file.close();

cout"Record added sucessfully.\n";

}




void displayAll(){

Employee x;



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

if(!file){

cout"ERROR IN OPENING FILE \n";

return;

}

while(file){

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

if(x.getSalary()>=10000 && x.getSalary()<=20000)

x.display();

}

file.close();

}




void searchForRecord(){

Employee x;

int c;

int isFound=0;




cout"Enter employee code: ";

cin>>c;







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

if(!file){

cout"ERROR IN OPENING FILE \n";

return;

}

while(file){

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

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

cout"RECORD FOUND\n";

x.display();

isFound=1;

break;

}

}

}

if(isFound==0){

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

}

file.close();

}




void increaseSalary(){

Employee x;

int c;

int isFound=0;

float sal;




cout"enter employee code \n";

cin>>c;







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

if(!file){

cout"ERROR IN OPENING FILE \n";

return;

}

while(file){

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

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

cout"Salary hike? ";

cin>>sal;

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

isFound=1;

break;

}

}

}

if(isFound==0){

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

}

file.close();

cout"Salary updated successfully."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"Error in opening EMPLOYEE.DAT file!!!\n";

return;

}

if(!fin){

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

return;

}

while(file){

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

if(x.getEmpCode()>newEmp.getEmpCode()){

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

}



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

}

}




fin.close();

file.close();



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

remove("TEMP.DAT");

cout"Record inserted successfully."endl;

}




int main()

{

char ch;




deleteExistingFile();




do{

int n;




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

cout"Make a choice: ";

cin>>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"Invalid Choice\n";

}




cout"Do you want to continue ? : ";

cin>>ch;




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



return 0;

}

RSS

Looking For Something? Search Here

Latest Activity

Mani Siddiqui BS VIII replied to Mani Siddiqui BS VIII's discussion مّخمصّہ
47 seconds ago
Bakhtawar khan replied to Mani Siddiqui BS VIII's discussion مّخمصّہ
3 minutes ago
Mani Siddiqui BS VIII posted a status
"کسی کی معصوم ہنسی کے پیچھے درد کو محسوس تو کرو سنا ہے ہنس ہنس کے لوگ خود کو سزا دیتے ہیں"
16 minutes ago
jimmy zack updated their profile
44 minutes ago
ARhum replied to ARhum's discussion Tu Bewafa Kahan TaK Hai,,,///
58 minutes ago
ARhum replied to ARhum's discussion Poetry...!!!
59 minutes ago
ARhum liked ARhum's discussion Pyaray Baba.....!!!!***
1 hour ago
ARhum liked ARhum's discussion ****..... Tamanna .....*****
1 hour ago

HELP SUPPORT

This is a member-supported website. Your contribution is greatly appreciated!

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

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

.