programs Programmed by Aastitva Jain: Work Done in Class 11
programs Programmed by Aastitva Jain: Work Done in Class 11
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
long km,m,cm,x;
cout<<"Enter value in centimeters :"<<endl;
cin>>cm;
km=cm/100000;
m=(cm%100000)/100;
x=(cm%100000)%100;
cout<<"The value is "<<km<<" kilometers, "<<m<<" meters and
"<<x<<" centimeters."<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
void binarysearch(int[],int,int);
void main()
{
clrscr();
int a[10],n,i;
cout<<"Enter the values for an array:";
for(i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"Enter the number :";
cin>>n;
binarysearch(a,10,n);
getch();
}
void binarysearch(int x[],int y,int z)
{
int s=0,e=y-1,m,f,i,j;
for(i=0;i<y-1;i++)
{
for(j=i+1;j<y;j++)
{
if(x[i]>x[j])
{
int t=x[i];
x[i]=x[j];
x[j]=t;
}
}
}
while(s<=e)
{
m=(s+e)/2;
if(x[m]==z)
{
f=1;
cout<<"Search Successful";
break;
}
else if(z>x[m])
{
s=m+1;
}
else
{
e=m-1;
}
}
if(f!=1)
cout<<"Search Unsuccessful";
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int sum=0,i,j,n;
cout<<"Enter the length of the array :";
cin>>n;
int a['n']['n'];
cout<<"Enter the values for the array :"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int i,j,r,c;
cout<<"Enter the no. of rows and columbs"<<endl;
cin>>r>>c;
int a['r']['c'],b['c']['r'];
cout<<"Enter the values for Matrix :"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
{
b[i][j]=a[j][i];
}
}
cout<<"\n\nThe values of original matrix :"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
cout<<"\n\nThe values of transpose matrix :"<<endl;
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<endl;
}
getch();
}
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void main()
{
clrscr();
char line[80];
int counter=0;
cout<<"Enter a line :";
gets(line);
for(int i=0;i<80;i++)
{
switch(line[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
counter++;
}
}
cout<<"The number of vowels in the line :"<<counter;
getch();
}
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void main()
{
clrscr();
char line[80];
int i,j,length=0;
cout<<"Enter a line :";
gets(line);
for(i=0;line[i]!='\0';i++)
{
length++;
}
char l[80];
for(i= 0,j=length-1;i<length;i++)
{
l[i]=line[j];
j--;
}
int flag=0;
for(i=0;i<length;i++)
{
if(l[i]!=line[i])
{
flag=1;
break;
}
}
puts(l);
cout<<endl;
if(flag==1)
{
cout<<"The line is not a palindrome";
}
else
{
cout<<"The line is palindrome";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void linearsearch(int[],int,int);
void main()
{
clrscr();
int a[10],n,i;
cout<<"Enter the values for an array:";
for(i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"Enter the number :";
cin>>n;
linearsearch(a,10,n);
getch();
}
void linearsearch(int x[],int y,int z)
{
int f;
for(int i=0;i<y;i++)
{
if(x[i]==z)
{
f=1;
cout<<"Search Successful";
}
}
if(f!=1)
cout<<"Search Unsuccessful";
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int a[100][100],i,j,n,space=0,k;
cout<<"Enter the length of the array :";
cin>>n;
cout<<"Enter the numbers :"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"Original matrix :"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
cout<<"Upper triangle :"<<endl;
for(i=0;i<n;i++)
{
for(k=1;k<=space;k++)
{
cout<<"\t";
}
space++;
for(j=i;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
getch();
}
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
void main()
{
clrscr();
char line[80];
cout<<"Enter a line :";
gets(line);
line[0]=toupper(line[0]);
for(int i=0;i<80;i++)
{
if(line[i]==' ')
{
line[i+1]=toupper(line[i+1]);
}
}
cout<<line;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double i,n,sum=0,f,j;
cout<<"Enter the value of 'n' :"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
f=1;
for(j=i;j>=1;j--)
{
f=f*j;
}
sum=sum+(1/f);
}
cout<<"The sum of the series is :"<<sum;
getch();
#include <iostream.h>
#include <conio.h>
#include <Math.h>
void main()
{
clrscr();
float x,t,sum=1;
int i,n;
cout<<"Enter the value of n :";
cin>>n;
cout<<"Enter the value of x :";
cin>>x;
x=x*3.1412/180;
t=t+1;
for(i=1;i<=n;i++)
{
t=t*pow((double)(-1),(double)(2*i-1))*x*x/(2*i*(2*i-1));
sum=sum+t;
}
cout<<"The sum of the series :"<<sum;
getch();
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float sales, comm;
cout<<"Enter sales made by the salesman :";
cin>>sales;
(sales>5000)?((sales>12000)?((sales>22000)?
((sales>3000
0)?(comm=sales*.15):
(comm=sales*.10)):(comm=sales*.07)):
(comm=sales*.03)): (comm=0);
cout<<"\n"<<"The commision is :"<<comm<<"\n";
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
char ch;
cout<<"Enter a character :";
cin>>ch;
(((ch>= 'A')&&(ch<='Z'))||((ch>='a')&&(ch<='z')))?
(cout<<"You entered an alphabet"<<"\n"):
(((ch>='0')&&(ch<='9'))?(cout<<"You entered a digit"<<"\n"):
(cout<<"You entered a character other than alphabets and
digits"<<"\n"));
getch();
}
/*Write a program to input an array from the user and print it on the
diagonals of a 2-D array*/
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n[5],a[5][5],i,j;
cout<<"Enter five numbers :";
for(i=0;i<5;i++)
{
cin>>n[i];
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==j)
{
a[i][j]=n[i];
}
else if(i+j==4)
{
a[i][j]=n[j];
}
else
{
a[i][j]=0;
}
}
}
cout<<"The answer :"<<endl;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void fibo(int);
void main()
{
clrscr();
cout<<"Enter n :";
int n;
cin>>n;
fibo(n);
getch();
}
void fibo(int s)
{
int a=0,b=1,c=a+b;
cout<<a<<"\t"<<b<<"\t";
while(c<s)
{
cout<<c<<"\t";
a=b;
b=c;
c=a+b;
}
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,s=0,t=0,k=0;
cout<<"Enter a number: ";
cin>>n;
s=n*n;
int p=n;
while(n!=0)
{
n=n/10;
k++;
}
for(int i=1;i<=k;i++)
{
if(s%10!=p%10)
{
t++;
break;
}
s=s/10;
p=p/10;
}
if(t==0)
{
cout<<"Automorphic";
}
else
{
cout<<"Not Automorphic";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Enter the length of the array:";
int n,i,j,temp;
cin>>n;
int a[100];
cout<<"Enter the numbers:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
for(i=1;i<n;i++)
{
temp=a[i];
j=i;
while(j!=0 && temp<a[j-1])
{
a[j]=a[j-1];
j--;
}
a[j]=temp;
}
cout<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Enter the length of the array:";
int n,i,j,pos,small;
cin>>n;
int a[100];
cout<<"Enter the numbers:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
for(i=0;i<n;i++)
{
small=a[i];
pos=i;
for(j=i+1;j<n;j++)
{
if(small>a[j])
{
small=a[j];
pos=j;
}
}
a[pos]=a[i];
a[i]=small;
}
cout<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Enter the length of the array:";
int n,i,j,temp;
cin>>n;
int a[100];
cout<<"Enter the numbers:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
class interest
{
public:
double p,r,t;
interest()
{
p=0;
r=0;
t=0;
}
void input()
{
cout<<"Enter the principal :"<<endl;
cin>>p;
cout<<"Enter the rate :"<<endl;
cin>>r;
cout<<"Enter the time :"<<endl;
cin>>t;
}
getch();
};
ci1=a1-p;
}
void display()
{
cout<<"The compound interest is"<<ci1<<endl;
cout<<"The amount is "<<a1<<endl;
}
};
void main()
{
si s;
s.input();
s.calc();
s.display();
ci c;
c.input();
c.calc();
c.display();
getch();
}
#include<iostream.h>
#include<conio.h>
class Saddle
{
int arr[20][20];
int N,i,j,k,l,check,m;
public:
Saddle(unsigned int nk)
{
N=nk;
cout<<"Enter Numbers:";
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
cin>>arr[i][j];
}
}
}
void displayArray()
{
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
cout<<arr[i][j]<<"\t";
}
cout<<endl;
}
}
void saddlePoint()
{
for(i=0;i<N;i++)
{
int low=arr[i][0];
k=0;
for(j=0;j<N;j++)
{
if(low>arr[i][j])
{
low=arr[i][j];
k=j;
}
}
int max=arr[0][k];
m=0;
for(l=0;l<N;l++)
{
if(max<arr[l][k])
{
max=arr[l][k];
m=l;
}
}
if(max==low)
{
check=1;
break;
}
}
if(check==1)
{
cout<<"There is a saddle
("<<m+1<<","<<k+1<<")";
point:
}
else
{
cout<<"There is no saddle point";
}
}
};
void main()
{
clrscr();
cout<<"Enter the size of 2D array:";
int n;
cin>>n;
Saddle s(n);
s.displayArray();
s.saddlePoint();
getch();
}
/*Write a program to initialize an array of 20 elements and sort all the odd
positioned values in ascending order and even positioned values in
descending order*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20];
int i,j;
cout<<"Enter twenty values:";
for(i=0;i<20;i++)
{
cin>>a[i];
}
for(i=0;i<=19;i++)
{
cout<<a[i]<<"\t";
}
for(i=0;i<19;i=i+2)
{
for(j=i+2;j<=19;j=j+2)
{
if(a[i]>a[j])
{
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=1;i<19;i=i+2)
{
for(j=i+2;j<=19;j=j+2)
{
if(a[i]<a[j])
{
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i<=19;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
/*Write a program to input names and salary. Then sort through namewise or
salary-wise (as provided by the user)*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<String.h>
void main()
{
clrscr();
char n[5][20];
int s[5];
int ch,i,j;
cout<<"Enter names with salary:";
for(i=0;i<5;i++)
{
gets(n[i]);
cin>>s[i];
}
cout<<"Enter 1 to sort namewise"<<endl;
cout<<"Enter 2 to sort salary wise"<<endl;
cin>>ch;
for(i=0;i<5;i++)
{
cout<<n[i]<<"\t"<<"\t"<<s[i]<<endl;
}
switch(ch)
{
case 1:
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(n[i],n[j])>0)
{
int t=s[i];
s[i]=s[j];
s[j]=t;
char h[20];
strcpy(h,n[i]);
strcpy(n[i],n[j]);
strcpy(n[j],h);
}
}
}
break;
case 2:
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
if(s[i]>s[j])
{
int t=s[i];
s[i]=s[j];
s[j]=t;
char h[20];
strcpy(h,n[i]);
strcpy(n[i],n[j]);
strcpy(n[j],h);
}
}
}
break;
default:
cout<<"Invalid Choice";
}
for(i=0;i<5;i++)
{
cout<<n[i]<<"\t"<<"\t"<<s[i]<<endl;
}
getch();
}
void main()
{
clrscr();
cout<<"Press 1 to convert binary to decimal"<<endl;
cout<<"Press 2 to convert octal to decimal"<<endl;
cout<<"Press 3 to convert hexa to decimal"<<endl;
cout<<"Enter your choice:"<<endl;
int ch;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the number in binary form"<<endl;
unsigned long n;
cin>>n;
int i=0,nu=0;
while(n!=0)
{
int a=n%10;
nu=nu+a*pow(2,i);
i++;
n=n/10;
}
cout<<"The decimal number is :"<<nu<<endl;
getch();
break;
case 2:
cout<<"Enter the number in octal form"<<endl;
long n1;
cin>>n1;
int j=0,nu1=0;
while(n1!=0)
{
int b=n1%10;
nu1=nu1+b*pow(8,j);
j++;
n1=n1/10;
}
cout<<"The decimal number is :"<<nu1<<endl;
getch();
break;
case 3 :
case 'F':
d=15;
break;
default:
d=nu3[z]-48;
}
nu3=nu3+d*pow(16,s);
s++;
}
cout<<nu3<<endl;
break;
getch();
}
}
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
ofstream file;
file.open("Student.txt");
char n[20],st[3],no[3];
int m[5],i=0;
cout<<"ENTER NAME, STANDARD, ROLL NO., MARKS
:\n";
gets(n);
gets(st);
gets(no);
file<<n<<"\t";
file<<st<<"\t";
file<<no<<"\n";
while(i<5)
{
cin>>m[i];
file<<m[i]<<"\t";
i++;
}
file.close();
getch();
}
#include<fstream.h>
#include<conio.h
#include<stdio.h>
void main()
{
char name[25],tele[12];
ofstream file("file.txt");
for(int i=1;i<5;i++)
{
cout<<"Enter the name and phone number";
gets(name);
gets(tele);
file<<name<<endl;
file<<tele<<endl;
}
file.close();
getch();
}
void main()
{
clrscr();
ifstream file;
ofstream file1;
file.open("Student.txt");
file1.open("Student1.txt");
char n[20],st[3],no[3];
int m,i=0,t,a;
file>>n;
file>>st;
file>>no;
int i=0;
while(i<5)
{
file>>m;
t=t+m;
i++;
}
a=t/5;
file1<<"TOTAL = "<<t<<"\t"<<"AVERAGE = "<<a;
file.close();
file1.close();
getch();
}
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<snap.h>
void main()
{
int gdriver = DETECT,gmode;
int x,y,i;
initgraph(&gdriver,&gmode,"C:\\TurboC3\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
for(i=30;i<200;i++)
{
delay(100);
setcolor(i/10);
arc(x,y,0,180,i-10);
}
capture("C:\\TC\\Capture\\Capture1.jpg");
getch();
}