yapısal programlama yüksek düzeyli dillerin gelişim süreci –1954-1957, fortran (by ibm), for...

34
Yapısal Programlama Yüksek Düzeyli Dillerin Gelişim Süreci 1954-1957, Fortran (by IBM), for creating scientific and engineering applications, first commercial high- level programming lang. 1959, Cobol, Commercial applications requiring manipulation of large amounts of data Late 1960s, Pascal, for academic use 1967, BCPL, for writing OSs, software, compilers 1970, B, early versions of UNIX 1973, C, UNIX, major operating systems 1975, BASIC 1980s, C++, object-oriented programming (OOP) 1995, Java, create dynamic content for Web pages and for consumer devices 2000, C#, designed specifically for the .NET platform

Upload: aliyah-matherly

Post on 13-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Yapısal Programlama• Yüksek Düzeyli Dillerin Gelişim Süreci

– 1954-1957, Fortran (by IBM), for creating scientific and engineering applications, first commercial high-level programming lang.

– 1959, Cobol, Commercial applications requiring manipulation of large amounts of data

– Late 1960s, Pascal, for academic use

– 1967, BCPL, for writing OSs, software, compilers– 1970, B, early versions of UNIX– 1973, C, UNIX, major operating systems– 1975, BASIC– 1980s, C++, object-oriented programming (OOP)– 1995, Java, create dynamic content for Web pages and for consumer

devices– 2000, C#, designed specifically for the .NET platform

list of directions given to you when you ask

how to get to the local grocery store 1. First, go to steps 8 and 9.2. Drive one mile straight.3. Drive one mile straight again.4. Drive one mile straight again. You

will see the store on your right.5. If the store is closed, go to step

11.6. Stop and get out of your car.7. Go to step 13.8. Drive straight to Harvard Avenue.9. Turn right at 51st Street.10.Go to step 2.11.Turn left on Yale Street.12.Go four miles straight and you will

see another grocery on your left.13.Go in and shop.

1. Drive straight to Harvard Avenue.2. Turn right at 51st Street.3. For the next three miles, keep

driving straight. You will see the grocery on your right.

4. If the grocery is open, go inside.5. If the grocery is closed, turn left on

Yale Street. Go four miles straight and you will see another grocery on your left.

6. Go inside whichever grocery is open and buy groceries.

Benefits of Structure

• Less code equals more power

• Make the code easier to read and follow

• Enable you to break your code into logical parts

• Make it easier to spot where errors are

• Make reusing code easier

The Constructs of Structured Programming

• Sequence (Sıra)• Decision (Karar) (also called selection)• Looping (Döngü) (also called repetition or iteration)

• As long as a programming language supports these three constructs, you can write structured programs.

• An unstructured program contains lots of branching.

Sequence

Decision

Looping

Structured Programming = Yapısal Programlama

• Input Process Output

Sequence (Functions)

Decision (Conditionals)

Looping (Loops)

Basic C++ Code Structure

// C++ code template comment

#include <iostream.h> header file (support for inputs and

outputs)

#include <string.h> header file (support for string handling)

void main() a function

{

// Code goes here!!!!

}

Functions

• Functions are the basic subdivision of code.

• Just as statements are the equivalent of sentences, functions are the equivalent of paragraphs.

• To move between functions you use calls.

Functions

• Main function– Functions called main have a special meaning in C++,

they are functions that will be automatically run.

// C++ code template#include <iostream.h>void main()

{cout << "Hello, World!" << endl;

}

Statement

cout instruction<< insertion operator"Hello, World!" string to be displayed<< insertion operatorendl insert a new line; statement closing

cout << "Hello, World!" << endl;

a function can do more than one thing

// C++ code template

#include <iostream.h>

void main()

{

cout << "Hello, World!" << endl;

cout << "How are you?" << endl;

}

More functions#include <iostream.h>

void hello(){

cout << "Hello, World!" << endl;}

void hello2(){

cout << "Hello, World, MK II!" << endl;}

void main(){

cout << "main function" << endl;}

#include <iostream.h>

void hello(){

cout << "Hello, World!" << endl;}

void hello2(){

cout << "Hello, World, MK II!" << endl;}

void main(){

cout << "main function" << endl;hello();hello2;

}

Remember to have the function appear before you call it

#include <iostream.h>

void hello(){

cout << "Hello, World!" << endl;hello2();

}

void hello2(){

cout << "Hello, World, MK II!" << endl;}

void main(){

cout << "main function" << endl;hello();

}

3 Örneği inceleyiniz. Yanlış olanlar ne?

#include <iostream.h>

void hello(){

cout << "main function" << endl;}

void main(){

cout << "main function" << endl;}

#include <iostream.h>

void main(){

cout << "main function" << endl;hello();hello2();

}

void hello(){

cout << "Hello, World!" << endl;hello2();

}

void hello2(){

cout << "Hello, World, MK II!" << endl;}

Conditionals (Karar yapıları, şartlı yapılar)

• Conditionals revolve around answers to questions. – true/ false– yes/ no

• For breakfast, would you rather have toast or cereal?– Toast– Cereal– Toast & Cereal– None

• Conditionals revolve around making a decision

Conditionals in C++

if (condition)

{

// do statements here if the condition is true

}

else

{

// do these statements if the condition is false

};

Loops (Döngü yapıları)

• the same piece of code a number of times– Bir komutun (ya da komut bloğunun) belirli

sayıda işletilmesi– Bir komutun (ya da komut bloğunun) belirli bir

şart gerçekleştiği sürece (bir ön teste bağlı olarak) işletilmesi

– Bir komutun (ya da komut bloğunun) belirli bir şart gerçekleşene kadar (bir son teste bağlı olarak) işletilmesi

Bir komutun (ya da komut bloğunun) belirli sayıda işletilmesi

C++ “for” yapısı: Örnek 1

for ( <initialisation> ; <terminating condition> ; <increment> ){

// statement (or block of statements)

}

C++ “for” yapısı: Örnek 2

Bir komutun (ya da komut bloğunun) belirli bir şart gerçekleştiği sürece (bir ön teste bağlı olarak) işletilmesi

C++ “while” yapısı

Bir komutun (ya da komut bloğunun) belirli bir şart gerçekleşene kadar (bir son teste bağlı olarak) işletilmesi

C++ “do while” yapısı

Infinite Loops