Project Programs for CBSE Class XII
Q1. WAP to generate an Anti-Spiral matrix.
Solution :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20][20],x,y,n,s,p;
cout<<"Enter size (even no.):";
cin>>s;
cout<<"Enter number:";//entry of starting no
cin>>n;
s--;
p=s/2;
for(x=p;x>=0;x--)//filling of elements in required order
{
for(y=x;y<=(s-x);y++)
a[x][y]=n++;
for(y=(x+1);y<=(s-x);y++)
a[y][s-x]=n++;
for(y=s-(x+1);y>=x;y--)
a[s-x][y]=n++;
for(y=s-(x+1);y>x;y--)
a[y][x]=n++;
}
cout<<endl;
for(x=0;x<=s;x++)//display of matrix after filling
{
for(y=0;y<=s;y++)
cout<<a[x][y]<<"\t";
cout<<endl<<endl;
}
getch();
}
/* OUTPUT
Enter size (even no.):4
Enter number:5
9 10 11 12
20 5 6 13
19 8 7 14
18 17 16 15
*/
Q2. WAP to find future date.
Solution :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int d,m,y,da;
cout<<"enter date in dd-mm-yyyy format:";
cin>>d;cout<<"-";cin>>m;cout<<"-";cin>>y;
cout<<"enter no. of days:";
cin>>da;
while(da>0)
{
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
{
if(d<31)
{
d++;
da--;
continue;
}
if(d==31 && m!=12)
{
m++;
d=1;
da--;
continue;
}
if(d==31 && m==12)
{
y++;
m=1;
d=1;
da--;
continue;
}
}
if(m==4 || m==6 || m==9 || m==11)
{
if(d<30)
{
d++;
da--;
continue;
}
if(d==30)
{
m++;
d=1;
da--;
continue;
}
}
if(m==2)
{
if(y%4==0)
{
if(d<29)
{
d++;
da--;
continue;
}
if(d==29)
{
m++;
d=1;
da--;
continue;
}
}
else
{
if(d<28)
{
d++;
da--;
continue;
}
if(d==28)
{
m++;
d=1;
da--;
continue;
}
}
}
}
cout<<"the future date= "<<d<<"-"<<m<<"-"<<y;
getch();
}
/* OUTPUT
enter date in dd-mm-yyyy format:11 05 2000
--enter no. of days:200
the future date= 27-11-2000
*/
Q3.WAP to find the number of days between two dates.
Solution :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int d,m,y,da=0,d2,m2,y2;
cout<<"enter 1st date in dd-mm-yyyy format:";
cin>>d;cout<<"-";cin>>m;cout<<"-";cin>>y;
cout<<"enter 2nd date in dd-mm-yyyy format:";
cin>>d2;cout<<"-";cin>>m2;cout<<"-";cin>>y2;
while(d!=d2 || m!=m2 || y!=y2)
{
da++;
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
{
if(d<31)
{
d++;
continue;
}
if(d==31 && m!=12)
{
m++;
d=1;
continue;
}
if(d==31 && m==12)
{
y++;
m=1;
d=1;
continue;
}
}
if(m==4 || m==6 || m==9 || m==11)
{
if(d<30)
{
d++;
continue;
}
if(d==30)
{
m++;
d=1;
continue;
}
}
if(m==2)
{
if(y%4==0)
{
if(d<29)
{
d++;
continue;
}
if(d==29)
{
m++;
d=1;
continue;
}
}
else
{
if(d<28)
{
d++;
continue;
}
if(d==28)
{
m++;
d=1;
continue;
}
}
}
}
cout<<"The number of days="<<da;
getch();
}
Q4. WAP to find the number of vowel pairs in an entered string.
Solution :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char s[100],v[10]="AEIOUaeiou";//string of all vowels to be checked
int l,a[5][5],x,y,c1,c2,f,p1,p2;
for(x=0;x<5;x++)
{
for(y=0;y<5;y++)
a[x][y]=0;
}
cout<<"Enter sentence:";
cin.getline(s,100);
l=strlen(s);
for(x=0;x<l-1;x++)
{
f=0;
c1=s[x];
c2=s[x+1];
for(y=0;y<10;y++)
{
if(c1==v[y])
{
p1=y;
for(y=0;y<10;y++)
{
if(c2==v[y])
{
p2=y;
f=1;
}
}
break;
}
}
if(f==1)
{
if(p1>4)
p1-=5;
if(p2>4)
p2-=5;
a[p1][p2]++;
}
}
cout<<"\n\nVovel pairs are:\n\n\n";
cout<<"\t";
for(x=0;x<5;x++)
cout<<v[x]<<"\t";
cout<<endl<<endl;
for(x=0;x<5;x++)
{
cout<<v[x]<<"\t";
for(y=0;y<5;y++)
cout<<a[x][y]<<"\t";
cout<<endl<<endl;
}
getch();
}
Q5. WAP to enter a number and print it in words.
Solution :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,r;
char na1[9][5]={"one","two","three","four","five","six","seven","eight","nine"};
char na2[8][7]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninty"};
char na3[10][9]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sisteen","seventeen","eighteen","nineteen"};
cout<<"Enter number:";
cin>>n;
if(n>=1000)//checking thousand'th digit for n>1000
{
r=n/1000;
n=n%1000;
r--;
cout<<na1[r]<<" thousand ";
}
if(n>=100)//checking hundered'th digit for n>100
{
r=n/100;
n=n%100;
r--;
cout<<na1[r]<<" hundred ";
}
if(n>=20)//checking last 2 digits for n>20
{
r=n/10;
n=n%10;
r-=2;
cout<<" "<<na2[r];
}
if(n>=10)//checking unit digit for n>10
{
r=n%10;
n=0;
r--;
cout<<na3[r];
}
if(n>0)
cout<<" "<<na1[(n-1)];
getch();
}
/* OUTPUT
Enter number:1254
one thousand two hundred fifty four
*/
To be updated soon......
Gaurav Nigam

0 comments:
Post a Comment