#include<iostream.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define c 80
#define z 10
#define pi 3.14
void ls(char [],char);
void capital(char []);
int sum(int);
float cal(float,float,char);
void maxmin(int []);
int stlen(char []);
void palindrome(char []);
int vowcnt(char []);
float rad(float);
int rev(int);
int Sum(int);
void prime(int);
double fact(int);
int sqcu(int);
void fct(int);
void arev(char []);
void swap(int []);
void lcgcd(int,int);
void mul(int);
void upcase(char []);
int power(int,int);
int cmp(char[],char[]);
void arm(int);
void main()
{ clrscr();
char str9[c],str8[c],cd,str1[c],str3[c],op,chc,str4[c],str5[c],str6[c],fl[c],str7[c];
int cf,lep,yr,ch,n,m,x,y,nm[z],len,cnt,numb,reve,mn,u,pr,fac,sq,cu,nm1,swp[z],lc,ld,n1,n2,n3,x1;
float res,deg,radi;
double fa;
int gd=DETECT, gm,i=500;
initgraph(&gd, &gm,"");
settextstyle(1,0,4);
setcolor(LIGHTRED);
outtextxy(159,119,"COMPUTER PROJECT");
sound(i);
delay(100);
nosound();
getch();
settextstyle(6,0,2);
setcolor(YELLOW);
outtextxy(159,170,"Done by: Akshay. R");
sound(500);
delay(100);
nosound();
getch();
window(1,1,80,30);
textcolor(BLACK);
textbackground(BLACK);
do
{ clrscr();
settextstyle(2,0,5);
setcolor(LIGHTBLUE);
outtextxy(0,0,"Functions menu:");
sound(700);
delay(100);
nosound();
cout<<"\n1.To search for a element in a 1D array";
cout<<"\n2.Which capitalises first word in a sentence";
cout<<"\n3.Sum of series 1+2+3+....+n";
cout<<"\n4.To perform the job of a calculator";
cout<<"\n5.To find maximum & minimum number in an array";
cout<<"\n6.To find length of the string";
cout<<"\n7.To find if a string is a palindrome or not";
cout<<"\n8.To count the number of vowels in a string";
cout<<"\n9.To convert the angle in degree to radian measure";
cout<<"\n10.To reverse a given number";
cout<<"\n11.To find cube sum of individual digits";
cout<<"\n12.To find if a number is prime or composite";
cout<<"\n13.To find factorial of a number";
cout<<"\n14.To find square of a number if it is even or cube of it if the number is odd";
cout<<"\n15.To find the factors of a number";
cout<<"\n16.To reverse a string";
cout<<"\n17.To swap 1st & last elements in an array";
cout<<"\n18.To find LCD & GCD of 2 integers";
cout<<"\n19.To print multiplication table of a number";
cout<<"\n20.To read a string & converts it into uppercase";
cout<<"\n21.To find a number raised to a power n";
cout<<"\n22.To compare 2 strings";
cout<<"\n23.To print armstrong numbers upto a limit";
cout<<"\n\nEnter your choice(1-23): ";
cin>>ch;
cout<<"\n";
clrscr();
switch(ch)
{
case 1: cout<<"Enter the string: ";
gets(str1);
cout<<"Enter the element to be searched: ";
cin>>cd;
ls(str1,cd);
getch();
break;
case 2: cout<<"Enter a string: ";
gets(str3);
capital(str3);
getch();
break;
case 3: cout<<"Enter the limit: ";
cin>>n;
m=sum(n);
cout<<"Sum of series is: "<<m;
getch();
break;
case 4: cout<<"Enter 2 numbers: ";
cin>>x>>y;
cout<<"Enter a operator(+,-,*,/): ";
cin>>op;
res=cal(x,y,op);
cout<<"Result of operation is: "<<res;
getch();
break;
case 5: cout<<"Enter the numbers: ";
for(int i=0;i<z;++i)
{ cin>>nm[i];
}
maxmin(nm);
getch();
break;
case 6: cout<<"Enter the string: ";
gets(str4);
len=stlen(str4);
cout<<"Length of the string is: "<<len;
getch();
break;
case 7: cout<<"Enter the string: ";
gets(str5);
palindrome(str5);
getch();
break;
case 8: cout<<"Enter the string: ";
gets(str6);
cnt=vowcnt(str6);
cout<<"The vowel count is: "<<cnt;
getch();
break;
case 9: cout<<"Enter the angle in degrees: ";
cin>>deg;
radi=rad(deg);
cout<<"Angle in radians is: "<<radi;
getch();
break;
case 10: cout<<"Enter the number: ";
cin>>numb;
reve=rev(numb);
cout<<"Reverse of the number is: "<<reve;
getch();
break;
case 11: cout<<"Enter the number: ";
cin>>mn;
u=Sum(mn);
cout<<"Cube sum of individual digits is: "<<u;
getch();
break;
case 12: cout<<"Enter a number(greater than 1): ";
cin>>pr;
prime(pr);
getch();
break;
case 13: cout<<"Enter the number: ";
cin>>fac;
fa=fact(fac);
cout<<"Factorial of the number is: "<<fa;
getch();
break;
case 14: cout<<"Enter the number: ";
cin>>sq;
cu=sqcu(sq);
if(cu%2==0)
{ cout<<"Square of the number is: "<<cu;
}
else
{ cout<<"Cube of the number is: "<<cu;
}
getch();
break;
case 15: cout<<"Enter the number: ";
cin>>nm1;
fct(nm1);
getch();
break;
case 16: cout<<"Enter the string: ";
gets(fl);
arev(fl);
getch();
break;
case 17: cout<<"Enter the numbers: ";
for(i=0;i<z;++i)
{ cin>>swp[i];
}
swap(swp);
getch();
break;
case 18: cout<<"Enter 2 numbers: ";
cin>>lc>>ld;
lcgcd(lc,ld);
getch();
break;
case 19: cout<<"Enter a number: ";
cin>>n1;
mul(n1);
getch();
break;
case 20: cout<<"Enter the string: ";
gets(str7);
upcase(str7);
getch();
break;
case 21: cout<<"Enter the number & the value of n: ";
cin>>n2>>n3;
x1=power(n2,n3);
cout<<"Result is: "<<x1;
getch();
break;
case 22: cout<<"Enter the 1st string: ";
gets(str8);
cout<<"Enter the 2nd string: ";
gets(str9);
cf=cmp(str8,str9);
if(cf==0)
{ cout<<"Both strings are of equal length";
}
else if(cf==1)
{ cout<<"First string is greater than second string";
}
else
{ cout<<"Second string is greater than first string";
}
getch();
break;
case 23: cout<<"Enter the limit: ";
cin>>yr;
arm(yr);
getch();
break;
default: cout<<"Wrong choice";
sound(700);
delay(300);
nosound();
}
cout<<"\n\nDo you want to continue(Y/N)? ";
cin>>chc;
if(chc=='n'||chc=='N')
{ clrscr();
settextstyle(4,0,6);
setcolor(RED);
outtextxy(159,119,"Thank You");
delay(5);
}
sound(650);
delay(100);
nosound();
} while(chc=='Y' || chc=='y');
}
void ls(char a[],char b)
{
int ct=0;
cout<<"Element is found at: ";
for(int i=0;a[i]!='\0';++i)
{ if(a[i]==b)
{ ct++;
cout<<i+1<<",";
}
}
if(ct==0)
{ cout<<"\nElement is not found";
}
}
void capital(char d[])
{ cout<<"Modified string is: ";
for(int i=0;d[i]!='\0';++i)
{ d[0]=toupper(d[0]);
if(d[i]==' ')
{ d[i+1]=toupper(d[i+1]);
}
cout<<d[i];
}
}
int sum(int q)
{ int w=0;
for(int i=1;i<=q;++i)
{ w+=i;
}
return w;
}
float cal(float o,float p, char po)
{ float Res;
switch(po)
{ case '+':Res=o+p;
break;
case '-':Res=o-p;
break;
case '*':Res=o*p;
break;
case '/':Res=o/p;
break;
default: cout<<"Wrong operator";
}
return Res;
}
void maxmin(int qw[])
{ int max,min;
max=min=qw[0];
for(int i=0;i<z;++i)
{ if(qw[i]>max)
{ max=qw[i];
}
else if(qw[i]<min)
{ min=qw[i];
}
}
cout<<"Maximum number is: "<<max;
cout<<"\nMinimum number is: "<<min;
}
int stlen(char st[])
{ for(int i=0;st[i]!='\0';++i)
{ cout<<"";
}
return i;
}
void palindrome(char pal[])
{ int flag=1;
for(int len=0;pal[len]!='\0';len++);
for(int i=0,j=len-1;i<len/2;i++,j--)
{ if(pal[i]!=pal[j])
{ flag=0;
break;
}
}
if(flag==0)
{ cout<<"String is not a palindrome";
}
else
{ cout<<"String is a palindrome";
}
}
int vowcnt(char vow[])
{ int count=0;
for(int i=0;vow[i]!='\0';++i)
{ switch(vow[i])
{ case 'a': ++count;break;
case 'e': ++count;break;
case 'i': ++count;break;
case 'o': ++count;break;
case 'u': ++count;break;
case 'A': ++count;break;
case 'E': ++count;break;
case 'I': ++count;break;
case 'O': ++count;break;
case 'U': ++count;break;
default: cout<<"";
}
}
return count;
}
float rad(float dg)
{ float mes;
mes=(pi/180)*dg;
return mes;
}
int rev(int nm)
{ int rem=0,re=0;
while(nm>0)
{ rem=nm%10;
re=rem+(re*10);
nm/=10;
}
return re;
}
int Sum(int t)
{ int rem=0,v=0;
while(t>0)
{ rem=t%10;
v+=rem*rem*rem;
t/=10;
}
return v;
}
void prime(int prm)
{ int count=0;
for(int i=2;i<prm;++i)
{ if(prm%i==0)
{ count++;
}
}
if(count==0)
{ cout<<"Prime number";
}
else
{ cout<<"Composite number";
}
}
double fact(int y)
{ double facto=1.0;
for(int i=1;i<=y;++i)
{ facto*=i;
}
return facto;
}
int sqcu(int qs)
{ int res=0;
if(qs%2==0)
{ res=qs*qs;
}
else
{ res=qs*qs*qs;
}
return res;
}
void fct(int nm2)
{ cout<<"Factors of the number are: ";
for(int i=1;i<=nm2/2;++i)
{ if(nm2%i==0)
{ cout<<i<<" ";
}
}
}
void arev(char fl1[])
{ for(int len=0;fl1[len]!='\0';++len);
cout<<"Reverse of the string is: ";
for(int i=len-1;i>=0;--i)
{ cout<<fl1[i];
}
}
void swap(int sp[])
{ int sop;
for(int i=0;i<z;++i)
{ sop=sp[0];
sp[0]=sp[z-1];
sp[z-1]=sop;
cout<<"Swapped first value is :"<<sp[0]<<" & last value is: "<<sp[z-1];
break;
}
}
void lcgcd(int a1,int a2)
{ int max=0,min=1000;
for(int i=2,j=2;i<=a1,j<=a2;++i,++j)
{ if(a1%i==0 && a2%j==0)
{ if(i==j)
{ if(j<min)
{ min=j;
}
if(j>max)
{ max=j;
}
}
}
}
if(min==1000 && max==0)
{ cout<<"No common divisors";
}
else
{ cout<<"LCD: "<<min<<"\nGCD: "<<max;
}
}
void mul(int m1)
{ int mu=1;
cout<<"Multiplication table";
for(int i=1;i<11;++i)
{ mu=m1*i;
cout<<"\n"<<m1<<"*"<<i<<"="<<mu;
}
}
void upcase(char up[])
{ cout<<"Modified string is: ";
for(int i=0;up[i]!='\0';++i)
{ up[i]=toupper(up[i]);
cout<<up[i];
}
}
int power(int b1,int b2)
{ int powr=1;
for(int i=0;i<b2;++i)
{ powr*=b1;
}
return(powr);
}
int cmp(char a[],char b[])
{ for(int i=0;a[i]!='\0';++i);
for(int j=0;b[j]!='\0';++j);
if(i==j)
{ return 0;
}
else if(i>j)
{ return 1;
}
else
{ return -1;
}
}
void arm(int ye)
{ int ab,bc,cd,su=0;
cout<<"\nArmstrong numbers from 1 to "<<ye<<" are: \n";
for(int i=1;i<=ye;++i)
{ ab=i/100;
bc=i/10-ab*10;
cd=i%10;
su=(ab*ab*ab)+(bc*bc*bc)+(cd*cd*cd);
if(su==i)
{ cout<<i<<" ";
}
}
}
/*Done by: Akshay. R */