1.fp201-1.intro to c++programming
TRANSCRIPT
-
8/13/2019 1.FP201-1.Intro to C++Programming
1/21
Chapter 1:
INTRODUCTION TO
PROGRAMMING LANGUAGE
1.1 C++ Programming Environment
1.2 Compiling Process An error In Programming
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
2/21
Learning Outcomes 1.1At the end of this sub-chapter, students should be able to:
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
Explain the history of C++ Illustrate a simple C++
program structure Describe C++ programming
development process Develop C++ program using
Integrated DevelopmentEnvironment (IDE) Get started with IDE
Create a project Create a simple C++ program Compile a C++ program Run a C++ program
1.1 Introducethe C++
programmingenvironment
-
8/13/2019 1.FP201-1.Intro to C++Programming
3/21
The history of C++
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
C with Class(Before 1983)
C++(1983)
C(Early 1970)
C++ was designed for the UNIX systemenvironment
C++ expanded and enhance version of C thatembodies the philosophy of OOP.
C++ enables programmers to improve the
quality of code produced, thus making reusablecode easier to write.
C++s clarity, extensibility, efficiency and easeof maintenance makes it the language of choicefor development of large software projects.
used widely in the area of communication,personal file systems and databases.
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
4/21
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
5/21
A simple C++ program structure
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
// my first program in C++
#include
int main ()
{
cout
-
8/13/2019 1.FP201-1.Intro to C++Programming
6/21
// Program: Display greetings
/* Hello World!*/
#include
using namespace std;void main()
{
cout
-
8/13/2019 1.FP201-1.Intro to C++Programming
7/21
Greeting Output
-
8/13/2019 1.FP201-1.Intro to C++Programming
8/21
C++ Programming Development Process
Identify: needed
input required
output neededprocess.
Understandthe Problem
A framework
shows steps inprob.solving
Methods :Algorithm - a
sequence ofinstructions (inhumanlanguage)
Flowchart - Agraphicalsymbols to showprocess
Pseudo code -half inprogrammingcode and half inhuman
language.
DesignProgram
Convert analgorithminto a C++.programming language
- includeadequatedocumentation, whicharecommentstatementswritten inyour
programcode
WriteProgram
Code
Use a set ofdata to
discovererrors and toensureaccuracy ofthe program
Process ofidentify&correct error.
Run programand checkresults.
Test &Debug theProgram
Update CodeVerifieswhetherperforming as
planned/ meetthe currentrequirement
Edit code tomake it moreefficient.
Maintenance& Documentation
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
For example, somepart uses C++
language code andsome part use Malay
/English language.
-
8/13/2019 1.FP201-1.Intro to C++Programming
9/21
Develop C++ program using Integrated
Development Environment (IDE)
WhatIDE?
An integrated developmentenvironment (IDE)a softwareapplicationthat providescomprehensive facilities tocomputer programmersfor softwaredevelopment.
All of the tools for writing,compiling and testing code in oneplace
An IDE normally consists of: a source code editor a compilerand/or an interpreter build automationtools a debugger
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
http://en.wikipedia.org/wiki/Software_applicationhttp://en.wikipedia.org/wiki/Software_applicationhttp://en.wikipedia.org/wiki/Computer_programmerhttp://en.wikipedia.org/wiki/Software_developmenthttp://en.wikipedia.org/wiki/Software_developmenthttp://en.wikipedia.org/wiki/Source_code_editorhttp://en.wikipedia.org/wiki/Compilerhttp://en.wikipedia.org/wiki/Interpreter_(computing)http://en.wikipedia.org/wiki/Build_automationhttp://en.wikipedia.org/wiki/Debuggerhttp://en.wikipedia.org/wiki/Debuggerhttp://en.wikipedia.org/wiki/Build_automationhttp://en.wikipedia.org/wiki/Interpreter_(computing)http://en.wikipedia.org/wiki/Compilerhttp://en.wikipedia.org/wiki/Source_code_editorhttp://en.wikipedia.org/wiki/Software_developmenthttp://en.wikipedia.org/wiki/Software_developmenthttp://en.wikipedia.org/wiki/Computer_programmerhttp://en.wikipedia.org/wiki/Software_applicationhttp://en.wikipedia.org/wiki/Software_application -
8/13/2019 1.FP201-1.Intro to C++Programming
10/21
Develop C ++ program
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
Do in lab activities 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
11/21
Learning Outcomes 1.2At the end of this sub-chapter, students should be able to:
Describe the compiling process of aprogram Identify the following errors in
programming: Syntax/ compile time errors Run time errors Logical errors
Identify effective debugging process Debug programs with syntax/
compile time, run time and logicalerror
1.2 Compilingand debugging
process anderror in
programming
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
12/21
Basic compiling process
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
-
8/13/2019 1.FP201-1.Intro to C++Programming
13/21
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
Example of compilingprocess of a program
FP201: Programming Fundamentals/ Chapter 1
i d l / h
-
8/13/2019 1.FP201-1.Intro to C++Programming
14/21
Compiling process of a programPrepared by Pn Mazniha bt Berahim,
Information Tech and Communication Department
1. SyntaxChecking
The code checking for valid syntax use compiler. This includes checking for semi-colons, matching braces, etc. This doesn't mean the code is correct, but it does determine
whether the code can be turned into machine code as written.
2. ConvertingTo Assembly
This step doesn't exist for all languages/compilers. Compilers convert source code (C++ language) to machine code .
3. LinkingMachine Code
Into AnExecutable
At this step, many linkers will do final checks to make sure allthe required pieces, functions, components, etc have beenaccounted for.
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
15/21
Compiler
This is where the "work" is done. High
level code is translated into machinecode, the result is object files.
Linker
All object files and relevent resources
are linked together. Symbolinformation is verified (run into aLinker error may be more then once)and an executable is made.
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP P i F d l / Ch
-
8/13/2019 1.FP201-1.Intro to C++Programming
16/21
Errors in programming
ERRORS
Syntax/Compile
RunTime
Logical
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
FP P i F d t l / Ch t
-
8/13/2019 1.FP201-1.Intro to C++Programming
17/21
3 basic types of errors in programmingPrepared by Pn Mazniha bt Berahim,
Information Tech and Communication Department
Error Decriptions Common examples
Syntaxerrors/compileerror
Grammar errorsin theuse of theprogramminglanguage.
Misspelled variable and function names.Missing semicolons(;)Improperly matches parentheses, squarebrackets[ ], and curly braces{ }
Incorrect format in selection and loopstatements
Run timeerrors
Occur when a programwith no syntax errorsasks the computer todo something that thecomputer is unable toreliably do.
Trying to divide by a variable that contains avalue of zeroTrying to open a file that doesn't existThere is no way for the compiler to knowabout these kinds of errors when the programis compiled.
Logicerrors
Logic errors occurwhen there is a designflaw in your program.
Multiplying when you should be dividingAdding when you should be subtractingOpening and using data from the wrong file
Displaying the wrong message
FP201: Programming Fundamentals/ Chapter 1
FP P i F d t l / Ch t
-
8/13/2019 1.FP201-1.Intro to C++Programming
18/21
Special Characters in C++ programming syntaxCharacter Name Meaning
// Double slash Beginning of a comment
# Pound sign Beginning of preprocessordirective
< > Open/close brackets Enclose filename in #include
( ) Open/closeparentheses
Used when naming afunction
{ } Open/close brace Encloses a group ofstatements
" " Open/closequotation marks
Encloses string of characters
; Semicolon End of a programming
statement
FP201: Programming Fundamentals/ Chapter 1
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
-
8/13/2019 1.FP201-1.Intro to C++Programming
19/21
What is syntax?
Set of rules in programming language.
Prepared by Pn Maznihabt Berahim, Information
Tech andCommunication
Department
FP201 P i F d t l / Ch t 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
20/21
Debug programs with syntax/ compiletime, run time and logical error
Do in lab activities 1
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department
FP201: Programming Fundamentals/ Chapter 1
-
8/13/2019 1.FP201-1.Intro to C++Programming
21/21
Prepared by Pn Mazniha bt Berahim,Information Tech and Communication Department