Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Exercise 2.
True or false A variable of type char can hold the value 301. ( F )
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Computer Science 1620 Accumulators. Recall the solution to our financial program: #include using namespace std; int main() { double balance = ;
CS150 Introduction to Computer Science 1
Functions:Passing Parameters by Value Programming.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
1 Chapter 3 Topics Constants of Type int and float l Evaluating Arithmetic Expressions l Implicit Type Coercion and Explicit Type Conversion l Calling.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Chapter 3: Input/Output
Data Types, Expressions and Functions (part I)
Basic Elements of C++ Chapter 2.
Due Dates Quiz 1, 2 : Friday September 11 th Quiz 3 : Friday September 18 th Quiz 4 : Monday September 28 th Lab 1, 2 and 3 : Friday Sep 11 th Project.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Numeric Types, Expressions, and Output 1. Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and.
Instructor - C. BoyleFall Semester
計算機程式語言 Lecture 03-1 國立臺灣大學生物機電系 3 3 Assignment, Formatting, and Interactive Input.
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
1 Original Source : and Problem and Problem Solving.ppt.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
Simple C++ Programs Program Structure Constants and Variables
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Chapter 05 (Part II) Control Statements: Part II.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
1 A Simple “Hello World” Example #include // input-output library using namespace std; int main() // function main { cout
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 3 Assignment and Interactive Input.
Computing Fundamentals
Basic Elements of C++.
Chapter 2 Assignment and Interactive Input
Writing Reuseable Formulas
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
Intro to Programming Week # 4 Control Structure Lecture # 8
Name: Rubaisha Rajpoot
CS150 Introduction to Computer Science 1
Counting Loops.
Chapter 3: Input/Output
Lab 1 Introduction to C++.
CS150 Introduction to Computer Science 1
Chapter 6: User-Defined Functions I
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Functions Imran Rashid CTO at ManiWeber Technologies.
C++ Programming Basics
C++ for Engineers and Scientists Second Edition
Presentation transcript:

Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016

Increment/decrement operators Incrementing (adding 1 to) and decrementing (subtracting 1 from) a variable are so common that they have their own operators in C. There are actually two version of each operator -- a prefix version and a postfix version.

Increment/decrement operators (Cont…) #include using namespace std; int main() { int x = 5, y = 5; cout << x << " " << y << endl; cout << ++x << " " << --y << endl; // prefix cout << x << " " << y << endl; cout << x++ << " " << y-- << endl; // postfix cout << x << " " << y << endl; return 0; }

Increment/decrement operators (Cont…)

Using Predefined Functions in a Program Function (Subprogram): set of instructions  When activated, it accomplishes a task main executes when a program is run Other functions execute only when called C++ includes a wealth of functions  Predefined functions are organized as a collection of libraries called header files

Using Predefined Functions in a Program (Cont.) Header file may contain several functions To use a predefined function, you need the name of the appropriate header file  You also need to know: 1.Function name 2.Number of parameters required 3.Type of each parameter 4.What the function is going to do

Using Predefined Functions in a Program (Cont.) To use pow (power), include cmath  Two numeric parameters  Syntax: pow(x,y) = x y x and y are the arguments or parameters  In pow(2,3), the parameters are 2 and 3

Examples

Examples (Cont…)

Examples #include using namespace std; float main() { int i, j, k; float average ; cout<< "Enter 3 numbers \n"; cin>> i >> j >> k; average = (i+j+k) / 3; cout<< "Average = "<< average << "\n"; return 0; } #include using namespace std; int main() { int width, length, area ; cout<< "Please Enter width & Length of a Rectangle \n"; cin>> width >> length; area = width * length; cout<< "Area of rectangle = " << area << "\n"; return 0 ; }

Examples (Cont…) #include using namespace std; int main() { const int a=5; int b=2; b = a + b; cout<< b << endl; return 0; }

#include using namespace std; int main() { int a=5, b=2 ; a += b; // a = a + b; cout<< a << "\n"; return 0; } #include using namespace std; int main() { int a, b, c, d; a = * (3 + 4); cout<< "Value of a = " << a << endl; b = 5 * % 4; cout<< "Value of b = " << b << endl; c = 5 * 2 % (7 - 4); cout<< "Value of c = " << c << endl; d = 2 * 5 * * 5 + 7; cout<< "Value of d = " << d << endl; return 0; }

#include using namespace std; int main() { int x; cout<< "Enter the value of X \n"; cin>>x; x+=5; cout<< x << "\n"; return 0; } #include using namespace std; int main() { int x; cout<< "Enter the value of X \n"; cin>>x; x*=10; cout<< x << "\n"; return 0; }

#include using namespace std; double main() { double x; cout<< “Enter the value of X \n"; cin>>x; x-=5; cout<< x << "\n"; return 0; } #include using namespace std; double main() { double x; cout<< “Enter the value of X \n"; cin>>x; x/=5; cout<< x << "\n"; return 0; }

#include using namespace std; int main() { int x; cout<< "Enter the number you need to increment it \n"; cin>>x; x++; cout<< x << "\n"; return 0; } #include using namespace std; int main() { int x, y = 10; cout<< "Enter the value of X \n"; cin>>x; cout<< ++x+y << "\n" ; y++; cout<< x << "\n" << y << "\n"; return 0; }

#include using namespace std; int main() { int x, y; cout<< "Enter the values of the two numbers \n"; cin>> x >> y; cout<< x++ + y << "\n"; cout<< x << "\n" << y << "\n"; return 0; } #include using namespace std; int main() { int x; cout<< "Enter the number you need to decrement it \n"; cin>>x; x--; cout<< x << "\n"; return 0; }

#include using namespace std; int main() { int x, y; cout<< "Enter the values of the two numbers \n"; cin>> x >> y; cout<< x-- + y << "\n"; cout<< x << "\n" << y << "\n" ; return 0; } #include using namespace std; int main() { int x, y; cout<< "Enter the values of the two numbers \n"; cin>> x >> y; cout<< --x * y << "\n"; cout<< x << "\n" << y << "\n" ; return 0; }

Examples (Cont…) #include using namespace std; int main() { int number1, sum; float number2; cout<< "Enter the values of number1 & number2 = " ; cin>> number1>> number2; sum = number1 + number2; cout<< " Sum = " << sum << endl; return 0; } #include using namespace std; int main() { float sum =50.0, count=5.0; int avg; avg = sum / count; cout<< avg << "\n"; return 0; }