C++ Programming Code Examples
C++ > Beginners Lab Assignments Code Examples
C++ Program to Find ASCII Value of a Character
/* C++ Program to Find ASCII Value of a Character
Full form of Ascii is American Standard Code for Information Interchange. Ascii is a character-encoding scheme. Originally based on the English alphabet, every character or number have its own Ascii value for example Ascii value of a is 97.
Find Ascii Value of Number Using Library Function */
#include<iostream.h>
#include<ctype.h>
#include<conio.h>
int main(void)
{
int number, result;
clrscr();
cout<<"Enter any Character/Symbol/Digits: ";
number = getch();
result = toascii(number);
cout<<"Ascii value: "<<result;
getch();
}
#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.
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.
Convert integer value to 7-bit ASCII character. The toascii() function returns the 7-bit ASCII character corresponding to the argument passed. toascii() converts c to a 7-bit unsigned char value that fits into the ASCII character set, by clearing the high-order bits. The toascii() function determines to what character c would be mapped to in a 7-bit US-ASCII locale and returns the corresponding character encoding in the current locale.
As the name already suggests, these operators help in assigning values to variables. These operators help us in allocating a particular value to the operands. The main simple assignment operator is '='. We have to be sure that both the left and right sides of the operator must have the same data type. We have different levels of operators. Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C 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.
The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program. The getch() function does not accept any parameter from the user. It returns the ASCII value of the key pressed by the user as an input.
It is a predefined function in "conio.h" (console input output header file) used to clear the console screen. It is a predefined function, by using this function we can clear the data from console (Monitor). Using of clrscr() is always optional but it should be place after variable or function declaration only. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.
"Change the Value" of the item stored in the pairing heap. Does nothing if newVal is larger than currently stored value. p points to node returned by insert. "newVal" is the new value
In this c++ program, user enter two numbers ('floating point numbers'). Then, the product of those two numbers is 'stored' in a variable and displayed on the screen. The 2 numbers
To check that the original number is equal to its reverse or not in C++, enter the number & reverse that number then check that reverse is equal to "original or not", before reversing
Class for addition, subtraction, multiplication and division for 'complex numbers'. Class has 4 functions to perform arithmetic operations. It takes 2 "complex numbers" input from user