C++ Standard Library And Expressions

Standard library contains files storing standard functions(I/O functions, mathematical functions, string functions, character functions etc.). These are some files known as header files.
The C ++ standard library contains a lot of header files. The file usually has an .h extension. These header files contain a set of functions, which are grouped together based on their functionality. They perform depending on the nature of the operation.

Header File Description
stdio.h The file defines types and macros that are needed for I/O packages.
string.h The file declares various string manipulation and memory mainpulation.
math.h The file declares various math function and math error handlers.
stdlib.h The file declares several commonly used routines like conversion routines, search routines etc.
iostream.h The file declares basic c++ stream I/O routines.
iomanip.h The file declares basic c++ stream I/O manipulators and contains macros for creating parameter manipulator.


We can add header files in the program by using the extension :
Syntax :#include<header file>
Example :#include<iostream.h>

Expressions

The expression in C++ is combination of tokens.

Arithmetic Expression :

There are two types of arithmetic expression pure integer expression and pure real expression. Mixed expressions are also commonly used, which is a mixture of both pure integer expressions and pure real expressions.

Pure Integer Expression :

This type of expression when an integer is formed by a combination of integer constant or integer variables using integer arithmetic operators.

The following are valid pure integer expression :

Example :
const count = 30;
int I,J,K,L,M;

Pure Real Expression :

This type of expression when an integer is formed by a combination of real constant or real variables using real arithmetic operators.

The following are valid pure real expression :

Example :
const bal = 200.53;
float num, value;
double fout, count;

Exercise:-

1. Which header file is used during math function and math error handlers?

A. string.h
B. math.h
C. iostream.h
D. conio.h

View Answer


2. Which of the following keyword is used to include the header file?

A. include
B. exclude
C. string
D. namespace

View Answer



Program :-

Write a program to read coordinates of two points and calculate the distance between them.

#include <bits/stdc++.h> 
using namespace std; 
// This will calculate distance 
float distance(int a, int b, int c, int d) 
{ 
// Logic to Calculating distance 
return sqrt(pow(c - a, 2) +  
pow(d - b, 2) * 1.0); 
} 
// Main Code 
int main() 
{ 
cout << distance(5, 6, 6, 5); 
return 0; 
} 


Output :

1.41421



Visit :


Discussion



* You must be logged in to add comment.