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

Programming: Logic and Design

Uploaded by

penafloridajhon3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Programming: Logic and Design

Uploaded by

penafloridajhon3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

FUNDAMENTALS OF C++

PROGRAMMING
LOGIC AND
DESIGN
JHON ERI C PE Ñ AFL ORI DA | CEI T 0 3 1 0 3 A
HISTORY OF C++
THE C++ PR OG RAMI N G LA NGUA GE I S O NE O F TH E
MOS T POPUL AR PROG RA M M I NG LA NGUA GES O U T
THERE, WHI C H H AS BE EN I N US E FO R O V ER FO U R
DECADES N OW. BUT DO Y O U K NO W A BO UT TH E
HI S TORY OF C + + AN D I TS TI M ELI NE?
DEV C++
C+ + WAS DE VE L OPE D BY BJ A RNE S TRO US TRUP W H I L E
WOR KI NG O N H I S PH . D. THES I S A T BELL LA BS I N 1979. H E
WAN TED TO C RE ATE A DY NA M I C LA NGUA GE T H AT
WOULD ALL OW PROG RA M M ERS TO BUI LD COM P L EX
S YS TEMS WI TH H I G H - LEV EL A BS TRA CTI O NS W H I L E STI L L
PR OVI DI NG L OW- L E VE L A CCES S TO THE HA RD W AR E.

TO GET THI S DON E , H E EX TENDED THE C L ANGUAG E TO


I NCLUDE FE ATURE S S U CH A S CLA S S ES , I NHER I TAN CE,
ABS TRACTI O N , AN D PO LY M O RP HI S M TO M A KE I T EASI ER
TO WRI TE E FFI C I E N T, M O DULA R, A ND REUS A B L E CO D E.

I N 1 983, THE FI RS T VE R S I O N O F C+ + WA S REL EASED TO


THE PUBLI C . AT TH I S POI NT, RI CK M A S CI TTI AL SO
MODI F I ED TH E L AN G UAGE NA M E FRO M ' C WI T H CL ASSES'
TO ' C++' . I T I S I N TE RE S TI NG TO NO TE THA T THE ' ++' I N
THE N AME RE PRE S E N TS THE A S S O CI A TE O P ER ATO R /
I NCREMENT OPE RATOR WHI CH WA S M I S S I NG I N C.
C++
[ I n 1 985, t he f i r st e d i t i o n o f ' T he C+ + Pro gra mmi n g
L a n g ua g e' wa s p ub li s he d , whi ch b e ca me the de f i n i t i v e
g ui de t o t he la n g ua g e a n d he lp e d to e sta b li sh C+ + a s a
ma i nst r ea m p r o g r a mmi n g la n gua ge . S i n ce the n , ther e
ha v e b een s ev e r a l ma j o r re l e a se s a n d sta n da rds o f t h e
l a n g ua g e.

[ I n 1 998, C++ 9 8 , t he f i r st i n te rn a ti o n a l sta n da rdi z e d


v e r s i o n of C+ + , wa s r e l e a s e d. I t i n clude d a ddi ti o n a l
l i b r a r i e s a nd v a r i o us n e w f e a ture s such a s
t e mpl a t es, ex ce p t i o n s, a nd n a me sp a ce s.

[ I n 2 011, a mo r e a d v a n ce d v e rs i o n o f the l a n gua ge w a s


r e l e a s ed, i . e. C + + 1 1 whi c h i n tro duce d s e v e ra l
i mp or t a nt f ea t ur e s such a s re gul a r e xp re s si o n s , R e ge x
s up por t , mov e s e ma n t i cs , ra n ge - b a se d f o r l o o p s,
l a mbda expr es si o n s , st a n d a rd thre a di n g l i b ra ry,
cus t oma r y t hr e a d i n g l i b r a ry, ti me li b ra ry, e tc. T hi s w a s
f ol l owed by C + + 1 4 , C + + 1 7 , a n d mo st re ce n tl y, C+ +20.
C++
MECHANICS

SUPPOSE YOU' VE WRI TTEN A C++ PROGRAM. HOW DO YOU GET I T RUNNI NG? THE EXACT
STEPS DEPEND UPON YOUR COMPUTER ENVI RONMENT AND THE PARTI CULAR C++ COMPI LER
YOU USE, BUT THEY WI LL RESEMBLE THE FOLLOWI NG STEPS

Compile the source code. This means


Use a text editor of some Link the object code with
running a program that translates the
sort to write the program additional code. C++
source code to the internal language,
and save it in a file. This programs, for example,
called machine language, used by the
file constitutes the source normally use libraries. A
host computer. The file containing
codefor your program. C++ library contains
the translated program is the object
code for your program.
BASIC C++ PROGRAMS

COMPI LE EXECUTE

%%bash %%bash

g++ hello01.cpp -o hello01 ./hello01


Hello, world!

C EQUI VALEN T
%%file hello01.c

#include <stdio.h>int main() {printf("Hello,


wolrd!\n");}

Overwriting hello01.c
C++ IS A GENERAL-PURPOSE PROGRAMMING C++
LANGUAGE AND IS WIDELY USED NOWADAYS FOR
COMPETITIVE PROGRAMMING. IT HAS IMPERATIVE,
ENVIRONMENT
OBJECT-ORIENTED, AND GENERIC PROGRAMMING
FEATURES.

C++ runs on lots of platforms like Windows, Linux,


Unix, Mac, etc. Before we start programming with
C++. We will need an environment to be set up on
our local computer to compile and run our C++
programs successfully. If you do not want to set up a
local environment you can also use online IDEs for
compiling your program.
SETTING UP C++ ENVIRONMENT
C+ + COMPI LER

On c e y ou ha v e i n s t a lle d t he te xt e di to r a n d sa v e d y o u r p r o gr a m i n a f i l e w i t h t h e
‘ . cpp’ ext ensi o n , yo u wi ll n e e d a C+ + co mp i le r to co mp i l e t h i s f i l e . A c o mp i le r i s a
comput er pr og r a m t ha t co n v e rts hi gh- le v e l la n gua g e i nt o ma c h i ne - u nd e r st a nd a b le
l ow- l e v el l a n g ua g e . I n o t h e r wo rds, we ca n sa y tha t i t c o nv e r t s t h e so u r c e c o d e
wr i t t en i n a p r o g r a mmi n g la n gua ge i n to a n o the r co mp u t e r l a ngu a ge t h a t t h e
comput er und e r s t a n d s . F o r co mp i li n g a C+ + p ro gra m w e w i ll ne e d a C++ c o mp i le r
t ha t wi ll conv e r t t he so urce co de wri tte n i n C+ + i n t o ma c h i ne c o d e s.
SETTING UP C++ ENVIRONMENT
TEX T EDI TOR

Te x t Edi t or s a r e t he t yp e o f p ro gra ms use d to e di t o r w r i t e t e x t s. We w i l l u se t e x t


e di t or s t o t ype o ur C + + pro gra ms. T he n o rma l e xte nsi o n o f a t e x t f i l e i s (.t x t ) b u t a
t e x t f i l e cont a i n i n g a C + + p ro gra m sho ul d b e sa v e d w i t h a ‘ .c p p ’ o r ‘ .c ’ e x t e nsi o n.
F i l e s e ndi ng wi t h t he e xt e n s i o n ‘ .CPP’ a n d ‘ .C’ a re c a l le d so u r c e c o d e f i l e s a nd t h e y
a r e s uppos ed t o co n t a i n s o urce co de wri tte n i n C+ + p r o gr a mmi ng l a ngu a ge . Th e se
e x t e nsi on he lp s t he co mp i le r to i de n ti f y tha t the f i le c o nt a i ns a C++ p r o gr a m.
Be f or e beg i nn i n g p r o g r a m mi n g wi th C+ + , o n e must h a v e a t e x t e d i t o r i nst a l l e d t o
wr i t e p r og r a ms . F o ll o w t h e b e lo w i n structi o n s to i n st a ll p o p u la r c o d e e d i t o r s l i ke V S
Code a nd Cod e : : Blo ck o n di f f e re n t O p e ra ti n g S yste ms li ke w i nd o w s, Ma c OS, e t c .
CREATING C++

[ To create a C++ project in Visual Studio

From the main menu, choose File > New > Project to
open the Create a New Project dialog box.
At the top of the dialog, set Language to C++ , set
Platform to Windows , and set Project type to Console .
From the filtered list of project types, choose Console
App then choose Next . In the next page, enter a name
for the project, and specify the project location if
desired.
Choose the Create button to create the project.

[ Add a new source file

If Solution Explorer isn't displayed, on the View menu,


click Solution Explorer.
Add a new source file to the project, as follows.
1 . In Solution Explorer, right-click the Source Files
folder, point to Add, and then click New Item.
2 . In the Code node, click C++ File (.cpp), type a
name for the file, and then click Add.

The .cpp file appears in the Source Files folder in


Solution Explorer, and the file is opened in the Visual
Studio editor.

In the file in the editor, type a valid C++


[ program that uses the C++ Standard Library,
or copy one of the sample programs and paste
it in the file.
Save the file.
On the Build menu, click Build Solution.
The Output window displays information
about the compilation progress, for example,
the location of the build log and a message
that indicates the build status.
On the Debug menu, click Start without
Debugging.
If you used the sample program, a command
window is displayed and shows whether
certain integers are found in the set.
WHAT ARE THE RULES TO
DECLARE VARIABLES IN
C++?

VARI ABLE NAMES I N C++ CAN RANGE FROM


1 TO 255 CHARACTERS.
ALL VARI ABLE NAMES MUST BEGI N WI TH A
LETTER OF THE ALPHABET OR AN
UNDERSCORE( _) .
AFTER THE FI RST I NI TI AL LETTER, VARI ABLE
NAMES CAN ALSO CONTAI N LETTERS AND T O DECL ARE A VARI ABL E , Y O U N E E D T O KN O W
NUMBERS. WHAT DATA TYP E I T I S GO I N G T O B E O F AN D
VARI ABLE NAMES ARE CASE SENSI TI VE. WHAT I TS NAM E WO UL D B E . T H E VAR I AB L E
NO SPACES OR SPECI AL CHARACTERS ARE NAME HAS CO NS TRAI NTS O N W H AT Y O U CAN
ALLOWED. NAME I T. FO L L O WI NG AR E T H E R U L E S F O R
YOU CANNOT USE A C++ KEYWORD ( A NAMI N G VAR I ABL ES −
RESERVED WORD) AS A VARI ABLE NAME.
VARIABLES AND RULES IN
VARIABLE DECLARATIONS

HER E ARE SOME E XAMP LES O F A CCEP TA BLE VAR I ABL E N AM ES −


REFERERENCES

ht t ps: / / www. g e e k s f o r g e e k s . or g / s e
t t i ng- c - de ve l o pme nt - e n v i r onme nt /

ht t ps: / / l e ar n. mi c r o s o f t . com/ e n-
us / c pp/ wi ndo w s / w a l k t h r oug h- cr e at i ng - a-
s t a ndar d- c pp- pr o g r a m- c p p ?v i e w = ms v c- 1 7 0

ht t ps: / / www. t u t o r i a l s po i nt . com/ What - ar e -


t he - r ul e s- t o - de c l a r e - v a ri ab l e s - i n- Cp l us p l us

You might also like