Informatik Hefter

55
EDV Written By : Christoper Dewangga Pramudita Internationales Studienkolleg Fachhochschule Kaiserslautern Germany Informatik in W1 -Seite 1 von 45- Christoper /home/website/convert/temp/convert_html/5571f9e3497959916990b04a/d ocument.doc

description

Informatik Hefter

Transcript of Informatik Hefter

Page 1: Informatik Hefter

EDV

Written By :

Christoper Dewangga Pramudita

Internationales Studienkolleg Fachhochschule Kaiserslautern

Germany

Januari, 2010

Informatik in W1 -Seite 1 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 2: Informatik Hefter

EDV

§ 1 EDV

Elektronische Daten Verarbeitung

elektronisch: Die EDV-Anlage enthält eine Vielzahl an elektronischen Bauteilen.Dadurch ist die Verarbeitungsgeschwindigkeit sehr hoch.

Daten sind Informationen, die durch einen Zeichenvorrat dargestellt werden.Zeichen sind:Buchstaben A,a … , Z,zZiffern 0,1,2, … 9Sonderzeichen !,§,$,%,&,?

Welche Daten gibt es?

analoge Daten: Sie lassen sich in kontinuierlicher Form darstellen, d.h. alle möglichen Zwischenwerte sind möglich

Beispiel: analoge Uhr, Fieberthermometer, Tachometer

digitalen Daten: Diese Daten werden nur durch 2 Ziffern dargestellt (0, 1). Man spricht auch von binären Daten

Beispiel: Digitaluhr, Digitalthermometer, Pixel

Was ist Information?

Von Information spricht man, wenn mit der eindeutigen Interpretation der Zeichenkette (string) auch eine Bedeutung verknüpft ist .Beispiel: Lottozahlen

8, 12, 27, 30, 31, 4925

Was ist eine Nachricht?

Als Nachricht wird bezeichnet, wenn Daten oder Information in irgendeiner Form (SMS, Handy, email) vom Ort A nach Ort B übertragen werden.

Was ist Informatik?

ist ein Kunstwort aus Information und Mathematik.

Welche Teildisziplinen gibt es in der Informatik?1. Theoretische Informatik2. Angewandte Informatik3. Technische Informatik4. Praktische Informatik

Informatik in W1 -Seite 2 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 3: Informatik Hefter

EDV

Was ist Hardware? Prozessor, Arbeitsspeicher und weitere Einheiten sind auf einer Platine angeordnet.Eine Platine ist ein Träger aus isolierendem Material mit festen leitenden Verbindungen.

Auf der Hauptplatine (mothherboard) sind die einzelnen Bauteile elektrisch miteinander verbunden. Diese sind:

1. Hauptprozessor (CPU)2. Hauptspeicher (RAM)3. BIOS4. Schnittstellen und Steckplätze für Erweiterungskarten

(Grafikkarte, Soundkarte, TV-Karte)

Zu 1.: Der Prozessor ist das „Herz“ eines Computers.Hauptsbestandteile sind:

Das Rechenwerk (ALU algorithmic logic memory) Register Steuerwerk Speichermanagement (MMU = memory management unit),

das den Arbeitspeicher verwaltet

Informatik in W1 -Seite 3 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 4: Informatik Hefter

EDV

Welche Aufgabe hat der Prozessor ?

Arithmatische Operationen (+-*/,vergleichen<=>) Logische Operationen (und,oder,nicht Lesen und schreiben von Daten in den Arbeitsspeicher Ausführen von Sprüngen im Computerprogramm

Zu 2. :Der Hauptspeicher ( Arbeitsspeicher oder RAM = Random Access Memory ) ist ein Speicher mit wahlfreiem Zugriff, in dem

Datenobjekte, d.h. Programme Zu verarbeitende Nutzdaten

Abgelegt werden.

Die Bezeichnung wahlfrei bedeutet, dass Speicherzellen über ihre Speicheradresse direkt angesprochen werden.

Wie groß ist der Arbeitsspeicher?

Hängt ab von der Rechnerkonfiguration, z.B.

Pentium Prozessor ist 32 bit-System, d.h.es können 2³²-Speicherzellen adressieert werden, also 2³² ByteUmrechnung:2³² Byte = 2³² Byte/1024 = 9194304 KB = 4096 MB = 4 GB

Ein RAM ist ein flüchtiger Speicher, d.h. alle Daten werden gelöscht, sobald der Strom ausgeschaltet wird.

Zu 3. :Als BIOS ( basic input output system) bezeichnet man eine Firmware bei x86-PCs.

Die Firma Intel ist der bekannteste Chiphersteller. Die Chips werden nummeriert:

80 86

Informatik in W1 -Seite 4 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

RegisterSpeichermanagement

Page 5: Informatik Hefter

EDV

80286 80386 80486 Pentium Pentium 1 bis Pentium 3 Core 2 Duo

Aus technischer Sicht handelt es sich beim BIOS um ein Programm, das in einem nichtflüchtigen Speicher(ROM = read only memory) auf der Hauptplatine des PCs abgelegt ist und das unmittelbar nach dessen Einschaltung ausgeführt wird (booten = laden)

Zu 4.:Das motherboard (Platine) ist elektrisch mit der internen Festplatte ( HDD = hard drive disk) verbinden.

Der Abstand zwischen Schreib-Lese-Kopf und Platte liegt bei 10 nm

10 nm = 10*10-9m = 10-8m = 10-5mm

Zum Vergleich : Ein Haar ist etwa 0,05mm = 5*10-2mm dick. Die Herstellung von Festplatten erfolgt deshalb in sog. Reinräumen.

Aufbau einer Festplatte: Die Festplatte enthält mehrere konzentrisch gelagerte Platten, die mit einer magnetischen

Schicht überzogen sind. Die Rotationsgeschwindigkeit beträgt 5000 bis 10000 UPM

UPM = Umdrehungen pro Minute Die Speicherkapazität liegt bei 1000 GB

Informatik in W1 -Seite 5 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 6: Informatik Hefter

EDV

weitere externe Speichermedien: DVD USB-stick Externe Festplatte Magnetband

Bei der von Neumann Architektur ist ein Bus ein System, das Daten zwischen den Computerbestadteilen überträgt.Wir unterscheiden folgende interne Busarten:

Datenbus:Er überträgt Daten zwischen dem Rechenwerk und dem RAMund der Ein- und Ausgabe.

AdressbusEr überträgt Adressen an den Arbeitsspeicher

SteuerbusEr koordiniert den Informationsfluß

Ein externer Bus ist eine Verbindung zwischen CPU, RAM und der Außenwelt (Drucker,Monitor,...)

Serieller Bus (bitweise Übertragung)

Paralleler Bus

hier werden mehrere bits gleichzeitig übertragen

§ 2 Darstellung von Information

Daten im alltäglichen Leben

Ziffern 10 Buchstaben 60 Sonderzeichen ($ § % & ? ) 70

---------Summe 140 Zeichen

Diese Daten werden im Computer digital dargestellt, d.h. in Form von 0 und 1

Informatik in W1 -Seite 6 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 7: Informatik Hefter

EDV

1 bit ist kleinste Information.

bit = binary digit

Frage: Wie viele Zustände lassen sich mit 1 bit darstellen ?

2 ZuständeAllgemein:

Mit n bits lassen sich 2n. Zustände darstellen.

Um alle 140 Zeichen darstellen zu können, sind 8 bits notwendig

1 BYTE entspricht 8 bits.

§ 2.1 Zahlensysteme

Dezimalsystem (Basis = 10, 10 Ziffern)

145(10) = 1*102* + 4*101 + 5*100..

Dualsystem oder Binärsystem ( Basis = 2, Zeichen 0 und 2)

Bespiel:

111(2) =1*102* + 4*101 + 5*100...= 7(10)

Oktalsystem (Basis = 8 Ziffern = 0 bis 7)

145(8) = 1*82* + 4*81 + 5*80 = 64+ 32+5 = 101(10)

Hexadezimalsystem (Basis = 16 Ziffern = 0 bis 9, A, B, C, D, E, F)

145(16) = 1*162* + 4*161 + 5*160..=..256 + 64+5 = 325(10)

Informatik in W1 -Seite 7 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Stellenwert Basis

Page 8: Informatik Hefter

EDV

§ 2.2 Umrechnungen

Dezimal in dualBeispiel: 25(10) = ..............(2)

Wir benutzen die Ganzahldivision. Rest25 / 2 = 12 112 / 2 = 6 06 / 2 = 3 03 / 2 = 1 11 / 2 = 0 1

25(10) = 11001(2)

Beispiel: 2009(10) = ………….(2)

2009 / 2 = 1004 11004 / 2 = 502 0502 / 2 = 251 0251 / 2 = 125 1125 / 2 = 62 162 / 2 = 31 031 / 2 = 15 115 / 2 = 7 17 / 2 = 3 13 / 2 = 1 11 / 2 = 0 1

2009(10) = 0111 1101 1001(2)

Dezimal in Hexadezimal

Beispiel: 25(10) = ..............(16)

25 / 16 = 1 99 / 16 = 0 1

25(10) = 19(19) = 1*161 + 9*160

Beispiel: 2009(10) = ……………….(2)

Informatik in W1 -Seite 8 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 9: Informatik Hefter

EDV

0111 1101 1001(2)

7 13 9 7 D 9(16)

135.(16) = 1000 0111(2) = 87 (16)

8 7

Verwandeln Sie bis MONTAG, 19.10. AFFE in das Dualsystem FABC in das Dezimalsystem 10 1111 0000 1100 1010

a) In das Hexadezimalsystemb) In das Dezimalsystem

§ 3 Codierung (= Verschlüsselung)

Morse Code

SOS = Save our Souls = rettet unsere Seelen

ASCII Code american standard code of information interchange

Damit lassen sich 27 Zeichen darstellen (7 bit Code). Dieser Code wurde auf 8 bit erweitert, um alle regionalen Zeichen darzustellen.

EBCDI-Code in IBM Rechner für Grossrechner

UNICODE gilt für das Betriebssystem WINDOWSist ein 16 bit Code, d.h. es lassen sich 216

(= 65536 Zeichen) darstellen

§ 4 Darstellung von Zahlen im PC

Wenn ich die Zeichnen ,’4’ und ‚’3’im PC eingebe, dann da wird wie folgt codiert

’4’ und ‚’3’ 0011 0100 und 0011 0011

Die Zahl 43 wird als Rechnengrösse wie folgt dargestellt:

Informatik in W1 -Seite 9 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 10: Informatik Hefter

EDV

0011 1011

Man unterscheidet:

ganze Zahlen ( integer Zahlen) Gleitkommazahlen ( floating point numbers) π = 3,1415....

Diese Zahlen werden im Rechner unterschiedlich dargestellt.

§ 4.1 Darstellung von ganzen Zahlen

wir unterscheiden:

vorzeichen ganze Zahlen 3, 25, 123 ganze Zahlen mit Vorzeichen -21, +67, -234

Vereinbarung: wir haben einen 16 bit Rechner

vorzeichen ganze Zahlen

0(0) = 0000 0000 0000 0000 01(10) = 0000 0000 0000 0001 12(10) = 0000 0000 0000 0010 23(10) = 0000 0000 0000 0011 34(10) = 0000 0000 0000 0100 45(10) = 0000 0000 0000 0101 56(10) = 0000 0000 0000 0110 67(10) = 0000 0000 0000 0111 78(10) = 0000 0000 0000 1000 89(10) = 0000 0000 0000 1001 910(10) = 0000 0000 0000 1010 10

usw

65535(10) = 1111 1111 1111 1111 FFFF

Die großte darstelbare Zahl mit N bits ist 2n - 1

Informatik in W1 -Seite 10 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

DualHexadezimal

Dezimal

Page 11: Informatik Hefter

EDV

ganze Zahlen mit Vorzeichen

Das höchstwertige bit das Vorzeichen an . 0 für positive Zahlen. 1 für negative Zahlen

Beispiel: +25(10) = 11001

Beispiel für eine negative Zahl:-105(10) = ?????????????????????

Um eine negative Zahl in das Dualsystem umzurechnen, bildet man das Zweierkomplement

+105(10) = 0000 0000 0110 1001Einerkomplement 1111 1111 1001 0110

addiere 1 1-----------------------------

Zweierkomplement 1111 1111 1001 0111

Zahlenbereich im 16 bit Rechner

§ 4.2 Gleitkommazahlen

Merke: Gleitkommazahlen ( floating point numbers ) können in einem Rechner nur bis zu einer bestimmten Genauigkeit dargestellt werden, z.B. in einem 32 bit Rechner können nur 23 Nachkommastellen exakt dargestellt werden.

1/3 = 0,33333333333333333333333 3333333333333333333333333333333

V E x p o n e n t M a n t i s s e31 23 0

Beispiel: 5,25(10) = (2)

Informatik in W1 -Seite 11 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1

zeigt, dass die Zahl negativ ist

-32768 327670

-105

Page 12: Informatik Hefter

EDV

5,25(10) = 5 + 0,25 = 101. + ???.

Übertrag0,25 * 2 = 0,5 00,50 * 2 = 1,0 10,00 * 2 = 0,0 0

Beispiel: 0,35(10) = 01 (2)

= 0*2-1 + 1*2-2 + 0*2-3 + 1*2-4 + 1*2-5 + 0*2-6 + ….= 1/4 + 1/16 + 1/32= (8 + 2 + 1) / 32= 11/32= 0,34375

§ 4.3 Gleitkommazahlen im 32 bit Rechner

Reelle Zahlen z werden näherungsweise durch die Dualzahlen m und e dargestellt, wobei gilt:

z = m*2e

m heißt Mantisse

e heißt Exponent

z = 10011 * 2101 = 19 * 25 = 19 * 32 = 608

z = 101.110 * 2101 = (1 * 22 + 0 * 21 + 1 * 20 + 1 * 2-1 + 0 * 2-2 + 1 * 2-3 ) * 25 = . = (4 +0 + 1 + 1/2 + 1/4 ) * 25

. = (5 +3/4) * 25

. = 5.75 * 25

. = 5.75 * 32

. = 184(10)

Umwandlung einer Gleitkommazahl in eine Dualzahl

Beispiel:

Beispiel: 0,35(10) = 01 (2)

= 0*2-1 + 1*2-2 + 0*2-3 + 1*2-4 + 1*2-5 + 0*2-6 + ….= 1/4 + 1/16 + 1/32

Informatik in W1 -Seite 12 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 13: Informatik Hefter

EDV

= (8 + 2 + 1) / 32= 11/32= 0,34375

absoluter Fehler: 0,35(10) - 0,34375 = 0,00625relativer Fehler: 0,00625/0,35 = 0,017857. . .prozentualer Fehler 1,786 %

Beispiel: 11,625(10) = 11 + 0,625 = 1011.101(2)

1. Schritt: Normalisierung

1011.101(2) = 1.011101 * 13

2. Schritt: Charakterisierung

CH = e + ke heißst Exponentk ist eine Konstante

k = 2E -1 -1

E gibt die Anzahl von bits an für den ExponentenE = 8 bits für einen 32-bit RechnerE = 16 bits für einen 64-bit Rechner

damit gilt für einen 32 bit Rechner

k = 28 -1 - 1k = 27 - 1 k = 127 für einen 32 bit Rechner

.damit gilt für E in unserer Aufgabe

1.011101 * 23

CH = e + k = 3 + 127 = 130(10) = 1000 0010(2)

Bestimmung der Mantisse m :1.011101 * 23

m = 011101

Informatik in W1 -Seite 13 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 14: Informatik Hefter

EDV

+11,625(10) = 1011.101(2)= 1.011101 * 23

0 1 0 0 0 0 0 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Beispiel: -234,65(10) = -(234 + 0,65) = ????

1 1 0 0 0 0 1 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 031

ENDE DES 1: TEILS DER VORLESUNG

Wir wissen jetzt:

Aufbau eines Rechners Darstellung von Zeichen ( ASCII-Code ) Darstellung von ganzen Zahlen ( integer-Zahlen )

a) positive Zahlenb) negative Zahlen ( Zweierkomplement )

Darstellung von Flieskommazahlen im 32-bit-Rechner

§ 5 Einführung in eine programiersprache

Algol, C, visual Basic, Pascal sind prozedurale Sprachen

delphi, JAVA, C++ sind objektorientiert

Informatik in W1 -Seite 14 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 15: Informatik Hefter

EDV

z.B: C++ des Befehls :

/****************************Internationales StudienkollegKaiserslauternGermany*****************************/

#include <iostream> //sharp #using namespace std ; // point virgule, Semikolon

int main (void){ cout<< " internationales Studienkolleg "; cout<< "Kaiserslautern"; cout<< "Germany";

return 0 ;

}

Informatik in W1 -Seite 15 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 16: Informatik Hefter

EDV

z.B: C++ des Befehls 2 :

/******************************************** Integer Operation

+ - * Ganzzahldivision Restdivision********************************************/

#include <iostream> using namespace std ;

int main(){

// VARIABLENDEKLARATION

int zahl1, zahl2,summe,differenz,ganzDiv,rest ;

// EINGABE

cout<< "Erste Zahl eingeben ";cin >> zahl1;

cout<< "Zweite Zahl eingeben ";cin >> zahl2;

// Verarbeitung

summe = zahl1 + zahl2; // Zuweisungsoperator

// AUSGABE

cout << summe ;

cout <<"\n\n\n\n\n\n";

return 0;

Informatik in W1 -Seite 16 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 17: Informatik Hefter

EDV

}

/******************************************** Integer Operation

+ - * Ganzzahldivision Restdivision********************************************/

#include <iostream> using namespace std ;

int main(){

// VARIABLENDEKLARATION

int zahl1,zahl2,summe,produkt,differenz,ganzDiv,rest ;

// EINGABE

cout<< "Erste Zahl eingeben ";cin >> zahl1;

cout<< "Zweite Zahl eingeben ";cin >> zahl2;cout<< "\n\n\n\n\n";

// Verarbeitungsumme = zahl1 + zahl2;differenz = zahl1 - zahl2 ;produkt = zahl1 * zahl2 ;ganzDiv = zahl1 / zahl2 ;rest = zahl1 % zahl2 ;

// AUSGABE

cout << "SUMME = " << summe << endl ;cout << "DIFFERENZ = " << differenz << endl ;cout << "PRODUKT = " << produkt << endl ;cout << "DIVISION = " << ganzDiv << endl ;

Informatik in W1 -Seite 17 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 18: Informatik Hefter

EDV

cout << "REST = " << rest << endl ;

cout <<"\n\n\n\n\n";

return 0;

}

/******************************************** Berechnung der Anzahl Kisten

********************************************/

#include <iostream> using namespace std ;

int main(){

// KONSTANTE

const int max_Anzahl = 115;

// VARIABLENDEKLARATION

int n, anzahlFahrten, uebrigeKisten ;

// EINGABE

cout<< "Anzahl der Kisten eingeben: ";cin >> n;

// Verarbeitung

// AUSGABE

cout <<"\n\n\n\n\n\n";

return 0;

}

Informatik in W1 -Seite 18 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 19: Informatik Hefter

EDV

return 0;

}

/****************************

Finanzberechnung: Verzinsung innerhalb eines Jahres

Aufgabe 1

****************************/

#include <iostream> using namespace std ;

int main(){

// VARIABLENDEKLARATION

double anfKap, zinsen, endKap; //entweder floatdouble zinsSatz; // oder doubleint tage, mon;

// EINGABE

cout<< "Anfangskapital eingeben\t=\t ";cin >> anfKap;

cout<< "Zinssatz eingeben\t=\t ";cin >> zinsSatz;

cout<< "Monate eingeben\t=\t ";cin >> mon;

cout<< "Tage eingeben\t=\t ";cin >> tage;

Informatik in W1 -Seite 19 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 20: Informatik Hefter

EDV

cout <<"\n\n\n\n\n\n";

// Verarbeitungtage = tage + mon * 30;zinsen = anfKap * zinsSatz/100 * tage / 360 ;endKap = anfKap + zinsen;

// AUSGABE

cout << "Zinsen = " << zinsen << endl;

cout << "Endkapital = " << endKap << endl;

return 0;

}

Informatik in W1 -Seite 20 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 21: Informatik Hefter

EDV

/****************************

Finanzberechnung: Verzinsung mehr als eines Jahres

Aufgabe 2

****************************/

#include <iostream>#include <cmath> using namespace std ;

int main(){

// VARIABLENDEKLARATIONdouble anfKap, zinsen, endKap; //entweder floatdouble zinsSatz; // oder doubleint jahre;

// EINGABEcout<< "Anfangskapital eingeben\t=\t ";cin >> anfKap;

cout<< "Zinssatz eingeben\t=\t ";cin >> zinsSatz;

cout<< "Jahre eingeben\t=\t ";cin >> jahre;

cout <<"\n\n\n\n\n\n";

// Verarbeitung

endKap = anfKap * pow((1+ zinsSatz/100),jahre);zinsen = endKap - anfKap;

// AUSGABE

cout << "Zinsen = " << zinsen << endl;

cout << "Endkapital = " << endKap << endl;

return 0;}

Informatik in W1 -Seite 21 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 22: Informatik Hefter

EDV

2 Semester

Übung 1 : HELLO World !!!

#include <iostream>

int main (){

std::cout << "Hello world! \n";return 0;

}

Übung 2 : Produkt !!!

/* Berechnet das Produkt zweier Zahlen *//* Dieser Kommentarkann mehrzeilig sein */// Dieser Kommentar ist einzeilig

#include <iostream> // #include-Direktive

int produkt(int x, int y); // Funktionsprotoyp

int a, b, c; // Variablendefinition

int main() // Hauptfunktion{

/* Erste Zahl einlesen */std::cout << "\n Geben Sie eine Zahl zwischen 1 und 100 ein: "; // Anweisungstd::cin >> a; // Anweisung

/* Zweite Zahl einlesen */std::cout << "\n Geben Sie einen weitere Zahl zwischen 1 und 100 ein: "; // Anweisungstd::cin >> b; // Anweisung

/* Produkt berechnen */c = a * b; // Anweisungstd::cout << "\n Ergebnis: " << c << "\n"; // Anweisung

return 0;

Informatik in W1 -Seite 22 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 23: Informatik Hefter

EDV

}

int produkt(int x, int y) // Beginn der Funktionsdefinition{

return (x * y) ; // Anweisung

} // Ende der Funktionsdefinition

#include <iostream>

int ganze_zahl;float gleitkomma_zahl;const int eine_konstante = 3;

int main(){

ganze_zahl = 1;gleitkomma_zahl = 1.62;std::cout << "\n\n Eine ganze Zahl: " << ganze_zahl << "\n";std::cout << "\n Eine Gleitkommazahl: " << gleitkomma_zahl << "\n";

std::cout << "\n Ein int belegt " << sizeof(int) << " Bytes \n";std::cout << "\n Ein long belegt " << sizeof(long) << " Bytes \n";std::cout << "\n Ein double belegt " << sizeof(double) << " Bytes \n";

return 0;}

Informatik in W1 -Seite 23 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 24: Informatik Hefter

EDV

# include <iostream> // Hier wird eine include-Datei eingefügt.float radius, umfang; // Hier werden Variablen definiert.const double PI = 3.142; // hier wird eine Konstante definiert

float umfang_berechnen(float radius);

int main() // Hauptfunktion, muss in jedem C++-Programm vorhanden sein{

/* der Benutzer wird aufgefodert , den Kreisradius einzugeben. Dann wird der Wert eingelesen. */std::cout << "\n Geben Sie den Kreisradius ein: "; // Anweisungstd::cin >> radius; // Anweisung

umfang = umfang_berechnen(radius); // Anweisung ( Funktionsaufruf )

std::cout << "\n Der Kreisumfang betraegt: " << umfang << "\n"; // Anw.

return 0; // Anweisung ( Ende des Hauptprogramms )}

/* Funktion gibt Kreisumfang zurück */float umfang_berechnen(float radius) // Beginn der Funktionsdefinition{ return (2 * PI * radius); // Anweisung} // Ende der Funktionsdefinition

Informatik in W1 -Seite 24 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 25: Informatik Hefter

EDV

Vergleichenübungen :

#include <iostream>

double zahl_1, zahl_2;

int main (){

std::cout << "\nZahlenwerte fuer die Variablen Zahl_1 eingeben = ";std::cin >> zahl_1 ;

std::cout << "\nZahlenwerte fuer die Variablen Zahl_2 eingeben = ";std::cin >> zahl_2 ;

std::cout << " \nDer Vergleich eingeben = " << (zahl_1 < zahl_2);

std::cout << " \n\n\n\n\n " ;

return 0;

}

Informatik in W1 -Seite 25 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 26: Informatik Hefter

EDV

Bei Lehrer Vergleichungenlösung

#include <iostream>

double zahl_1, zahl_2;

int main (){

std::cout << "\n\nBitte geben Sie ene Zahl ein : ";std::cin >> zahl_1 ;

std::cout << "\n\nBitte geben Sie weitere Zahl ein :";std::cin >> zahl_2 ;

std::cout << " \n\nDer Vergleich (zahl_1 < zahl_2) ergibt : ";std::cout << (zahl_1 < zahl_2) ;std::cout << " \n\n\n\n\n " ;

return 0;

}

Informatik in W1 -Seite 26 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 27: Informatik Hefter

EDV

Wurzel Anweisungen Übung

#include <iostream>#include <cmath>

double eingabe_zahl;double wurzel;

// double eingabe_zahl, wurzel ;

int main(){

std::cout << "\nProgramm zur Wurzelberechnung \n";

std::cout << "\nBitte geben Sie eine Zahl ein: ";std::cin >> eingabe_zahl ;

if (eingabe_zahl >= 0){wurzel = sqrt (eingabe_zahl);std::cout << "\nErgebnis: " << wurzel << "\n" ;

}else{std::cout << "\nWurzel negativer Zahl kann nicht berechnet werden. \n";}

std::cout << "\n\n\n\n" ;

return 0;

}

Informatik in W1 -Seite 27 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 28: Informatik Hefter

EDV

Übung Vergleichen bei lehrerin

#include <iostream>

double zahl_1, zahl_2;

int main(){

std::cout << "\nZahlen vergleichen mit if-Anweisung\n\n";

std::cout << "\nBitte geben Sie zahl_1 ein: ";std::cin >> zahl_1;

std::cout << "\nBitte geben Sie zahl_2 ein: ";std::cin >> zahl_2;

if (zahl_1 == zahl_2){

std::cout << "\n\nzahl_1 und zahl_2 sind gleich. \n\n";}

if (zahl_1 > zahl_2){

std::cout << "\nzahl_1 ist groesser als zahl_2. \n\n";}

if (zahl_2 > zahl_1){

std::cout << "\nzahl_2 ist groesser als zahl_1. \n\n";}

return 0;}

Informatik in W1 -Seite 28 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 29: Informatik Hefter

EDV

Übung Vergleichen bei mir

#include <iostream>

int zahl_1 , zahl_2;

int main(){

std::cout << "\nBitte geben Sie erste Zahl ein :\n";std::cin >> zahl_1 ;

std::cout << "\nBitte geben Sie zweite Zahl ein: \n";std::cin >> zahl_2 ;

if (zahl_1 == zahl_2){std::cout << " \nZahl_1 und Zahl_2 sind gleich = ";std::cout << (zahl_1 == zahl_2);}

if (zahl_1 > zahl_2){std::cout << " \nZahl_1 ist groesser als Zahl_2 = ";std::cout << (zahl_1 > zahl_2);}

if (zahl_2 > zahl_1){std::cout << " \nZahl_2 ist groesser als Zahl_1 = ";std::cout << (zahl_2 > zahl_1);}

std::cout << "\n\n\n\n" ;

return 0;

}

Informatik in W1 -Seite 29 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 30: Informatik Hefter

EDV

Übung Anweisungen-If

#include <iostream>

int zahl_1 , zahl_2;

int main(){

std::cout << "\nZahlen vergleichen mit if-Anweisung\n\n";

std::cout << "\nBitte geben Sie erste Zahl ein :\n";std::cin >> zahl_1 ;

std::cout << "\nBitte geben Sie zweite Zahl ein: \n";std::cin >> zahl_2 ;

if (zahl_1 == zahl_2){std::cout << " \nZahl_1 und Zahl_2 sind gleich ";}

else {

if (zahl_1 > zahl_2){std::cout << "\n\n zahl_1 ist groesser als zahl_2. \n\n";

}

else {std::cout << "\n\n zahl_2 ist groesser als zahl_1. \n\n";

}

}return 0;

Informatik in W1 -Seite 30 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 31: Informatik Hefter

EDV

}

Logische Operatoren bei mir

#include <iostream>using namespace std;

int main (){

double zahl;std::cout << "\n\nzahl eingeben : " ;std::cin >> zahl ;

if ((zahl>1) && (zahl<20)){

std::cout << "zahl zwischen 1 und 20 ";}else {

if (zahl<1){std::cout << " zahl ist kleiner als 1 " ;

}else cout << "zahl ist groesser als 20";

}return 0;

}

Informatik in W1 -Seite 31 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 32: Informatik Hefter

EDV

Logische bei Lehrerin

#include <iostream>

double zahl;

int main(){

std::cout << "Bitte geben Sie eine Zahl ein: ";std::cin >> zahl;

if ((zahl >= 1) && (zahl <= 20)){

std::cout << "\nZahl liegt zwischen 1 und 20.\n\n";}else if (zahl < 1){

std::cout << "\nZahl ist kleiner als 1.\n\n";}else{

std::cout << "\nZahl ist groesser als 20.\n\n";}

return 0;}

Informatik in W1 -Seite 32 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 33: Informatik Hefter

EDV

While Anweissung :

#include <iostream>

int main(){

int i; //Zählvariablei = 1;

while (i<=10) // Schleifenbedingung{

std::cout << i << "\n";i++;

}

// Nach Ende dieser Schleife hat i den Wert 10 (i = 10;)

i = 10;std::cout << "\n";

while (i > 0){

std::cout << i << "\n";i--;

}

return 0;

}

Informatik in W1 -Seite 33 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 34: Informatik Hefter

EDV

While und For function:

#include <iostream>

int main(){

int i; // Zählvariablei = 1; // Initialisierung

while (i<=10) // Schleifenbedingung{

std::cout << i << "\n";i++; // Inkrementierung

}

// Nach Ende dieser Schleife hat i den Wert 10 (i = 10;)

i = 10;std::cout << "\n";

while (i > 0){

std::cout << i << "\n";i--;

}

std::cout << "\n\n";

// for-Schleifefor (i = 1; i <= 10; i++) // Schleifenkopf. mit Initialisierung.

// Bedingung und Inkrementierung

{std::cout << i << "\n";

}

return 0;

Informatik in W1 -Seite 34 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 35: Informatik Hefter

EDV

}

#include <iostream>using namespace std;

int main(){

int i; // Zählvariablei = 0; // Initialisierung

while (i<=20) {

cout << i << "\n";i += 2;

}

std::cout << "\n\n";

for (i=19; i >= 1; i-=3) {

cout << i << "\n";

}

return 0;

}

Informatik in W1 -Seite 35 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 36: Informatik Hefter

EDV

Uebungsprogramm Modulo

#include <iostream>Using namespace std;

int main (){

int zahl;

cout << "Bitte Zahl eingeben: ";cin >> zahl;

while ((zahl%3)==0){

cout << "\n Zahl ist durch 3 teilbar. Bitte naechste Zahl eingeben : ";

cin >> zahl;}cout << "\n Zahl ist nicht durch drei teilbar. Programmende.\n\n";

return 0;}

Informatik in W1 -Seite 36 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 37: Informatik Hefter

EDV

Übung Ablaufdiagramm

#include <iostream>

int main(){

int i;

// Möglichkeit 1: for-Schleifefor(i = 5; i < 11; i++){

std::cout << "\n" << i;}

/*// Möglichkeit 2: while-Schleife

i = 5;while (i < 11){

std::cout << "\n" << i;i++;

}

*/std::cout << "\n\nProgrammende\n\n";

}

Informatik in W1 -Seite 37 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 38: Informatik Hefter

EDV

Uebung Primzahl

#include <iostream>

using namespace std ;

int main (){

int zahl, teiler;

cout << "\nBenutzer eingabe : " ;cin >> zahl;

for (teiler=2; teiler<=(zahl-1); teiler++){

if((zahl%teiler)==0){cout << " keine Primzahl teilbar durch "<< teiler ;

}

else{cout << "\nZahl nicht teilbar durch " << teiler ;

}}

cout << "\n\n" ;

return 0;}

Informatik in W1 -Seite 38 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 39: Informatik Hefter

EDV

Übung Primzahl 2

#include <iostream>using namespace std ;

int zahl, teiler;bool ist_primzahl;

int main (){

cout << "\nBenutzer eingabe : " ;cin >> zahl;

ist_primzahl = true; // Statusvariable ( Annahme: Die Zahl ist eine Primzahl )

for (teiler=2; teiler<=(zahl-1); teiler++){

if((zahl%teiler)==0){cout << "\nkeine Primzahl: Zahl teilbar durch "<< teiler ;ist_primzahl = false; // Passender Teiler gefunden. ( Annahme : Zahl ist keine

Primzahl )

}

else{cout << "\nZahl nicht teilbar durch " << teiler ;}

}

if (ist_primzahl){

cout << "\nDie Zahl ist eine Primzahl.";}

else

Informatik in W1 -Seite 39 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 40: Informatik Hefter

EDV

{cout << "\nDie Zahl ist nicht eine Primzahl.";

}

cout << "\n\n" ;

return 0;}

Primzahl_3 ( programm Prim_zahl verbesserung )

#include <iostream>

using namespace std;

int zahl, teiler;bool ist_primzahl;

int main(){

cout << "Bitte Zahl eingeben: ";cin >> zahl;

ist_primzahl = true; // Statusvariable (Annahme: Die Zahl ist eine Primzahl)

// Das Programm könnte noch weiter verbessert werden, wenn die// Bedingung weiter ändertfor (teiler = 2; (teiler <= (zahl/2)) && ist_primzahl; teiler++) {

if ((zahl % teiler) == 0){

cout << "\nKeine Primzahl: Zahl teilbar durch " << teiler;ist_primzahl = false; // Passender Teiler gefunden, Zahl ist keine Primzahl)

}else{

cout << "\nZahl nicht teilbar durch " << teiler;}

}

if (ist_primzahl){

cout << "\n\nDie Zahl ist eine Primzahl.";}

Informatik in W1 -Seite 40 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 41: Informatik Hefter

EDV

else{

cout << "\n\nDie Zahl ist keine Primzahl.";}

cout << "\n\n";

return 0;}

Effezierte Primzahl bei Lehrerin

#include <iostream>

using namespace std;

int zahl, teiler;bool ist_primzahl;

int main(){

for (zahl = 2; zahl <= 100; zahl++){

ist_primzahl = true; // Statusvariable (Annahme: Die Zahl ist eine Primzahl)

// Das Programm könnte noch weiter verbessert werden, wenn die

// Bedingung weiter ändertfor (teiler = 2; (teiler <= (zahl/2)) && ist_primzahl; teiler++) {if ((zahl % teiler) == 0){

ist_primzahl = false; // Passender Teiler gefunden, Zahl ist keine Primzahl)

}}

if (ist_primzahl){cout << "\n" << zahl;

}}cout << "\n\n";

Informatik in W1 -Seite 41 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 42: Informatik Hefter

EDV

return 0;}

Primzahl mit Funktion

#include <iostream>using namespace std;

// Haupt Funktion// Funktionsprototyp ;bool primzahl_test ( int zahl ) ;

int main(){

bool status;int ganze_zahl ;for (ganze_zahl = 2; ganze_zahl <= 100; ganze_zahl++){

// Funktionsaufruf ;status = primzahl_test(ganze_zahl);

if (status){

cout << "\n" << ganze_zahl;}

}cout << "\n\n";

return 0;}// Neben Funktionbool primzahl_test ( int zahl ) {

bool ist_primzahl;int teiler ;ist_primzahl = true; // Statusvariable (Annahme: Die Zahl ist eine Primzahl)

// Das Programm könnte noch weiter verbessert werden, wenn die

Informatik in W1 -Seite 42 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 43: Informatik Hefter

EDV

// Bedingung weiter ändertfor (teiler = 2; (teiler <= (zahl/2)) && ist_primzahl; teiler++) {

if ((zahl % teiler) == 0){

ist_primzahl = false; // Passender Teiler gefunden, Zahl ist keine Primzahl)

}}return ist_primzahl ;

}

muss druecken :1. Ctrl + F7 = Erstellen kompalieren von text2. Ctrl + F5 = Erstellen ausführen von text

Informatik in W1 -Seite 43 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc

Page 44: Informatik Hefter

EDV

Informatik in W1 -Seite 44 von 45- Christoper

/tt/file_convert/5571f9e3497959916990b04a/document.doc