STRUCTURED PROGRAMMING C++ Standard Library

Content 2



C++ standard library



C++ standards streams



C++ namespace



Types of common errors

Objectives 3



By the end you should recognize: 

Ability to use offered C++ codes in appended standard library



Library that provides handling of input / output in programs



Input / output streams (cin , cout, and cerr) and their functionality



Classification of the outcome errors from programs



Important programming skills that you will gain after this

programming course

Standard Library 4



Rich collections of existing code that can be reused in your applications 

Common math calculations e.g. sqrt, pow …etc



String / character manipulations



Date / Time functions



Input / output



Error checking



Provided as part of C++ development environment



You can use their capabilities by referring to the corresponding header file that certain library defined in

iostream Library 5



Part of the C++ Standard Library



Provides a uniform way of handling input from and output to predefined sources



Based on the concept of a "stream "

Streams 6



Pre-connected input and output channels between a computer program and its environment when it begins execution



A stream is an object where a program can either insert or extract

characters to or from it 

Streams are generally associated to a physical source or destination of characters 

a disk file, the keyboard, or the screen

Streams (cont.) 7



Two types 

Input streams are used to hold input from a data producer, such as a keyboard, a file



Output streams are used to hold output for a particular data consumer, such as a monitor, a file, or a printer



Programmer only has to learn how to interact with the streams



Details about how the stream interacts with the actual devices is left up to the environment or operating system

Streams (cont.) 8



Standard Input Stream (cin)



Standard Output Stream (cout)



Standard Error Stream (cerr)

keyboard

cin cout

screen

cerr

program

cin and cout 9



Think of cout as a variable that accepts all data bound for standard output



Think of cin as a variable that accepts all data bound for standard input



The cout and cin declarations and definitions are located in the header file “iostream”



All of the Standard C++ libraries are wrapped in a single

namespace std “standard”

Namespaces 10



A mechanism for logically grouping declarations and definitions into a common declarative region



Problem 

It becomes harder to think of new names for functions and variables when your programs reach a certain size



C++ has a single arena where all the names live



All developers must be careful not to accidentally use the same names to avoid conflict

Namespaces (cont.) 11



Solution 

the namespace keyword



Each set of C++ definitions in a library or program is “wrapped” in a namespace



You can create your own namespace that hold blocks of codes then can be accessed by any code inside or outside the namespace

Common Errors 12



Syntax (compilation) Errors 

encountered during compilation



occurs when an instruction does not follow the syntax rules of the

programming language 



e.g. forgetting a semicolon

Logic (Semantic) Errors 

Not detected during compilation



produces unintended or undesired results 

e.g. forgetting to initialize a sum variable

Common Errors (cont.) 13



Runtime (Execution-time) Errors 

occurs during the execution of a program



May sometimes cause the program to crash 



e.g. division by zero

You must develop 3 skills 

Design



Debug



Trace

Introduction and Basics in

Important programming skills that you will gain after this ... Rich collections of existing code that can be reused in your ... a common declarative region.

217KB Sizes 0 Downloads 98 Views

Recommend Documents

Bayesian Basics: A conceptual introduction with application in R and ...
exploring Bayesian data analysis for themselves, assuming they have the requisite .... of the world, expressed as a mathematical model (such as the linear ..... such as N and K, can then be used subsequently, as we did to specify dimensions. From the

Bayesian Basics: A conceptual introduction with application in R and ...
CENTER FOR STATISTICAL CONSULTATION AND RESEARCH. UNIVERSITY OF MICHIGAN. BAYESIAN ... exploring Bayesian data analysis for themselves, assuming they have the requisite context to begin with. ..... and for the next blocks, we declare the type and dim

FREE [P.D.F] Blockchain Basics: A Non-Technical Introduction in 25 ...
Online PDF Blockchain Basics: A Non-Technical Introduction in 25 Steps, Read PDF .... No mathematical formulas, program code, or computer science jargon.

[PDF BOOK] Blockchain Basics: A Non-Technical Introduction in 25 ...
... Blockchain Basics: A Non-Technical. Introduction in 25 Steps - Full Online ... The Internet of Money: A collection of talks by Andreas M. Antonopoulos: Volume 1.

pdf-1447\introduction-to-networking-basics-2nd-second-edition.pdf ...
pdf-1447\introduction-to-networking-basics-2nd-second-edition.pdf. pdf-1447\introduction-to-networking-basics-2nd-second-edition.pdf. Open. Extract.

BASICS IN TOURISM Tourism concepts-definitions-historical ...
resources-Fairsand Festivals-Dance forms and Music-Art and Architecture and ... 21​st​ Century-Technology and Social Media:Using Social Media,Tools and.

Introduction to the PIC32 - The Basics, Getting Started, IO ports and ...
Introduction to the PIC32 - The Basics, Getting Started, IO ports and the First Program.pdf. Introduction to the PIC32 - The Basics, Getting Started, IO ports and the ...

THE BASICS OF ASTHMA, ALLERGIES AND ANAPHYLAXIS
Apr 12, 2016 - online to www.anaphylaxis.ca​. Anaphylaxis Canada is a national non-profit ... Canada, the Lung Association, and the Public Health School ...

Applied Math and Machine Learning Basics - GitHub
reality and using a training algorithm to minimize that cost function. This elementary framework is the basis for a broad variety of machine learning algorithms ...