C++ program to find capital of a country entered using structure

C++ program to find capital of a country entered using structure
Just copy this program in a notepad and save it as .cpp file now install any C++ environment the most common one is Turbo C++ install it in your windows drive. After installation go to the windows drive and search for a software as turbo c++ now open the folder you can see multiple file on it click on the file named as BIN now save the notepad file first saved in it now open the software and go to files and click on Files-Open a separate menu gets opened now select the file saved open it now press ctrl+f9 press enter the press alt+f9 you can see the program to get opened.
  This program basically takes input of a country and its capital name then give you an option to search capital for a particular country.

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct world
{
char country[30];
char capital[30];
};
void main()
{
clrscr();
world w[10];
int i=0,n;
cout<<"Enter no. of records (<=10): ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the country: ";
gets(w[i].country);
cout<<"Enter the capital: ";
gets(w[i].capital);

}
char ch,*cont;
int flag;

cout<<"\n\t1.Search for capital\n\t2.List all Records\n\t3.Exit";
cin>>ch;
do
{
if(ch=='1')
{
cout<<"\nEnter the country : ";
gets(cont);
flag=0;
for(i=0;i<n;i++)
{
if(strcmp(cont,w[i].country)==0)
{
cout<<"\n capital is: "<<w[i].capital;
flag=1;
break;
}
}
if(flag==0)
cout<<"\ncountry not found";
}
if(ch=='2')
{
cout<<"\nCOUNTRY\t\tCAPITAL";
cout<<"\n-------\t\t-------";
for(i=0;i<n;i++)
cout<<"\n"<<(w[i].country)<<"\t\t"<<(w[i].capital);

}


cout<<"\n\t1.Search for capital\n\t2.List all Records\n\t3.Exit";
cin>>ch;

}while(ch!='3');

getch();
}
For any kind of queries please feel free to comment.

C++ program to compare two strings using a function

C++ program to compare two strings using a function
It is program that will take entry of tho sentences as per user's entry using different function the two sentences are first merged then they are displayed with an another fuction.




#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void findlength()
{
char str[30];
int l=0;
cout<<"\n Enter the string (n<=30) ";
gets(str);
while(str[l]!='\0')
{
l++;
}
cout<<"\n Length Of the given String is: "<<l<<endl;
}
void compare()
{
char str1[30], str2[30];
int i=0,j=0,i=0,flag=0;
cout<<"\n Enter the string1 (n<=30) ";
gets(str1);
while(str1[i]!='\0')
{
i++;
}
cout<<"\n Enter the string2 (n<=30) ";
gets(str2);
while(str2[j]!='\0')
{
j++;
}
if(j!=i)
{
cout<<"\n Strings are not Equal ";
}
else
{
for(i=0;i<i;i++)
{
   if(str1[i]!=str2[i])
   {
flag=1;
break;
   }
}
if(flag==1)
{

cout<<"\n Strings are not Equal ";
}
else
{
cout<<"\n Strings are Equal ";
}
}


}

void concat()
{
char str1[30], str2[30];
int i=0,j=0,i=0,flag=0;
cout<<"\n Enter the string1 (n<=30) ";
gets(str1);
while(str1[i]!='\0')
{
i++;
}
cout<<"\n Enter the string2 (n<=30) ";
gets(str2);
while(str2[j]!='\0')
{
j++;
}
for(i=0;i<j;i++)
{
str1[i+i]=str2[i];
}
str1[i+j]='\0';
cout<<"\n The concatenated String is: ";
puts(str1);

}


void main()
{
clrscr();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
char ch;
cin>>ch;
do
{
if(ch=='1')
findlength();
if(ch=='2')
compare();
if(ch=='3')
concat();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
cin>>ch;

}while(ch!='4');
getch();
}