Você está na página 1de 14

BY: RICHA SINGH (XI-B)

Practical 1
Passing Parameters and Returning Values

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void add(int a,int b)
{
cout<<"Sum is "<<a+b<<endl;
}
void subtract(int a,int b)
{
cout<<"Difference is "<<a-b<<endl;
}
void multiply(int a, int b)
{
cout<<"Product is "<<a*b<<endl;
}
int divide(int a,int b)
{
int c=a/b;
return c;
}
int modulus(int a,int b)
{
int c=a%b;
return c;
}
void main()
{
int a,b,c;
clrscr();
for(b=0;b!=6;b++)
{
cout<<"1.Sum\n 2.Difference\n 3.Product\n 4.Quotient\n 5.Remainder\n 6.Exit\n Enter your choice\n";
cin>>c;
cout<<"Enter 2 no.\n";
cin>>a>>b;
switch(c)
{
case 1: add(a,b);
break;

1
case 2: subtract(a,b);
break;
case 3: multiply(a,b);
break;
case 4: a=divide(a,b);
cout<<"Quotient is "<<a<<endl;
break;
case 5: a=modulus(a,b);
cout<<"Remainder is "<<a<<endl;
break;
case 6: exit(0);
}
}
getch();
}

Output

2
Practical 2

<ctype.h> Header File

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch;
clrscr();
cout<<"Enter a character\n";
cin>>ch;
if(isalnum(ch))
{
if(isalpha(ch))
{
if(isupper(ch))
{
cout<<"It's an upper case alphabet\n";
ch=tolower(ch);
cout<<"Toggled value is "<<ch;
}
else if(islower(ch))
{
cout<<"It's an lower case alphabet\n";
ch=toupper(ch);
cout<<"Toggled value is "<<ch;
}
}
else if(isdigit(ch))
{
cout<<"It's a digit\n";
}
}
else
{
cout<<"It's a special character\n";
}
getch();
}

3
Output

4
Practical 3
<math.h> Header File

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b;
clrscr();
cout<<"Enter a no. and it's power to be raised\n";
cin>>a>>b;
a=pow(a,b);
cout<<"The result is "<<a<<"\n Enter another no.\n";
cin>>b;
a=sqrt(b);
cout<<"The square root is "<<a<<endl;
getch();
}
Output

5
Practical 4
Integer Arrays: Total Even and Total Odd Numbers

#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],b,c=0,d=0;
clrscr();
for(b=0;b<10;b++)
{
cout<<"Enter a no.\n";
cin>>a[b];
if(a[b]%2==0)
{
c++;
}
else
{
d++;
}
}
cout<<"Even no. are "<<c<<"\nOdd no. are "<<d<<endl;
getch();
}

Output

6
Practical 5
Integer Arrays: Replacement of Values

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],b;
clrscr();
for(b=0;b<5;b++)
{
cout<<"Enter a no.\n";
cin>>a[b];
if(a[b]%5==0)
{
a[b]=a[b]*a[b];
}
else
{
a[b]=a[b]/2;
}
}
for(b=0;b<5;b++)
{
cout<<a[b]<<endl;
}
getch();
}
Output

Prac
tical
6
Integer
Arrays:
Display
the
Minimu
m Value

#include
<iostrea
m.h>

7
#include<conio.h>
void main()
{
int a[5],b,c;
clrscr();
for(b=0;b<5;b++)
{
cout<<"Enter a no.\n";
cin>>a[b];
}
c=a[0];
for(b=1;b<5;b++)
{
if(a[b]<c)
{
c=a[b];
}
}
cout<<"Minimum value is "<<c<<endl;
getch();
}

Output

Practical 7
Integer Arrays: Arrangement in Ascending Order

#include<iostream.h>

8
#include<conio.h>
void main()
{
int a[5],b,c;
clrscr();
for(b=0;b<5;b++)
{
cout<<"Enter a no.\n";
cin>>a[b];
}
for(b=0;b<5;b++)
{
for(c=b+1;c<5;c++)
{
if(a[b]>a[c])
{
a[b]=a[b]+a[c];
a[c]=a[b]-a[c];
a[b]=a[b]-a[c];
}
}
}
cout<<"No in ascending order are\n";
for(c=0;c<5;c++)
{
cout<<a[c]<<"\t";
}
getch();
}
Output

Practical 8
Character Array:Toggling the String

#include<iostream.h>

9
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
char str[20];
int a;
clrscr();
cout<<"Enter a string\n";
gets(str);
for(a=0;str[a]!='\0';a++)
{
if(isupper(str[a]))
str[a]=tolower(str[a]);
else if(islower(str[a]))
str[a]=toupper(str[a]);
}
cout<<"Toggled string is "<<str<<endl;
getch();
}
Output

Practical 9
Character Array:Username and Password

#include<iostream.h>

10
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char str[20],ch[20],u[5]={"admin"},p[5]={"hello"};
int a,b;
clrscr();
cout<<"Enter username and password\n";
gets(str);
gets(ch);
a=strcmp(str,u);
b=strcmp(ch,p);
if(a==0&&b==0)
cout<<"welcome";
else
cout<<"Incorrect username or password";
getch();
}
Output

Practical 10
Check Palindrome or Not

#include<iostream.h>

11
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char str[20],ch[20];
clrscr();
cout<<"Enter a string\n";
gets(str);
strcpy(ch,str);
strrev(ch);
if(strcmp(str,ch)==0)
cout<<"Palindrome";
else
cout<<"Not a palindrome";
getch();
}
Output

Practical 11
Structures: Sales Data Type

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

12
struct sales
{
int sle[4];
char nme[20],ar[20],id[10];
};
void main()
{
sales s;
clrscr();
cout<<"Enter your id,name and area\n";
cin>>s.id>>s.nme>>s.ar;
int c,a=0;
for(c=0;c<4;c++)
{
cout<<"Enter your sale in "<<c+1<<" quarter\n";
cin>>s.sle[c];
a=a+s.sle[c];
}
cout<<"Id is "<<s.id<<endl;
cout<<"Name is "<<s.nme<<endl;
cout<<"Area is "<<s.ar<<endl;
for(c=0;c<4;c++)
{
cout<<"Sale in "<<c+1<<" quarter is "<<s.sle[c]<<endl;
}
cout<<"Total sale is "<<a<<endl;
cout<<"Average sale is "<<a/4<<endl;
getch();
}
Output

Practical
12
Array
Structures: 10 Employees Data

13
#include<iostream.h>
#include<conio.h>
struct employee
{
int sly;
char nme[20],dep[20],cd[5],desg[20];
};
void main()
{
employee s[10];
clrscr();
int c,a=0;
for(c=0;c<10;c++)
{
cout<<"Enter your code,name,department and designation\n";
cin>>s[c].cd>>s[c].nme>>s[c].dep>>s[c].desg;
cout<<"Enter your salary\n";
cin>>s[c].sly;
a=a+s[c].sly;
}
for(c=0;c<10;c++)
{
cout<<"Code is "<<s[c].cd<<endl;
cout<<"Name is "<<s[c].nme<<endl;
cout<<"Department is "<<s[c].dep<<endl;
cout<<"Designation is "<<s[c].desg<<endl;
cout<<"Salary is "<<s[c].sly<<endl;
}
cout<<"Total salary is "<<a<<endl;
cout<<"Average salary is "<<a/10<<endl;
getch();
}
Output

14

Você também pode gostar