Documente Academic
Documente Profesional
Documente Cultură
//Header Files
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
for(i=count-1,j=0;i>=0;i--,j++)
{
s2[i]=s1[j];
}
s2[j]='\0';
s3[j]=' ';
j++;
for(i=0;s2[i]!='\0';i++,j++)
s3[j]=s2[i];
s3[j]='\0';
cout<<"The concatinated string is "<<s3;
break;
l1=strlen(s1);
l2=strlen(s2);
if(l1!=l2)
cout<<"The two strings are unequal";
else
{
for(i=0;s1[i]!='\0';i++)
{
r1=s1[i];
r2=s2[i];
if(r1!=r2)
{
flag=1;
break;
}
}
}
if(flag==1)
cout<<"The strings are not equal";
else
cout<<"The strings are equal";
break;
//Wrong choice
default: cout<<"Invalid entry";
}//End of main
/*
OUTPUT
MAIN MENU
1. LENGTH OF A STRING
2. COPY A STRING
3. REVERSE A STRING
4. CONCATINATE TWO STRINGS
5. COMPARE TWO STRINGS
6. EXIT
CASE 1
CASE 3
CASE 4
CASE 5
CASE 6
*/
QUES- WRITE A MENU DRIVEN PROGRAM WHICH CONVERTS VARIOUS DATA FORMS INTO EACH OTHER
//Header Files
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
#include<string.h>
//Start of main
void main()
{
clrscr();
// Declaration of variables
int bin[20],n,i=0,r,j,sum=0,term,num,c,length,k;
char symbol,choice,ch,s1[10];
while(n!=0)
{
r=n%2;
bin[i]=r;
i++;
n=n/2;
}
for(j=i-1;j>=0;j--)
cout<<bin[j];
break;
while(n!=0)
{
r=n%10;
term=r*pow(2,i);
i++;
sum=sum+term;
n=n/10;
}
cout<<"The decimal form is "<<sum;
break;
while(n!=0)
{
r=n%8;
bin[i]=r;
i++;
n=n/8;
}
for(j=i-1;j>=0;j--)
cout<<bin[j];
break;
while(n!=0)
{
r=n%10;
term=r*pow(8,i);
i++;
sum=sum+term;
n=n/10;
}
cout<<"The decimal form is "<<sum;
break;
while(n!=0)
{
r=n%16;
bin[i]=r;
i++;
n=n/16;
}
for(j=i-1;j>=0;j--)
{
num=bin[j];
if(num==10)
cout<<'A';
else if(num==11)
cout<<'B';
else if(num==12)
cout<<'C';
else if(num==13)
cout<<'D';
else if(num==14)
cout<<'E';
else if(num==15)
cout<<'F';
else
cout<<num;
}
break;
for(i=length-1,c=0;i>=0;i--,c++)
{
if(s1[i]=='1')
k=1;
else if(s1[i]=='2')
k=2;
else if(s1[i]=='3')
k=3;
else if(s1[i]=='4')
k=4;
else if(s1[i]=='5')
k=5;
else if(s1[i]=='6')
k=6;
else if(s1[i]=='7')
k=7;
else if(s1[i]=='8')
k=8;
else if(s1[i]=='9')
k=9;
else if(s1[i]=='A'||s1[i]=='a')
k=10;
else if(s1[i]=='B'||s1[i]=='b')
k=11;
else if(s1[i]=='C'||s1[i]=='c')
k=12;
else if(s1[i]=='D'||s1[i]=='d')
k=13;
else if(s1[i]=='E'||s1[i]=='e')
k=14;
else if(s1[i]=='F'||s1[i]=='f')
k=15;
term=k*pow(16,c);
sum=sum+term;
}
cout<<"The decimal form is "<<sum;
break;
//Wrong choice
default: cout<<"Invalid entry\n";
}//End of main
/* OUTPUT
MAIN MENU
1. CONVERT DECIMAL NUMBER INTO BINARY
2. CONVERT BINARY NUMBER INTO DECIMAL
3. CONVERT DECIMAL NUMBER INTO OCTAL
4. CONVERT OCTAL NUMBER INTO DECIMAL
5. CONVERT DECIMAL NUMBER INTO HEXADECIMAL
6. CONVERT HEXADECIMAL NUMBER INTO DECIMAL
7. EXIT
CASE 1
CASE 2
CASE 3
CASE 4
CASE 5
CASE 6
CASE 7
DEFAULT
*/
QUES- WRITE A MENU DRIVEN PROGRAM TO PERFORM THE STRING HANDLING OPERATIONS USING INBUILT
FUNCTIONS
//Header Files
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
//start of main
void main()
{
clrscr();
//Decleration of variables
do
{
//Main menu
cout<<"\t MAIN MENU\n";
cout<<" 1. LENGTH OF A STRING \n";
cout<<" 2. COPY A STRING \n";
cout<<" 3. REVERSE OF A STRING \n";
cout<<" 4. CONCATINATE TWO STRINGS \n";
cout<<" 5. COMPARE TWO STRINGS (WITH CASE) \n";
cout<<" 6. COMPARE TWO STRINGS (WITHOUT CASE) \n";
cout<<" 7. EXIT \n";
switch(symbol)
{
//Finding length of a string
case '1': cout<<"Enter the string \n";
cin>>s1;
length=strlen(s1);
cout<<"The length of the string is "<<length;
break;
//Copying one string into another
case '2': cout<<"Enter the string \n";
cin>>s1;
strcpy(s2,s1);
cout<<"The copied string is "<<s2;
break;
//Wrong choice
default: cout<<"Invalid entry \n";
/* OUTPUT
MAIN MENU
1. LENGTH OF A STRING
2. COPY A STRING
3. REVERSE OF A STRING
4. CONCATINATE TWO STRINGS
5. COMPARE TWO STRINGS (WITH CASE)
6. COMPARE TWO STRINGS (WITHOUT CASE)
7. EXIT
CASE 1
CASE 2
CASE 3
CASE 4
CASE 5
CASE 6
CASE 7
DEFAULT
*/
QUES- WRITE A PROGRAM TO PRINT THE PATTERN
//Header files
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
//Start of main
void main()
{
clrscr();
int i,s,j,n;
cout<<"Enter the number of stars in the pattern : ";
cin>>n;
cout<<endl;
for(i=1,s=n;i<=n;i++,s--)
{
cout<<setw(s)<<"";
for(j=1;j<=i;j++)
cout<<"* ";
cout<<"\n";
}
for(i=n-1,s=2;i>=1;i--,s++)
{
cout<<setw(s)<<"";
for(j=1;j<=i;j++)
cout<<"* ";
cout<<endl;
}
}//End of main
/* OUTPUT
Enter the number of stars in the pattern : 5
*
**
***
****
*****
****
***
**
*
*/