You are on page 1of 9

Q-Program to input employee data&print payslip #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.

h> struct date {int dd,mm,yy; }; struct perk1 {float da,hra; int bonus; }; struct emp {int no; char name[20],desig[20]; date dob; float basic,net; perk1 perk; }e; void main() { clrscr(); cout<<"Enter the employee number:"; cin>>e.no; cout<<"Enter the employee name:"; gets(e.name); cout<<"Enter date of birth in dd mm yyyy format:"; cin>>e.dob.dd>>e.dob.mm>>e.dob.yy; cout<<"Enter basic salary:"; cin>>e.basic; e.perk.bonus=800; e.perk.da=0.15*e.basic; e.perk.hra=0.12*e.basic; e.net=e.basic+e.perk.bonus+e.perk.da+e.perk.hra; if(e.net>=25000) strcpy(e.desig,"Manager"); if(e.net>=15000 && e.net<25000) strcpy(e.desig,"Executive"); if(e.net<15000) strcpy(e.desig,"Non executive"); cout<<"\nPayslip"; cout<<"\nEmployee no.:"<<e.no; cout<<"\nName:"<<e.name; cout<<"\nDate of birth:"<<e.dob.dd<<"/"<<e.dob.mm<<"/"<<e.dob.yy; cout<<"\nDesignation:"<<e.desig; cout<<"\nBasic="<<e.basic; cout<<"\nDA="<<e.perk.da; cout<<"\nHRA="<<e.perk.hra; cout<<"\nBonus="<<e.perk.bonus; cout<<"\nNet salary="<<e.net; getch();

Q-WAP to open a text file and count the no. of occurrences of this and these. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<string.h> void main() {clrscr(); ifstream f1; f1.open("article.txt"); char word[80];int c=0; while(f1) {f1>>word; if((strcmp("this",word)==0) || (strcmp("these",word)==0)) c++;} cout<<"the number of occurences of 'this' and 'these' are"<<c; f1.close(); getch();} the number of occurences of 'this' and 'these' are 3 Q-WAP to enter marks and Roll no in a binary file. #include<iostream.h> #include<conio.h> #include<fstream.h> void main() {ofstream filout; filout.open("marks.dat"); char ans='y'; int rollno; float marks; while(ans=='y'||ans=='Y') {cout<<"\n Enter rollno. "<<endl; cin>>rollno; cout<<"\n Enter Marks"<<endl; cin>>marks; filout<<rollno<<'\n'<<marks<<'\n'; cout<<"\n Want to enter more records?(y/n)...."<<endl; cin>>ans; } filout.close(); } Enter rollno. 1 Enter Marks 99 Want to enter more records?(y/n).... y Enter rollno.

2 Enter Marks 98 Want to enter more records?(y/n).... N Q- WAP to delete the first element of an array. #include<iostream.h> #include<conio.h> void del(arr[50],n) {int i; for(i=0;i<n;i++) arr[i]=arr[i+1]; n--; cout<<"New array is :"; cout<<arr[i]; } void main() {clrscr(); int i,n,arr[50]; cout<<"enter the size"<<endl; cin>>n; cout<<"enter the array element "<<endl; for(i=0;i<n;i++) cin>>arr[i]; del(arr,n); getch(); } enter the size 5 enter the array element 1 2 3 4 5 New array is : 2 3 4 5

Q-WAP to insert an element in an array of elements. //insertion sorting #include<iostream.h> #include<conio.h> void inst(arr[50],n) {int k,item; for(k=0;k<n;k++) { item=arr[k]; for(i=k-1;((item<arr[i])&&(i>=0));i--) arr[i+1]=arr[i];

arr[i+1]=item; } cout<<"New array is :"<<endl; for(i=0;i<n;i++) cout<<arr[i]<<endl; void main() {clrscr(); int i,k,n,arr[50]; cout<<"enter the size"<<endl; cin>>n; cout<<"enter the array element "<<endl; for(i=0;i<n;i++) cin>>arr[i]; inst(arr,n); getch();} enter the size 5 enter the array element 9 1 82 5 3 New array is : 1 3 5 9 82 Q-WAP to find the AREAS of different geometrical figures. #include<iostream.h> #include<conio.h> void area(float r) {cout<<"area of circle is "<<3.14*r^2; } void area(float l,float b) {cout<<"area of rectangle is "<<l*b; } void area(float b,float h) {cout<<"area of triangle is "<<(1/2)*b*h; } void main() {clrscr(); int ch; float r,l,b,h; cout<<" Menu "<<endl; cout<<"1-area of circle"<<endl; cout<<"2-area of rectangle"<<endl; cout<<"3-area of triangle"<<endl; cin>>ch; switch(ch) {case 1:

cout<<"enter radius "<<r<<endl; cin>>r; area(r) break; case 2: cout<<"enter length and breadth "<<endl; cin>>l>>b; area(l,b) break; case 3: cout<<"enter base and height "<<r<<endl; cin>>b>>h; area(b,h) break; } getch();} Q-WAP for multiplication of matrices. #include<iostream.h> #include<conio.h> class matrix { int x[10][10]; int m,n; public: void input(); void output(); void multiply(matrix,matrix); }; void matrix::input() {cout<<"Enter Row"<<endl; cin>>m; cout<<"Enter Column"<<endl; cin>>n; cout<<"Matrix"<<endl; for(int i=0;i<m;i++) {for(int j=0;j<n;j++) { cin>>x[i][j]; }}} void matrix :: output() {for(int i=0;i<m;i++) {cout<<endl; for(int j=0;j<n;j++) {cout<<x[i][j]<<" "; }}} void matrix :: multiply(matrix m1, matrix m2) {for(int i=0;i<m1.m;i++) {for(int j=0;j<m2.n;j++) {x[i][j]=0; for(int k=0;k<m1.n;k++) {x[i][j]=x[i][j] +( m1.x[i][k] * m2.x[k][j]); m=m1.m;

n=m2.n; }}}} void main() {clrscr(); matrix m1,m2,m3; m1.input(); m2.input(); m3.multiply(m1,m2); m3.output(); getch(); } Q- WAP #include<iostream.h> #include<conio.h> #include<process.h> void main() {clrscr(); int ch,i,top=-1,stack[5]; x: cout<<endl<<endl; cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl; cin>>ch; switch(ch) {case 1: top++; if(top<=4) {cout<<"Enter The Element"<<endl; cin>>stack[top]; cout<<"The Stack is"<<endl; for(i=0;i<=top;i++) cout<<stack[i]; goto x;} else {cout<<" ************* Stack OVERFLOW ********** "<<endl; goto x;} case 2: if(top>=0) {top--; cout<<"Stack is"<<endl; for(i=0;i<=top;i++) cout<<stack[i]; goto x;} else {cout<<"************** Stack UNDER FLOW ***********"<<endl; goto x;} case 3: exit(0); default : cout<<"WRONG CHOICE !!!!!!!!!!! "<<endl; goto x; }}

Q-WAP to modify records in a binary file. #include<iostream.h> #include<conio.h> #include<fstream.h> #include<string.h> struct emp {int eno; char name[20]; int sal;}e; void main() {clrscr(); int empno,x; cout<<"enter empno which is to be modified:"; cin>>empno; fstream f1; f1.open("emp.dat",ios::in|ios::out|ios::binary); while(!f1.eof()) {f1.read((char*)&e,sizeof(emp)); if(e.eno==empno) x=f1.tellg(); cout<<x<<endl; cout<<"enter employee no:"; cin>>e.eno;cout<<endl; cout<<"enter employee name:"; cin>>e.name; cout<<endl; cout<<"enter salary:"; cin>>e.sal; cout<<endl; f1.seekp(x-sizeof(emp),ios::beg); f1.write((char*)&e,sizeof(emp)); break;} f1.seekg(0); cout<<"the file after modification is"<<endl; f1.read((char*)&e,sizeof(emp)); while(!f1.eof()) {cout<<e.eno<<endl; cout<<e.name<<endl; cout<<e.sal<<endl; f1.read((char*)&e,sizeof(emp));} f1.close(); getch();} enter empno which is to be modified:1 24 enter employee no:5 enter employee name:nik enter salary:6543 the file after modification is 5 nik 6543 2 avaneesh 1234

3 Q- WAP to MERGE ARRAYS. #include<iostream.h> #include<conio.h> int c[100],i,j,k; class merged {int na,nb,a[50],b[50]; public: void merge(); void display(); void input(); }g; void merged::merge() {int j=0; int i=na-1; while((i>0)&&(j<nb)) {if (b[j]<a[i]) {c[k]=a[i]; i--; k++; }if (b[j]>a[i]) {c[k]=b[j]; j++; k++;} if (b[j]==a[i]) {c[k]=b[j]; j++; k++; c[k]=a[i]; i--; k++; }} if(i==-1) {while(j<nb) {c[k]=b[j]; j++; k++; }} if(j==nb) {while(i>=0) {c[k]=a[i]; i--; k++; }}} void merged::display() {for(i=0;i<na+nb;i++) cout<<c[i]; } void merged::input() {cout<<"Enter A Lim"<<endl; cin>>na; cout<<"Enter B Limit"<<endl; cin>>nb;

cout<<"Enter array A"<<endl; for(i=0;i<na;i++) cin>>a[i]; cout<<"Enter Array B"<<endl; for(j=0;j<nb;j++) cin>>b[j]; } void main() {clrscr(); g.input(); g.merge(); g.display(); getch(); }

You might also like