Sei sulla pagina 1di 39

Date : 11.jan.

2011

//Write a program to input a line//


#include<iostream.h> #include<conio.h> void main() { char sent[200]; cout<<"enter the line"; cin.getline(sent,200); cout<<endl<<"the entered line is:"<<endl<<sent; getch(); }

Output:-

Date: 18.jan.2011

//Write a program to calculate salary of an employee using structure and switch statement. (1) Employee whose basic salary is fixed. DA=55% HRA=25% MEDICAL ALLOWANCE=RS.850
(2) Employee

whose basic salary is according to no. of hour worked.

1hr=117 DA=35% HRA=18% MEDICAL ALLOWANCE=RS.765 (3) Employee whose basic salary is according to units produced per unit=87.50 Result should be in absolute value//
#include<iostream.h> #include<conio.h> struct salary { float g_sal; float b_sal; float DA; float HRA; int m_all; }; main() { struct salary e1; int hr,category; int unit; cout<<"enter the category of employee"<<endl;

cin>>category; switch(category) { case 1: cout<<"enter the basic salary"<<endl; cin>>e1.b_sal; e1.DA=0.55*e1.b_sal; e1.HRA=0.25*e1.b_sal; e1.m_all=850; e1.g_sal=e1.b_sal+e1.DA+e1.HRA+e1.m_all; cout<<"the grass salary is"<<e1.g_sal<<endl; break; case 2: cout<<"enter the no. of hours worked"<<endl; cin>>hr; e1.b_sal=hr*117; e1.DA=0.35*e1.b_sal; e1.HRA=0.18*e1.b_sal; e1.m_all=765; e1.g_sal=e1.b_sal+e1.DA+e1.HRA+e1.m_all; cout<<"the grass salary is"<<e1.g_sal<<endl; break; case 3: cout<<"enter the no.of units produced"<<endl; cin>>unit;

e1.b_sal=unit*87.50; e1.DA=0.31*e1.b_sal; e1.HRA=0.14*e1.b_sal; e1.m_all=666; e1.g_sal=e1.b_sal+e1.DA+e1.HRA+e1.m_all; cout<<"the grass salary is"<<e1.g_sal<<endl; break; default: cout<<"category of the employee does not matched"; } getch(); }

Output:-

Date : 23.jan.2011

//Write a program in which a function accepts no arguments and returns no value//


#include<iostream.h> #include<conio.h> void func1(); void func2(); void main() { func1(); func2(); func1(); } void func1() { int i; for(i=1;i<10;i++) cout<<i; cout<<endl; } void func2() { int j; for(j=1;j<10;j++) cout<<"*"; cout<<endl;

cout<<endl; getch(); }

Output:-

Date : 23.jan.2011

//Write a program in which a function accepts arguments and returns no value//


#include<iostream.h> #include<conio.h> void func1(int,int); main() { int a,b,prod; cout<<"enter the value of a and b"<<endl; cin>>a>>b; func1(a,b); } void func1(int c,int d) { int x; x=c*d; cout<<"the product ogf two no is="<<x; getch(); }

Output:-

Date:23.jan.2011

//Write a program of functions with arguments and return values//

#include<iostream.h> #include<conio.h> float division(int,int); void main() { int a,b; float c; cout<<"enter dividend:"; cin>>a; cout<<endl<<"enter divisor:"; cin>>b; c=division(a,b); cout<<endl<<"quotient is:"<<c; getch(); } float division(int x,int y) { //float c; //c=(float)x/y; return((float)x/y); }

Output:-

Date:23.jan.2011

//write a program with no arguments but return values//

#include<iostream.h> #include<conio.h> int no_arg(); void main() { int a; a=no_arg(); cout<<endl<<"value returned to main is:"<<a; getch(); } int no_arg() { cout<<"control entered in function"; int n; cout<<endl<<"enter the number:"; cin>>n; return(n); }

Output:-

Date:24.jan.2011

//write a program of functions that return multiple values//

#include<iostream.h> #include<conio.h> void compute(int,int,int*,int*); void main() { int a,b; int add,subtract; cout<<"enter two numbers"; cin>>a>>b; compute(a,b,&add,&subtract); cout<<endl<<"values returned to main:"; cout<<endl<<"add="<<add; cout<<endl<<"subtraction="<<subtract; getch(); } void compute(int a,int b,int*x,int*y) { *x=a+b; *y=a-b; }

Output:-

Date: 28.jan.2011

//write a program to merge two arrays//


#include<iostream.h> #include<conio.h> void main() { int a[20],b[20],c[50]; int i,j,m,n,l; cout<<"number of elements in first array"; cin>>m; cout<<"enter the elements of first array:"<<endl; for(i=0;i<m;i++) { cin>>a[i]; } cout<<"number of elements in second array:"; cin>>n; cout<<"enter the elements of second array:"<<endl; for(i=0;i<n;i++) { cin>>b[i]; } for(i=0;i<m;i++) c[i]=a[i]; l=m+n; for(i=m,j=0;i<l;i++,j++)

{ c[i]=b[j]; } cout<<"array after merging:"<<endl; for(i=0;i<l;i++) { cout<<c[i]; cout<<" "; } getch(); }

Output:-

Date:29.jan.2011

//Write a program to multiply two matrices using pointers//

#include<iostream.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3]; int i,j,k; cout<<"enter matrix a:"<<endl; cout<<endl<<"three rows and three columns of matrix a"; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>a[i][j]; } } cout<<"enter matrix b"<<endl; cout<<endl<<"three rows and three columns of matrix b"; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>b[i][j]; } } cout<<"matrix c is:"<<endl;

for(i=0;i<3;i++) { for(j=0;j<3;j++) { *(*(c+i)+j)=0; for(k=0;k<3;k++) { *(*(c+i)+j)+=*(*(a+i)+k)**(*(b+k)+j); } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<(*(*(c+i)+j)); cout<<" "; } cout<<"\n"; } getch(); } Output:-

Date:11.feb.2011

//Write a program of Hollywood bollywood game //

#include<iostream.h> #include<conio.h> #include<string.h> #include<dos.h> #include<process.h> static int cnt=0; void main() { clrscr(); char film[150],ch,film2[150]; int choi,len,res=0,dig=0,j,count=0,len1,flag=1,p; cout<<"enter 1 for hollywood & 2 for bollywood"; cin>>choi; cout<<"enter the name of the film"; cin>>film; len=strlen(film); len1=len; clrscr(); gotoxy(15,10); if(choi==1) cout<<"hollywood"; else cout<<"bollywood"; for(int i=0;i<len1;i++) {

gotoxy(15+i,12); switch(film[i]) { case'a': cout<<"a"; len--; film2[cnt]='a';


cnt++; break; case'e': cout<<"e"; len--; film2[cnt]='e';

cnt++; break; case'i': cout<<"i"; len--; film2[cnt]='i'; cnt++; break; case'o': cout<<"o"; len--; film2[cnt]='o';

cnt++; break; case'u': cout<<"u"; len--; film2[cnt]='u'; cnt++; break; case'.': cout<<"."; len--; break; case' ': cout<<" "; len--; break; default: cout<<"_"; } } gotoxy(15,15); cout<<"guess the film"; while(flag==1) { p=0;

dig=0; gotoxy(37,15); cin>>ch; film2[cnt]=ch; if(cnt>=1) { for(int k=0;k<cnt;k++) { if(film2[k]==ch) p=1; } } cnt++; for(j=0;j<len1;j++) { if(film[j]==ch) { dig++; count++; if(p==1) { count--; } gotoxy((15+j),12); cout<<ch;

if(count==len) { gotoxy(15,17); cout<<"congrats you won!by"<<"points"; getch(); exit(0); } } } if(dig==0) { if(p==1) { res--; } gotoxy((15+res),10); cout<<ch; res++; if(res==9) { flag=0; gotoxy(15,17); cout<<"sorry you lost,the name of film was"<<film; getch(); }

} } }

Output:-

Date:15.feb.2011

//write a program to count the vowels in a string//

#include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[10],a; int vowel=0; int flag; clrscr(); do { vowel=0; cout<<"enter the string:"; cin>>str; for(int i=0;i<strlen(str);i++) { //flag=0; if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u') { vowel++; flag=1; } if(flag==1) cout<<endl<<str[i]<<"present at location"<<i<<endl; }

cout<<endl<<"total="<<vowel; cout<<endl<<"continue(y/n):"; cin>>a; } while(a!='n'); getch(); }

Output:-

Date:16.feb.2011

//Write a program in which number 1 to 100 are divisible by 2, 3 and 5//


#include<iostream.h> #include<conio.h>

static int two; static int three; static int five; void main() { clrscr(); for(int i=1;i<=100;i++) { if(i%2==0) ++two; if(i%3==0) ++three; if(i%5==0) ++five; } cout<<endl<<"two="<<two; cout<<endl<<"three="<<three; cout<<endl<<"five="<<five; getch(); } Output:-

Date:17.feb.2011

//C++ PROGRAM TO PASS OBJECT AS AN ARGUMEMT. The program adds the two heights given in feet and inches. //
#include<iostream.h> #include<conio.h>

class height { int feet,inches; public: void getht(int f,int i) { feet=f; inches=i; } void putheight() { cout<<"\nHeight is:"<<feet<< "feet\t"<<inches<<"inches"<<endl; } void sum(height a,height b) { height n; n.feet = a.feet + b.feet; n.inches = a.inches + b.inches; if(n.inches ==12) { n.feet++; n.inches = n.inches -12; } cout<<endl<<"Height is "<<n.feet<<" feet and "<<n.inches<<endl; }

}; main() { height h,d,a; clrscr(); h.getht(6,5); a.getht(2,7); h.putheight(); a.putheight(); d.sum(h,a); getch(); }

Output:-

Date:17.feb.2011

//Write a program to reverse a string using recursion//


#include<iostream.h> #include<string.h> #include<conio.h> void rev(char str[],int l,int k) {

char temp; if(k<(l/2)+1) { temp=str[l]; str[l]=str[k]; str[k]=temp; k++; l--; rev(str,l,k); } } void main() { clrscr(); char st[50]; int i,l=0; cout<<"\n enter the string:"; cin>>st; for(i=0;st[i]!='\0';i++) { l++; } l--; rev(st,l,0); cout<<"\n the reverse of string is:"<<st;

getch(); }

Output:-

Potrebbero piacerti anche