Programming concept Lect1

Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Programming concept : 

Programming concept Lecture 1 Hisham Mat Hussin 734661396 www.projekelektronik.com/tutorials/ hisham2arabia@gmail.com

Slide 4: 

So, what exactly is a programming language? A tool used by a programmer to give the computer very specific instructions in order to serve some purpose for the user. A program is like a recipe. It outlines exactly the steps needed to create something or perform a certain task. For, example, when baking chocolate chip cookies, there are certain steps that need to be followed: mix eggs, butter, sugar in a bowl add flour, baking soda, and flavorings mix until creamy add chocolate chips bake in the oven.

Slide 5: 

For a person who has made cookies before and knows the amounts of each ingredient to use, this recipe is sufficient, however, for a person who has never baked cookies before, this recipe will not do. That person would need a recipe like the following: place two eggs in a bowl add 1.5 c. butter to the eggs ... bake cookies for 10-12 minutes at 375 degrees or until brown There is still a problem with the preceding recipe. The first instruction says to put two eggs in the bowl, but it doesn't say to shell them first! This may seem like common sense, but it illustrates a fundamental concept: computers do exactly what they are told, no more, no less. When writing a program, a programmer must outline every possible step and scenario that could occur.

Slide 6: 

The first programming languages that emerged, were assembly languages. These languages are exactly the instruction set of a specific processor. These languages are very low-level and hard to understand. For example, say we wanted to add two numbers, 3 and 4 and get a result: in C++: in assembly: int a = 3 + 4; ldl 3, R1 ldl 4, R2 addl R1, R2, R3 The version in C++ is easier to understand and simpler to write. This is analagous to the differences in the first recipe presented and the second recipe presented. The first recipe expressed the method of baking cookies on a high level, while the second method went more in depth on how to actually mix and bake the cookies. Programmers write their code in a high level language and then use a compiler to translate their code into an assembly language and then into a machine language that will run on the machine they are using.

Programming Languages : 

Programming Languages Programming languages allow programmers to code software. The three major families of languages are: Machine languages Assembly languages High-Level languages

Machine Languages : 

Machine Languages Comprised of 1s and 0s The “native” language of a computer Difficult to program – one misplaced 1 or 0 will cause the program to fail. Example of code:1110100010101 111010101110 10111010110100 10100011110111

Assembly Languages : 

Assembly Languages Assembly languages are a step towards easier programming. Assembly languages are comprised of a set of elemental commands which are tied to a specific processor. Assembly language code needs to be translated to machine language before the computer processes it. Example:ADD 1001010, 1011010

High-Level Languages : 

High-Level Languages High-level languages represent a giant leap towards easier programming. The syntax of HL languages is similar to English. Historically, we divide HL languages into two groups: Procedural languages Object-Oriented languages (OOP)

Procedural Languages : 

Procedural Languages Early high-level languages are typically called procedural languages. Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript

Object-Oriented Languages : 

Object-Oriented Languages Most object-oriented languages are high-level languages. The focus of OOP languages is not on structure, but on modeling data. Programmers code using “blueprints” of data models called classes. Examples of OOP languages include C++, Visual Basic.NET and Java.

Compiling : 

Compiling Regardless of the HL Language, all HL programs need to be translated to machine code so that a computer can process the program. Some programs are translated using a compiler. When programs are compiled, they are translated all at once. Compiled programs typically execute more quickly than interpreted programs, but have a slower translation speed.

Programming Example : 

Programming Example Simple programming problem: Convert a price from British pounds into Dollars. Pseudocode Input the price of the item, PoundPrice, in pounds Compute the price of the item in dollars: Set DollarPrice = 1.62 * PoundPrice Write DollarPrice

Programming Example : 

Programming Example Translating to Basic programming language: INPUT PoundPrice LET DollarPrice = 1.62 * PoundPrice PRINT DollarPrice END

Slide 19: 

introduction to the c++

Introduction to C++ : 

Introduction to C++ A program is a sequence of instructions that can be executed by a computer. C++ (pronounced “see-plus-plus”). The most powerful programming language available. Gives the programmer the power to write efficient, structured, object-oriented programs.

Sample program codes : 

Sample program codes Example: The “Hello, World!” Program This program simply prints “Hello World” #include <iostream.h> int main() { cout << “Hello World!\n”; return 0; }

Sample program codes : 

Sample program codes Example: The “Hello, World!” Program This program simply prints “Hello World” #include <iostream.h> --------> line 1 int main() --------> line 2 { cout << “Hello World!\n”; --------> line 3 return 0; }

Slide 23: 

Line 1  #include <iostream.h> Called preprocessor directive. The identifier iostream.h is the name of the file in the Standard C++ Library Every c++ programs that ahs standard input and output must include this preprocessor directive. Sign # is required to indicate that the word “include” is a preprocessor directive. The angle brackets < > are required to indicate that the word “iostream.h” (which stands for “input/output stream”) is the name of a Standard c++ Library file. The expression <iostream.h> is called a standard header.

Slide 24: 

Line 2  int main() Required in every c++ program The identifier main is the name of function, called the main function of the program. Every c++ program must have one and the only one main() function. Parentheses that follow the word “main” indicate that it is a function. The keyword int is the name of the data type in c++. int stands for integer. Used to indicate the return type for the main() function. When the program has finished running, it can return an integer value to the operating system to signal some resulting status.

Slide 25: 

The last three lines constitute the actual body of the program. A program body is a sequence of the program statement enclosed in braces { }. cout << “Hello World!\n”; Above statement means the program send the string “Hello, World!\n” to the standard output stream object. The symbol >> represents the c++ output operator. When the above statement executes, the character enclosed in quotation marks “ “ are sent to the standard output device which usually the computer screen. #include <iostream.h> int main() { cout << “Hello World!\n”; return 0; }

Slide 26: 

The \n represents the newline character. Every program statement must end with a semicolon ( ; ). “return 0;” The return statement causes the main function to finish. Return may be followed by a return code (in our example is followed by the return code 0). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ program. #include <iostream.h> int main() { cout << “Hello World!\n”; return 0; }

Another Version of “Hello World” Program : 

Another Version of “Hello World” Program int main() { cout << “Hel” << “lo, Wo” << “rld!” << endl; } int main() { cout << “Hello, W” << “o” << “rld!” << endl; } int main () { cout << "Hello World"; return 0; }

COMMENT : 

COMMENT Comments are parts of the source code disregarded by the compiler. They simply do nothing. The purpose is only to allow the programmer to insert notes or descriptions embedded within the source code. C++ supports two ways to insert comments: // line comment /* block comment */

COMMENT : 

The first of them, known as line comment, discards everything from where the pair of slash signs (//) is found up to the end of that same line. The second one, known as block comment, discards everything between the /* characters and the first appearance of the */ characters, with the possibility of including more than one line. COMMENT

Example: : 

Example: