Pobieranie prezentacji. Proszę czekać

Pobieranie prezentacji. Proszę czekać

Podstawy programowania (1)

Podobne prezentacje


Prezentacja na temat: "Podstawy programowania (1)"— Zapis prezentacji:

1 Podstawy programowania (1)
dr Jerzy Bartoszek

2 Opis przedmiotu Cele: Podstawowym celem przedmiotu jest nauczenie studentów budowania algorytmów i programowania w języku imperatywnym wyższego rzędu. Studenci zapoznają się z podstawowymi cechami algorytmów, strukturami danych, instrukcjami, elementarną analizą programów, ich kompilowaniem i testowaniem. Opis przedmiotu: Wykład. Algorytmy i ich cechy. Podstawowe konstrukcje programistyczne: zmienne; stałe; typy danych: typy proste, tablice jedno- i wielowymiarowe, struktury, referencje; pliki; instrukcje: podstawienia, warunkowe, pętli; procedury i funkcje oraz ich parametry; rekursja; moduły; biblioteki; przestrzenie nazw. Obsługa zdarzeń i wyjątków. Podstawowe komponenty interfejsu z użytkownikiem. Zasady programowania strukturalnego. Etapy kompilacji. Elementy analizy poprawności programów i ich efektywności. Laboratorium. Składowe środowiska programowania. Tworzenie programów wykorzystujących proste typy danych i podstawowe instrukcji programistycznych (instrukcje podstawienia, warunkowe, pętle, konsolowe operacje wejścia/wyjścia). Tworzenie programów zawierających typy złożone (tablice jedno i dwuwymiarowych, struktury). Tworzenie programów z procedurami, funkcjami, modułami i obsługą wyjątków. Tworzenie prostego interfejsu z użytkownikiem i obsługiwanie zdarzeń. Śledzenie wykonywania programów.

3 Opis przedmiotu cd. Forma prowadzenia zajęć:
Wykład wykorzystujący środki multimedialne oraz laboratorium. Metody oceny: Zaliczenie wykładu w formie egzaminu pisemnego, zaliczenie laboratorium – sprawdziany i projekty programistyczne. Bibliografia: N. Wirth, Algorytmy+struktury danych=programy, WNT Warszawa 1980 (i późniejsze) N. Wirth, Wstęp do programowania systematycznego, WNT Warszawa 1978 H. Gantenbein i inni, Microsoft Visual Basic .NET Księga eksperta, Wydawnictwo Helion, 2006 M. Szeliga, Visual Basic .NET : ćwiczenia, Wydawnictwo Helion, 2004

4 Algorytm Algorytm to jednoznaczny, dobrze określony
przepis rozwiązania dowolnego zadania z pewnej klasy zadań. składa się z kroków, wykorzystuje dane wejściowe, wytwarza wyniki, jest dobrze określony, jest skończony, jest wykonywalny.

5 Złożoność obliczeniowa algorytmów
Czas wykonywania algorytmu wyrażony jako funkcja rozmiaru zadania (liczby danych), to złożoność czasowa. logarytmiczna O(log n) liniowa O(n) kwadratowa O(n2) wielomianowa O(nk) , k>2 wykładnicza O(2n) lub O(n!).

6 Porównanie czasów wykonywania algorytmów
Porównano w niej czasy wykonywania algorytmu na dwóch komputerach, w których każda operacja jednostkowa zajmuje, odpowiednio, 10-6 s i 10-9 s.

7 Porównanie czasów wykonywania algorytmów
Rozmiar 20 50 100 200 Czas działania(2n/106) 1,04s 35,7 lat 4 * 1014 wieków 5 * 1044 wieków Czas działania(2n/109) 0,001s 13 dni 4 * 1011 wieków 5 * 1041 wieków

8 Wniosek: nawet zastosowanie komputera działającego 1000 razy szybciej nie pozwala na wykonanie algorytmu (w rozsądnym czasie).

9 Przykładowy program Module Module1 Sub Main()
Dim BankBalance As Single = If (BankBalance < 0) Then Dim strError As String strError = "Hey, your bank balance is negative!" System.Console.WriteLine(strError) End If End Sub End Module

10 Programowanie w logice
append([ ], X, X). append([H1 | T1], Y, [H1 | T2]) :- append(T1,Y,T2). ?- append([a, b, c], [d, e], X). X = [a, b, c, d, e] ?- append([a, b], X, [a, b, c]). X = [c] ?- append(X, Y, [a, b, c]). X = [ ] Y = [a, b, c] ; X = [a] Y = [b, c] ; X = [a, b] Y = [c] ; X = [a, b, c] Y = [ ] ; no

11 Programowanie funkcyjne
(define (silnia n) if (n = 0) 1 n * (silnia (n-1))) (silnia 5) 120

12 Przykładowe elementy języka
stałe zmienne typy deklaracje instrukcje funkcje i procedury moduły

13 Deklaracje stałych Const name [ As type ] = initexpr Przykłady:
Const Pi = Const m As Integer = 30 identyfikator typ

14 Type Storage size Boolean 2 bytes Byte 1 byte Char Date 8 bytes Decimal 16 bytes Double Integer 4 bytes Long Object Short Single

15 Deklaracje zmiennych Dim name [ As type ] [ = initexpr ] Przykłady:
Dim EmployeeID As Integer = 1 Dim EmployeeName As String = "Bob Owens" Dim EmployeeAddress As String

16 Przykład Module Module1 Sub Main() Dim intVariable1 As Integer = 1234
intVariable3 = intVariable1 + intVariable2 System.Console.WriteLine(intVariable3) End Sub End Module

17 Operatory arytmetyczne
^ Exponentiation * Multiplication / Division \ Integer division Mod Modulus + Addition - Subtraction & + String Concatenation

18 Podstawienia = Assignment ^= Exponentiation followed by assignment
*= Multiplication followed by assignment /= Division followed by assignment \= Integer division followed by assignment += Addition followed by assignment -= Subtraction followed by assignment &= Concatenation followed by assignment

19 Operatory relacyjne < (Less than) True if operand1 is less than operand2 <= (Less than or equal to) True if operand1 is less than or equal to operand2 > (Greater than) True if operand1 is greater than operand2 >= (Greater than or equal to) True if operand1 is greater than or equal to operand2 = (Equal to) True if operand1 equals operand2 <> (Not equal to) True if operand1 is not equal to operand2 Is True if two object references refer to the same object Like Performs string pattern matching

20 And Performs an And operation (for logical operations: True if both operands are True, False otherwise; the same for bit-by-bit operations where you treat 0 as False and 1 as True). Not Reverses the logical value of its operand, from True to False and False to True, for bitwise operations, turns 0 into 1 and 1 into 0. Or Operator performs an Or operation (for logical operations: True if either operand is True, False otherwise; the same for bit-by-bit operations where you treat 0 as False and 1 as True). Xor Operator performs an exclusive-Or operation (for logical operations: True if either operand, but not both, is True, and False otherwise; the same for bit-by-bit operations where you treat 0 as False and 1 as True). AndAlso "short circuited" And operator; if the first operand is False, the second operand is not tested. OrElse "short circuited" Or operator, if the first operand is True, the second is not tested.

21 Priorytety operatorów
Module Module1 Sub Main() Dim intGrade1, intGrade2, intGrade3, _ intNumberStudents As Integer intGrade1 = 60 intGrade2 = 70 intGrade3 = 80 intNumberStudents = 3 System.Console.WriteLine("Average grade = " & _ Str(intGrade1 + intGrade2 + intGrade3/ _ intNumberStudents)) End Sub End Module

22 Priorytety operatorów
Module Module1 Sub Main() Dim intGrade1, intGrade2, intGrade3, _ intNumberStudents As Integer intGrade1 = 60 intGrade2 = 70 intGrade3 = 80 intNumberStudents = 3 'Three students System.Console.WriteLine("Average grade = " & _ Str((intGrade1 + intGrade2 + intGrade3) / _ intNumberStudents)) End Sub End Module


Pobierz ppt "Podstawy programowania (1)"

Podobne prezentacje


Reklamy Google