BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Object Oriented Programming (http://bzupages.com/300-object-oriented-programming/)
-   -   Program to enter a letter and output the next 2 letters (http://bzupages.com/f300/program-enter-letter-output-next-2-letters-14664/)

bonfire 09-03-2011 12:13 AM

Program to enter a letter and output the next 2 letters
 
1 Attachment(s)
Program to enter a letter and output the next 2 letters


#include
#include

void main()
{
clrscr();
char charac;
cout << "Enter your letter : " << endl;
cin>>charac;
cout << "The 2 letters are : " << endl;
cout << (char)(charac-1) << endl;
cout << (char)(charac+1) << endl;
getch();
}
This program takes in a letter charac of the English alphabet as a screen input from the user.
It then determines its previous letter and next letter and prints it out using the 'cout' command.



Sample Input
x
Sample Output
The next 2 letters after x are :
y
z

abdkhan 10-03-2011 12:56 AM

Re: Program to enter a letter and output the next 2 letters
 
But a good programmer will consider A-z & a-z as characters for a sequence.

The code above will give "[" after Z and '{' after z ,although its a character but it dosnt make any sense .


#include
#include

void main()
{
{



clrscr(); //This clrscr produces wastege in systems performance
char charac;
cout << "Enter your char : " << endl;
cin>>charac;



cout << "The 2 letters are : " << endl;

if (((char)(charac) <=90 && (char)(charac) >= 66 ) | (char)(charac) <=122 && (char)(charac) >= 98 )// this line can simply be replaced by if (charc != 'a' | charc!='A')
cout << (char)(charac-1) << endl;
else
cout << "There is no char Before "<<(char)(charac)<< endl;



if ((char)(charac) <=89 && (char)(charac) >= 65 | (char)(charac) <=121 && (char)(charac) >= 97 )
cout << (char)(charac+1) << endl;
else
cout << "There is no char After"<<(char)(charac)<< endl;

getch();

}//end main function
}

bonfire 10-03-2011 02:17 AM

Re: Program to enter a letter and output the next 2 letters
 
Bahi jaan 1 program banay kay kafi ways hotay hain, yahain simple post kia hai. complex program k liyai acha programmer bhi chayai. and u can see that yeh 1st semester k liyai ha. Thanks for reply

abdkhan 10-03-2011 12:25 PM

Re: Program to enter a letter and output the next 2 letters
 
ur right, that wa meant for information..After all one has to cover all aspects :D


All times are GMT +5. The time now is 08:00 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.