C++ standard functions

C++ Functions

C++ Standard Functions

C++ language is shipped with a lot of functions which are known as standard functions
These standard functions are groups in different libraries which can be included in the C++ program, e.g.
Math functions are declared in library
Character-manipulation functions are declared in library
C++ is shipped with more than 100 standard libraries, some of them are very popular such as and , others are very specific to certain hardware platform, e.g. and

Example of Using Standard C++ Math Functions
#include
#include void main()
{
// Getting a double value
double x;
cout << « Please enter a real number: « ; cin >> x;
// Compute the ceiling and the floor of the real number
cout << « The ceil( » << x << « ) =  » << ceil(x) << endl;
cout << « The floor( » << x << « ) =  » << floor(x) << endl;
}

Example of Using Standard C++ Character Functions
#include // input/output handling
#include // character type functions
void main()
{
char ch;
cout << « Enter a character: « ; cin >> ch;
cout << « The toupper( » << ch << « ) =  » << (char) toupper(ch) << endl;
cout << « The tolower( » << ch << « ) =  » << (char) tolower(ch) << endl;
if (isdigit(ch))
cout << « ‘ » << ch <<« ‘ is a digit!\n »;
else
cout << « ‘ » << ch <<« ‘ is NOT a digit!\n »;
}

User-Defined C++ Functions
Although C++ is shipped with a lot of standard functions, these functions are not enough for all users, therefore, C++ provides its users with a way to define their own functions (or user-defined function)
For example, the library does not include a standard function that allows users to round a real number to the ith digits, therefore, we must declare and implement this function ourselves

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *