0% found this document useful (0 votes)
20 views

Library Header

The document discusses various C++ concepts including functions, libraries, header files, and namespaces. It provides examples of common C++ header files like iostream, string, windows.h, and what libraries they belong to. It also compares source code to object code, and high-level languages to low-level languages. Finally, it summarizes key points about functions, libraries, and namespaces.

Uploaded by

Aimee O.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Library Header

The document discusses various C++ concepts including functions, libraries, header files, and namespaces. It provides examples of common C++ header files like iostream, string, windows.h, and what libraries they belong to. It also compares source code to object code, and high-level languages to low-level languages. Finally, it summarizes key points about functions, libraries, and namespaces.

Uploaded by

Aimee O.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

C++ Program

• Standard Function Library


• Library Header files
Review
What is the Difference of Source
code from Object Code?

What is the Difference of High Level


Language from Low Level language?
Return Type Function Name Parameter List
A console
traditionally refers to
a computer terminal
where a user may
input commands and
view output such as
the results of
inputted commands
or status messages
Function from the computer.
Body

Header
A function is a block of organized, reusable code that is used to
perform a single, related action.
A function definition in C programming consists of a function header and a function body. Here
are all the parts of a function −
Return Type − A function may return a value. The return type is the data type of the value the
function returns. Some functions perform the desired operations without returning a value. In
this case, the return type is the keyword void.

Function Name − This is the actual name of the function. The function name and the
parameter list together constitute the function signature.

Parameter List − A parameter is like a placeholder. When a function is invoked, you pass a
value as a parameter. This value is referred to as the actual parameter or argument. The
parameter list refers to the type, order, and number of the parameters of a function.
Parameters are optional; that is, a function may contain no parameters.

Function Body − The function body contains a collection of statements that defines what the
function does.
The Standard Function Library in C++ is what keeps you
from having to rewrite even the simplest of programming
instructions. It is like a huge library of sub-libraries, each of
which contains the underlying code for several functions. In
order to make use of these libraries, you link to each library
in the broader library through the use of header files.

Here's another way to think of this. When you import the


input/output library, you are actually taking down a copy of
all of the code within that library. This is what lets you use
those functions that reside in the library. But the beauty of
this setup is that you don't see any of that underlying code.
You don't need to.
Standard c++ Library - Header files – Containing functions

Library file - <iosteam> - cin >> and cout <<


C++ comes with libraries that provide us with many ways for performing input
and output. In C++ input and output are performed in the form of a sequence of
bytes or more commonly known as streams.

Input Stream: If the direction of flow of bytes is from the device(for example,
Keyboard) to the main memory then this process is called input.

Output Stream: If the direction of flow of bytes is opposite, i.e. from main
memory to device( display screen ) then this process is called output.
Sr. No. Key Header file Library

1 Definition Header File is On other hand


the file where all Library is the file
the headers where the
name are implementation
mentioned that code of each
going to be header is
used or written down
consumed in which is
the main code mentioned in
file. the Header file.

Many common or standard functions, whose definitions have


already been written, are ready to be used in any program. They
are organized into a group of functions (think of them as several
books) and are collectively called a standard library.
Naming conventions for header files in C and C++
A naming convention is a convention (generally agreed scheme)
for naming things.

1.Standard C Library
• There are 19 header files in the Standard C Library. All files have the .h file extension.
Examples: #include <stdio.h>
                 #include <string.h>

2.Standard C++ Library


• There are a total of 49 header files in the Standard C++ Library. This includes
equivalents of the 19 Standard C Library header files. All of the equivalent C header
files have a ‘c’ prepended to the name and have no .h file extension.
Examples: #include <cstdio>
                 #include <cstring>

• Includes 30 additional header files (49 total) that are exclusive to C++
#include <windows.h>
header file is used to access the Win32 API (API stands for
Application Programming Interface) functions and it makes it
easier for the user to use the in-built functionality.

- Win32 executable is used in the source code if the


inbuilt functions are used or included in the main file.

- The header file in particular includes the library and


functions used in the libraries like stdio.h or stdlib.h.
<ncurses> - is a library that helps you manage interactions with
the underlying terminal environment. But it doesn't provide a terminal
emulator itself.

The thing that actually displays stuff on the screen (which in your
requirement is listed as "native resizable win32 windows") is usually
called a Terminal Emulator. If you don't like the one that comes with
Windows there are a few alternatives. 
Terminal emulation is the ability to make one computer 
terminal, typically a PC, appear to look like another,
usually older type of terminal so that a user can access
programs originally written to communicate with the
other terminal type. Terminal emulation is often used to
give PC users the ability to log on and get direct access
to legacy programs in a mainframe operating system. 
The word "terminal" comes from early computer
systems that were used to send commands to other
computers. Terminals often consist of just a keyboard and
monitor, with a connection to another computer. The
purpose of a terminal is not to process information (like a
typical computer), but to send commands to another
system. For example, a network administrator may use a
terminal to log in to a network and manage devices
connected to the network.
With modern computers, the word "terminal"
usually refers to a terminal program, or emulator,
which provides a text-based interface for typing
commands. This type of program is often
abbreviated "TTY" and may also be referred to as
a command-line interface.
The <unistd.h> header defines miscellaneous symbolic
constants and types, and declares miscellaneous
functions. unistd stands for "Unix standard"

<stdio.h>
The header file stdio.h stands for Standard Input Output. It has
the information related to input/output functions.

getc()- getch() //function


It reads the character from the file.
<stdlib.h>
The header file stdlib.h stands for Standard Library. It has the
information of memory allocation/freeing functions.

rand() //function
It returns a random integer value

Thread is a sequence of instructions that can be executed


concurrently with other such sequences in multithreading
environments, while sharing a same address space.
This header file contains definitions of functions to get
and manipulate date and time information.

Functions Conversion

Time manipulation asctime


clock Convert tm structure to string (function )
Clock program (function )
ctime
difftime Convert time_t value to string (function )
Return difference between two
times (function ) gmtime
mktime Convert time_t to tm as UTC time (function )
Convert tm structure to
time_t (function ) localtime
Convert time_t to tm as local time (function )
time
Get current time (function ) strftime
Format time as string (function )
#include <conio.h>

kbhit() –(Keyboardhit)
is present in conio.h and used to determine if a key has been pressed
or not.

Getch() - (Getcharacter)
It will tell to the console wait for some time until a key is hit given after running of
program. By using this function we can read a character directly from the keyboard.
Generally getch() are placing at end of the program after printing the output on
screen.
srand
void srand (unsigned int seed);
Initialize random number generator
The pseudo-random number generator is initialized using the argument passed
as seed.

For every different seed value used in a call to srand, the pseudo-random number


generator can be expected to generate a different succession of results in the
subsequent calls to rand.

rand
i
Generate random number

This number is generated by an algorithm that returns a sequence of apparently


non-related numbers each time it is called. This algorithm uses a seed to generate
the series of numbers, which should be initialized to some distinctive value using
function srand.
Namespaces
Namespaces allow to group entities like classes, objects and
functions under a name. This way the global scope can be divided in
"sub-scopes", each one with its own name.

Namespaces were introduced into C++ to resolve identifier name


conflicts. This ensured that two objects can have the same name
and yet be treated differently if they belonged to different
namespaces.
What is Cout?
It is used in C++. It is an object under <iostream>. It is also used to print user-
defined data on-to an output screen. Cout does not need format specifiers.
Moreover, it does not return any value. Also, the input parameters in cout are
type-safe.

What is printf() - printw() : Print formatted output similar to printf()

This is mainly used in C language. It is a formatting function that prints to the


standard out. It prints to the console and takes a format specifier to print. It returns
an integer value. It is not type safe in input parameters. It can be used in C++
language too. it is a function under <stdio.h> and it is declared under <stdio.h>. 

In a type-safe language, the language’s type system is a particular way of


ensuring that only the “right” (non-wrong) programs go through. In
particular, we say a program (or program phase) is well typed if the type
system deems it acceptable, and type safety ensures that well typed
programs never go wrong: they will have a (well defined) meaning. 
Switch case statement is used when we
have multiple conditions and we
need to perform different action based on the
condition.

Why we use a getch() function?

We use a getch() function in a C/ C++ program to hold the output


screen for some time until the user passes a key from the keyboard
to exit the console screen. Using getch() function, we can hide the
input character provided by the users in the ATM PIN, password,
etc.
  DESCRIPTION

The external variable stdscr specifies the default


window used by functions that do not specify a
window using an argument of type WINDOW *. 
The very first thing to do: Before you use any
other curses routines, the initscr() routine must be called first.

initscr(); - screen initialisation functions

The initscr() function determines the terminal type and


initializes all implementation data structures.

No echo. To suppress the automatic echoing of typed characters, you


need to call noecho();
The scrollok option controls

What happens when the cursor of a window is moved off the edge
of the window or scrolling region, either as a result of a newline action
on the bottom line, or typing the last character of the last line?

If disabled, (bf is FALSE), the cursor is left on the bottom line. If


enabled, (bf is TRUE), the window is scrolled up one line.
napms()
Sleep for a given number of milliseconds.
1000ms = 1sec

Description:
The napms() routine delays the calling process
for ms milliseconds. This function is similar to delay() and nap().
NAME
endwin(); - suspend Curses session
 

 DESCRIPTION
The endwin() function restores the terminal after Curses activity
by at least restoring the saved shell terminal mode, flushing any
output to the terminal and moving the cursor to the first column
of the last line of the screen. Refreshing a window resumes
program mode.

You might also like