Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes
CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ > Strings Code Examples

check the entered character is capital letter, small letter, digit or a special character

/* check the entered character is capital letter, small letter, digit or a special character C++ program which takes input a character and check it whether entered character is capital letter, small letter, Digit or Special character All characters like small letters, capital letters, digits or special character have ASCII codes when a key is pressed from keyboard there is always an ASCII value behind it like if small letter 'a' is pressed its ASCII is 97 if capital letter 'A' is pressed its ASCII value is 65 if a number digit '0' is pressed its ASCII value is 48. ASCII value ranges 0 - 9 48 - 57 A - Z 65 - 90 a - z 97 - 122 Special Characters 0-47, 58-64, 91-96, 123-127 On the basis of ASCII values and using operators like and operator (&&) or Operator (||) we can differentiate the letters. */ #include<iostream> using namespace std; int main() { char character; cout<<"Enter a character = "; cin>>character; int storeAscii=character; cout<<"The ASCII value of "<<character<< " is "<<storeAscii; if (storeAscii>=65 && storeAscii<=90) { cout<<"\nYou have entered a capital letter"; } else if (storeAscii>=97 && storeAscii<=122) { cout<<"\nYou have entered a small letter"; } else if (storeAscii>=47 && storeAscii<=57) { cout<<"\nYou have entered a digit "; } else if (storeAscii>=0 && storeAscii>=47 || storeAscii>=54 && storeAscii<=64 || storeAscii>=91 && storeAscii<=96 || storeAscii>=123 && storeAscii<=127) { cout<<"\nYou have entered a special character"; } return 0; }
#include Directive in C++ Programming Language
#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.
If Else Statement in C++ Programming Language
In computer programming, we use the if statement to run a block code only when a certain condition is met. An if statement can be followed by an optional else statement, which executes when the boolean expression is false. There are three forms of if...else statements in C++: • if statement, • if...else statement, • if...else if...else statement, The if statement evaluates the condition inside the parentheses ( ). If the condition evaluates to true, the code inside the body of if is executed. If the condition evaluates to false, the code inside the body of if is skipped.
Namespaces in C++ Programming Language
Consider a situation, when we have two persons with the same name, jhon, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother's or father's name, etc. Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function you are referring to within your code.
main() Function in C++ Programming Language
A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.
Standard Output Stream (cout) in C++ Programming Language
The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.
If Else If Ladder in C++ Programming Language
The if...else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities. The if...else ladder allows you to check between multiple test expressions and execute different statements. In C/C++ if-else-if ladder helps user decide from among multiple options. The C/C++ if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the C else-if ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.
Standard Input Stream (cin) in C++ Programming Language
The cin object is used to accept input from the standard input device i.e. keyboard. It is defined in the iostream header file. C++ cin statement is the instance of the class istream and is used to read input from the standard input device which is usually a keyboard. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard. The "c" in cin refers to "character" and "in" means "input". Hence cin means "character input". The cin object is used along with the extraction operator >> in order to receive a stream of characters.
Strings in C++ Programming Language
Strings are objects that represent sequences of characters. The standard string class provides support for such objects with an interface similar to that of a standard container of bytes, but adding features specifically designed to operate with strings of single-byte characters. The string class is an instantiation of the basic_string class template that uses char (i.e., bytes) as its character type, with its default char_traits and allocator types. Note that this class handles bytes independently of the encoding used: If used to handle sequences of multi-byte or variable-length characters (such as UTF-8), all members of this class (such as length or size), as well as its iterators, will still operate in terms of bytes (not actual encoded characters).
Logical Operators in C++ Programming Language
Logical Operators are used to compare and connect two or more expressions or variables, such that the value of the expression is completely dependent on the original expression or value or variable. We use logical operators to check whether an expression is true or false. If the expression is true, it returns 1 whereas if the expression is false, it returns 0. Assume variable A holds 1 and variable B holds 0:
If you don't have a vector type
A Templated Stack Data Structure sample
Using Templates so that any type of data can be stored in stack without multiple defination of class. Contains "Location of Topmost data" pushed onto stack. Sets the top location to -1
Variable Declaration and Operating Variables in C++
C++ Basic Operation Addition Subtraction
"Addition(+)" of 2 vectors. "Subtraction(-)" of 2 vectors. "Multiplication" of vector with the scalar. "Cross" product of 2 vectors. Scalar(or dot) product of 2 vectors. Negative of vectors
Program to Find number of Digits from any number
Deque operatorlt - Returns true if d1 is lexicographically less than d2
C++ Language Header File For Linked List
Return true if "empty"; else false. Remove all items. Return position to prior to first. Return "first position". Insert x after "current iterator" position p. Return position that views. ListItr
Programs to print inverted half pyramid using * and numbers
Using atoi: convert string to int
Create the intersection of list1 and list2
Program to open a file whose name is passed as command line argument
A C++ Program to Multiply two Matrices. Divide And Conquer Algorithm