SlideShare a Scribd company logo
Computer Programming
University Of Salahaddin
Engineering College
Electrical Engineering
2009-2010
What we learn
We will begin the study of the language starting with the
fundamentals of the language and simple programs; and as we explore
more of the language, we will write increasingly larger programs.
By the end of this year, every student:
• will learn about all the essential programming concepts
• will demonstrate a good familiarity with C++ syntax
• will be able to write reasonably complex procedural programs
What We Will Learn
The following topics will be covered in this course:
• Flow charts and algorithms
• Variables and assignment
• Input, output (I/O), formatting output
• Basic data types
• A simple C++ program
• Arithmetic operators
• Flow of control and loops
• Program style
• Procedures and functions
• Local and global variables, constants
• File I/O
• Structures and arrays
• Numerical analysis
Problem Solving
Engineers use their knowledge of science, mathematics, and
appropriate experience to find suitable solutions to a problem.
Engineering is considered a branch of applied mathematics and
science. Creating an appropriate mathematical model of a problem
allows them to analyze it (sometimes definitively), and to test potential
solutions.
Usually multiple reasonable solutions exist, so engineers must
evaluate the different design choices on their merits and choose the
solution that best meets their requirements.
How To Solve Problems
1.Define the problem and see if there is a better way to redefine it.
2.Find the way how human solves it.
3.Write down human’s solution
4.Break down this solution to its original steps and do not forget
simplest thoughts.
5. match every human activity with computer’s tool.
6.If some activity don’t exist directly in computer find alternatives.
7.Group these tiny computer actions into logically related functions.
8.Combine these functions in a complete solution.
9.Solution Implementation and Verification
An Algorithm: Baking a Cake
An Algorithm: Baking a Cake (cont)
Flowchart
A flowchart is a common type of diagram, that represents an
algorithm or process, showing the steps as boxes of various kinds, and
their order by connecting these with arrows.
Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields.[1]
Flowchart (cont)
Flowchart (cont)
Flowchart (cont)
Lamp Fixing Flowchart.
Flowchart (cont)
Game of Monopoly Flowchart.
Pseudocode
This is the pseudocode for a Game of Monopoly, including one
person's move as a procedure:
Exercise
1.Find a solution for this equation x^2 + x – 9 = 18. using
pseudocode and flowchart.
2.How can you replace a broken door.
3.Write a pseudocode that illustrate kids going to the school steps.
4.Draw a flowchart for buying a house.
Flowchart Example #1
Draw a flowchart to find
the sum of first 50 natural
numbers
Flowchart Example #2
Draw a flowchart to find the largest of three numbers A,B, and C.
Flowchart Example #2
Draw a flowchart for computing
factorial N (N!)
Exercise
1.Draw a flowchart to read a number N and print all its divisors.
2.Draw a flowchart for computing the sum of the digits of any
number
3.Draw a flowchart to find the sum of given N numbers.
4.Draw a flowchart to compute the sum of squares of integers from 1 to 50
5.Draw a flowchart to arrange the given data in an ascending order.
Variables
A C++ variable is a placeholder used for storing data. The type of
data may be numerical, string, character and any other type that the
language uses it.
The data in a variable is called its value and it can be changed or
deleted. in order to uniquely identify and keep track of a variable, we
need to give each variable a name; this is called declaring a variable. it
is a good idea to use meaningful names for variables. For example:
int books;// this is variable declaration
It’s common to initialize variables upon declaration. if a variable is
used in a program without being initialized, the results will be
unpredictable. Variable initialization can be performed either during
declaration using assignment statements as in:
int books = 0; // this is variable declaration and
initialization
Variables (cont)
Values can be assigned or stored in variables with assignment
statements:
books=34; //this is assignment statement
An assignment statement is an order, to the computer, to assign the
value on the right-hand side of the equal sign to the variable on the
left-hand side.
Basic Data Types
Tell which continent your country is located on and which countries
are its neighbors.
1- Integer Numbers (int)
2- Real Numbers(double)
Basic Data Types (cont)
3- Characters (char)
char letter, symbol;
letter = ‘A’;
symbol=‘#’;
4- Boolean expressions (bool)
bool you = true;
important note
As a general rule, you cannot store values of one type in a variable
of another type. This is a good rule to follow, even though some C++
compilers do not enforce this type checking.
Assignment Statements
Values can be assigned or stored in variables with assignment
statements:
books=34;
An assignment statement is an order, to the computer, to assign the
value on the right-hand side of the equal sign to the variable on the
left-hand side. The sign (=) is called the assignment operator. (C++
operators will be covered later in the course). Assignment
statements end with a semicolon.
The value on the right-hand side can also be another variable or
expression:
books1=books2;
In an assignment statement, first the value on the right-hand side is
evaluated and then its result is stored or assigned to the variable on
the left-hand side.
Performing Output
The values of variables, numerical values and strings of text ,may be
output to the screen using cout as in
int books=0;
cout<<books<<endl;
cout<<72<<endl;
cout<<“This is the output”<<endl;
In the first output statement, the value of variable books will be output
on the screen, which is 0;
In the second, the numerical value 72 will be output to the screen, and
in the last statement, the string “This is the output” will be output
to the screen.
Input Using cin
in C++, cin is used to input values into variables. After declaring a
variable of type int,
int price;
cout<<“Enter the price:”;
cin>>price;
cout<<“The price you entered is $“<<price<<endl;
in this program extract, first an integer is declared, then the user is
asked to enter/type a value for price. This value is then input in the
variable price using cin. A message is also output to the screen
notifying the user of the input value.
When the program reaches a cin statement, it waits for input to be
entered from the keyboard and for this value to be input into the
Variable, the user must enter a new line.
A simple C++ Program
Now, we will write our first complete C++ program.
#include <iostream.h>
main( ){
int hours=0;
cout<<“This is your first C++ program”<<endl;
cout<<“Welcome to C++ Programming”<<endl;
cout<<endl<<endl;
cout<<“How many hours/week do you practice C++ ?”;
cin>>hours;
cout<<“You practice “<<hours<<“ per week.”<<endl;
cout<<“OK, this is enough for now.”<<endl;
return 0;
}

More Related Content

PPT
Basics of c++
PPT
Basics of c++ Programming Language
PPSX
Complete C++ programming Language Course
PPT
Introduction to C++
PPT
01 c++ Intro.ppt
PDF
C++ Programming
PPTX
Overview of c++ language
PPT
Getting started with c++
Basics of c++
Basics of c++ Programming Language
Complete C++ programming Language Course
Introduction to C++
01 c++ Intro.ppt
C++ Programming
Overview of c++ language
Getting started with c++

What's hot (20)

PPTX
Intro to c++
PPTX
C++ Basics introduction to typecasting Webinar Slides 1
PPT
Getting Started with C++
PPT
The smartpath information systems c plus plus
PPT
C++ Programming Course
PDF
C programming notes
PPSX
C++ Programming Language
PPTX
Learning C++ - Introduction to c++ programming 1
PPT
Programming of c++
PDF
C programming | Class 8 | III Term
PPTX
Introduction Of C++
PPTX
C++ PROGRAMMING BASICS
PPT
C++ Language
ODP
(2) cpp imperative programming
PPTX
C++ ppt
PPTX
C++ Programming Language Training in Ambala ! Batra Computer Centre
PPS
Learn C
PDF
PPS
basics of C and c++ by eteaching
DOCX
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Intro to c++
C++ Basics introduction to typecasting Webinar Slides 1
Getting Started with C++
The smartpath information systems c plus plus
C++ Programming Course
C programming notes
C++ Programming Language
Learning C++ - Introduction to c++ programming 1
Programming of c++
C programming | Class 8 | III Term
Introduction Of C++
C++ PROGRAMMING BASICS
C++ Language
(2) cpp imperative programming
C++ ppt
C++ Programming Language Training in Ambala ! Batra Computer Centre
Learn C
basics of C and c++ by eteaching
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Ad

Viewers also liked (19)

DOCX
basic programs in C++
PPT
Lecture#2 Computer languages computer system and Programming EC-105
PPT
Program Logic Formulation - Ohio State University
PDF
Nummeth0 ay1415
PPT
Lecture 19 matlab_script&function_files06
PPTX
Computer programming
PPTX
Apt programming
DOC
Lab 5 array
PDF
Use of computer programming in animal diet formulation
PPSX
DISE - Programming Concepts
PPT
Numerical solution using runge kutta with programming in c++
PPT
NC Programming
PPT
Computer Programming- Lecture 6
PPT
10 Myths for Computer Science
PPTX
Software And Computer Applications for civil engineering
PPT
Computer Science Engineering
PPTX
Computer Engineering (Programming Language: Swift)
PDF
Introduction to cad cam
PPT
Embedded System Basics
basic programs in C++
Lecture#2 Computer languages computer system and Programming EC-105
Program Logic Formulation - Ohio State University
Nummeth0 ay1415
Lecture 19 matlab_script&function_files06
Computer programming
Apt programming
Lab 5 array
Use of computer programming in animal diet formulation
DISE - Programming Concepts
Numerical solution using runge kutta with programming in c++
NC Programming
Computer Programming- Lecture 6
10 Myths for Computer Science
Software And Computer Applications for civil engineering
Computer Science Engineering
Computer Engineering (Programming Language: Swift)
Introduction to cad cam
Embedded System Basics
Ad

Similar to C++ for beginners (20)

PPT
Introduction to Procedural Programming in C++
PPTX
C++ lecture 01
PPT
C program
PPT
Chapter2
PPT
C++ programming
PPTX
C programming
PPT
Elementary_Of_C++_Programming_Language.ppt
PPTX
Fundamentals of Programming Lecture #1.pptx
PPTX
C and C++ programming basics for Beginners.pptx
PDF
introduction to python programming course 2
PPTX
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
PPTX
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
PPTX
classVI_Coding_Teacher_Presentation.pptx
PPTX
classVI_Coding_Teacher_Presentation.pptx
PPT
Ap Power Point Chpt2
PPTX
#Code2 create c++ for beginners
PDF
java or oops class not in kerala polytechnic 4rth semester nots j
PPTX
C Programming Unit-1
PPTX
Fundamentals of computers - C Programming
Introduction to Procedural Programming in C++
C++ lecture 01
C program
Chapter2
C++ programming
C programming
Elementary_Of_C++_Programming_Language.ppt
Fundamentals of Programming Lecture #1.pptx
C and C++ programming basics for Beginners.pptx
introduction to python programming course 2
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
Ap Power Point Chpt2
#Code2 create c++ for beginners
java or oops class not in kerala polytechnic 4rth semester nots j
C Programming Unit-1
Fundamentals of computers - C Programming

More from Salahaddin University-Erbil (7)

PPTX
HTML for beginners
PPT
Advanced Java Topics
PPT
Java for C++ programers
PDF
PPT
Object-Oriented Programming Using C++
HTML for beginners
Advanced Java Topics
Java for C++ programers
Object-Oriented Programming Using C++

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
master seminar digital applications in india
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPH.pptx obstetrics and gynecology in nursing
master seminar digital applications in india
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
TR - Agricultural Crops Production NC III.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Final Presentation General Medicine 03-08-2024.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning

C++ for beginners

  • 1. Computer Programming University Of Salahaddin Engineering College Electrical Engineering 2009-2010
  • 2. What we learn We will begin the study of the language starting with the fundamentals of the language and simple programs; and as we explore more of the language, we will write increasingly larger programs. By the end of this year, every student: • will learn about all the essential programming concepts • will demonstrate a good familiarity with C++ syntax • will be able to write reasonably complex procedural programs
  • 3. What We Will Learn The following topics will be covered in this course: • Flow charts and algorithms • Variables and assignment • Input, output (I/O), formatting output • Basic data types • A simple C++ program • Arithmetic operators • Flow of control and loops • Program style • Procedures and functions • Local and global variables, constants • File I/O • Structures and arrays • Numerical analysis
  • 4. Problem Solving Engineers use their knowledge of science, mathematics, and appropriate experience to find suitable solutions to a problem. Engineering is considered a branch of applied mathematics and science. Creating an appropriate mathematical model of a problem allows them to analyze it (sometimes definitively), and to test potential solutions. Usually multiple reasonable solutions exist, so engineers must evaluate the different design choices on their merits and choose the solution that best meets their requirements.
  • 5. How To Solve Problems 1.Define the problem and see if there is a better way to redefine it. 2.Find the way how human solves it. 3.Write down human’s solution 4.Break down this solution to its original steps and do not forget simplest thoughts. 5. match every human activity with computer’s tool. 6.If some activity don’t exist directly in computer find alternatives. 7.Group these tiny computer actions into logically related functions. 8.Combine these functions in a complete solution. 9.Solution Implementation and Verification
  • 7. An Algorithm: Baking a Cake (cont)
  • 8. Flowchart A flowchart is a common type of diagram, that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.[1]
  • 12. Flowchart (cont) Game of Monopoly Flowchart.
  • 13. Pseudocode This is the pseudocode for a Game of Monopoly, including one person's move as a procedure:
  • 14. Exercise 1.Find a solution for this equation x^2 + x – 9 = 18. using pseudocode and flowchart. 2.How can you replace a broken door. 3.Write a pseudocode that illustrate kids going to the school steps. 4.Draw a flowchart for buying a house.
  • 15. Flowchart Example #1 Draw a flowchart to find the sum of first 50 natural numbers
  • 16. Flowchart Example #2 Draw a flowchart to find the largest of three numbers A,B, and C.
  • 17. Flowchart Example #2 Draw a flowchart for computing factorial N (N!)
  • 18. Exercise 1.Draw a flowchart to read a number N and print all its divisors. 2.Draw a flowchart for computing the sum of the digits of any number 3.Draw a flowchart to find the sum of given N numbers. 4.Draw a flowchart to compute the sum of squares of integers from 1 to 50 5.Draw a flowchart to arrange the given data in an ascending order.
  • 19. Variables A C++ variable is a placeholder used for storing data. The type of data may be numerical, string, character and any other type that the language uses it. The data in a variable is called its value and it can be changed or deleted. in order to uniquely identify and keep track of a variable, we need to give each variable a name; this is called declaring a variable. it is a good idea to use meaningful names for variables. For example: int books;// this is variable declaration It’s common to initialize variables upon declaration. if a variable is used in a program without being initialized, the results will be unpredictable. Variable initialization can be performed either during declaration using assignment statements as in: int books = 0; // this is variable declaration and initialization
  • 20. Variables (cont) Values can be assigned or stored in variables with assignment statements: books=34; //this is assignment statement An assignment statement is an order, to the computer, to assign the value on the right-hand side of the equal sign to the variable on the left-hand side.
  • 21. Basic Data Types Tell which continent your country is located on and which countries are its neighbors. 1- Integer Numbers (int) 2- Real Numbers(double)
  • 22. Basic Data Types (cont) 3- Characters (char) char letter, symbol; letter = ‘A’; symbol=‘#’; 4- Boolean expressions (bool) bool you = true; important note As a general rule, you cannot store values of one type in a variable of another type. This is a good rule to follow, even though some C++ compilers do not enforce this type checking.
  • 23. Assignment Statements Values can be assigned or stored in variables with assignment statements: books=34; An assignment statement is an order, to the computer, to assign the value on the right-hand side of the equal sign to the variable on the left-hand side. The sign (=) is called the assignment operator. (C++ operators will be covered later in the course). Assignment statements end with a semicolon. The value on the right-hand side can also be another variable or expression: books1=books2; In an assignment statement, first the value on the right-hand side is evaluated and then its result is stored or assigned to the variable on the left-hand side.
  • 24. Performing Output The values of variables, numerical values and strings of text ,may be output to the screen using cout as in int books=0; cout<<books<<endl; cout<<72<<endl; cout<<“This is the output”<<endl; In the first output statement, the value of variable books will be output on the screen, which is 0; In the second, the numerical value 72 will be output to the screen, and in the last statement, the string “This is the output” will be output to the screen.
  • 25. Input Using cin in C++, cin is used to input values into variables. After declaring a variable of type int, int price; cout<<“Enter the price:”; cin>>price; cout<<“The price you entered is $“<<price<<endl; in this program extract, first an integer is declared, then the user is asked to enter/type a value for price. This value is then input in the variable price using cin. A message is also output to the screen notifying the user of the input value. When the program reaches a cin statement, it waits for input to be entered from the keyboard and for this value to be input into the Variable, the user must enter a new line.
  • 26. A simple C++ Program Now, we will write our first complete C++ program. #include <iostream.h> main( ){ int hours=0; cout<<“This is your first C++ program”<<endl; cout<<“Welcome to C++ Programming”<<endl; cout<<endl<<endl; cout<<“How many hours/week do you practice C++ ?”; cin>>hours; cout<<“You practice “<<hours<<“ per week.”<<endl; cout<<“OK, this is enough for now.”<<endl; return 0; }

Editor's Notes

  • #3: Insert a map of your country.
  • #4: Insert a map of your country.
  • #5: Insert a map of your country.
  • #6: Insert a map of your country.
  • #7: Insert a map of your country.
  • #8: Insert a map of your country.
  • #9: Insert a map of your country.
  • #10: Insert a map of your country.
  • #11: Insert a map of your country.
  • #12: Insert a map of your country.
  • #13: Insert a map of your country.
  • #14: Insert a map of your country.
  • #15: Insert a map of your country.
  • #16: Insert a map of your country.
  • #17: Insert a map of your country.
  • #18: Insert a map of your country.
  • #19: Insert a map of your country.
  • #20: Insert a map of your country.
  • #21: Insert a map of your country.
  • #22: Insert a map of your country.
  • #23: Insert a map of your country.
  • #24: Insert a map of your country.
  • #25: Insert a map of your country.
  • #26: Insert a map of your country.
  • #27: Insert a map of your country.