Lecture 1: Introduction to Programmeringsteknik DT143G PDF

Document Details

SaintlySphene5524

Uploaded by SaintlySphene5524

Örebro University

2024

Pascal Rebreyend

Tags

programming computer science C programming introduction

Summary

This document is a lecture introduction to Programmeringsteknik DT143G, covering topics like course details, staff information, course literature, lectures, labs and criteria to pass. The lecture is delivered at Örebro University in 2024.

Full Transcript

Introduction Programmeringsteknik DT143G Lecture 1: Introduction Pascal Rebreyend 4-11-2024 Pascal Rebreyend Programmeringsteknik DT143G Introduction Today’s contents Practical information Organization of the course...

Introduction Programmeringsteknik DT143G Lecture 1: Introduction Pascal Rebreyend 4-11-2024 Pascal Rebreyend Programmeringsteknik DT143G Introduction Today’s contents Practical information Organization of the course First contact with programming The spirit of the subject Goals of this course Pascal Rebreyend Programmeringsteknik DT143G Introduction Staff and Materials Pascal Rebreyend Course responsible Lectures Office: T2232 Email: [email protected] 2 assistants Laboratories Materials are in BB Learn Pascal Rebreyend Programmeringsteknik DT143G Introduction Course litterature Main book C från Början. Jan Skansholm References Programmeringsmetodik C, Gunnar Joki The C programming Language, Brian W. Kernighan and Dennis M Ritchie Do not forget what is available on the web! Pascal Rebreyend Programmeringsteknik DT143G Introduction Lectures and Labs 15 Lectures (2*45 minutes) 6 labs sessions for each group. (3 big groups) Work in group of 2 Thus, find your teammate. (Groups will be open in Blackboard soon). DEADLINES Pascal Rebreyend Programmeringsteknik DT143G Introduction Criteria to Pass the Course Approved written exam Some questions 50% of points: 3, 70-75% grade 4, 85/90% grade 5 Approved labs: Lab 3,4,5 and 6. Pascal Rebreyend Programmeringsteknik DT143G Introduction Computers and programs Pascal Rebreyend Programmeringsteknik DT143G Introduction Computer Calculations to do Results Calculations are done Pascal Rebreyend Programmeringsteknik DT143G Introduction Computer Primary Unit (RAM,ROM) CPU Control Unit Input Entity Output Entity Arithmetic Logic Unit (ALU) Secondary Memory (Hard Disk) Pascal Rebreyend Programmeringsteknik DT143G Introduction CPU CPU includes: Control Unit: In charge of controlling everything Arithmetic Logic Unit (ALU): A unit whose job is calculating everything Primary Unit (RAM,ROM) CPU Control Unit Input Entity Output Entity Arithmetic Logic Unit (ALU) Secondary Memory (Hard Disk) Pascal Rebreyend Programmeringsteknik DT143G Introduction Primary Memory Primary Memory (RAM,ROM): A place to put information during the time the computer is running ROM: Read Only Memory. Programmed by the manufacturer and cannot be changed. RAM: Random Access Memory. A place to store the date and programs during the time the computer is running. Its contents are gone when computer is switched off. Pascal Rebreyend Programmeringsteknik DT143G Introduction Computers and Input-Output Input Entity: An entity used to input data (keyboard, mouse, sensors,... ) Output Entity: An entity to output the results (screen,... ) Pascal Rebreyend Programmeringsteknik DT143G Introduction Secondary Memory A place to store data when the computer is switched off. Its capacity is much higher than primary memory... but much slower! Pascal Rebreyend Programmeringsteknik DT143G Introduction Computers and Data How data is stored in a computer? by using bits: A bit is either 0 either 1 (binary) 8 bits forms a Byte Be familiar with conversions: 01000110 (byte, base 2) is 70 (decimal, base 10) 46 (Hexadecimal, base 16) can be interpreted as “C” (ASCII) Interpretations of the bytes depends on the context of the data. (text, mp3 files, images,... ) Pascal Rebreyend Programmeringsteknik DT143G Introduction Files On a Hard Drive (or secondary memory in general), data is store in the form of files A file is a sequence of bytes in the memory A file is identified by a name. (like myfile.exe, anotherfile.docx,... ) Folders (called directories too) are used to group and therefore organize files. A folder can contain files and other folders. Pascal Rebreyend Programmeringsteknik DT143G Introduction Program A program is a sequence of instructions telling the computer what to do. The program is loaded in the memory The instructions are executed (run) one by one Every instruction is represented by a set of bytes. Pascal Rebreyend Programmeringsteknik DT143G Introduction Programming Language A computer can only understand (run) programs written in its own machine code (0 and 1) Assembly language: One instruction per line LOAD A ADD B STORE C High level programming language: closer to human language (english). Like C,C++,Java,... Each language has its own rules (syntax) Many languages use similar concepts Pascal Rebreyend Programmeringsteknik DT143G Introduction Developing a program - basic way (C) 1 Write it in a text editor 2 It should be translated (compiled) into a machine so that the computer can understand and run it. A compiler is a program that compile (translate) a program into machine code (or object code). 3 A program may use some other already existing written programs: The new program has to be linked to them. A linker is such program. NOTE 1: Some languages are interpreted and therefore the translation is done line by line NOTE 2: You can also use an Integrated development environment (IDE) to do all the 3 steps above (Visual Studio,... ) Pascal Rebreyend Programmeringsteknik DT143G Introduction C Language High Level language. 1972, Dennis Ritchie Provides high flexibility, Close to hardware (was used first and still to write an Operating System) Widely used for embedded computers Powerful but dangerous and hard if the programmer is not careful enough A great language commonly used Pascal Rebreyend Programmeringsteknik DT143G Introduction Example: Hello world #include int main() { printf("Hello World\n"); } This code print Hello World on the screen/console. Pascal Rebreyend Programmeringsteknik DT143G Introduction Programmming in C 1 Write the program using a text editor 2 Save it as a file such as helloworld.c (The usage is to use the suffix.c for C code) 3 Compile the file 4 If compilation succeeds, an object file will be created (helloworld.o in Linux, helloworld.obj in Windows) 5 You need to use a linker to link the program with other programs 6 If linkage succeeds, an executable program will be generated (a.out in Linux, helloworld.exe in Windows) 7 You can execute it! Pascal Rebreyend Programmeringsteknik DT143G Introduction Programming in C gcc (Gnu Compiler Collection): the most common C compiler on unix/linux gcc will do compilation and linkage in one command. (but you can force it to do it separately, see documentation) IDE exists and other lot of tools (like debugging,... ) But too much functionalities for our purpose: Learning C Pascal Rebreyend Programmeringsteknik DT143G Introduction Explanations #include int main() { printf("Hello World\n"); } We include the file stdio.h (definition of printf) Many functions (like printf) are already defined in the “C standard Library” In fact, some files will be linked (like glibc.o) Pascal Rebreyend Programmeringsteknik DT143G Introduction C programming \n means jump to the next line (carriage return) All C programs should contain main(): This is the starting point (function) of the program Curly braces are used to group code statements in a block Each code statement is ended with a semicolon. White spaces (spaces, tabulations) are not taken into account by the compiler. Pascal Rebreyend Programmeringsteknik DT143G Introduction Variables Programming: we are doing computations We execute some code on some values stored in variables A variable is an allocated space in memory where you can store values A variable has a type: Storage space, how to interpret the bits,... Pascal Rebreyend Programmeringsteknik DT143G Introduction Variables in C A variable has to be declared before being used A type must be specified (int, double, float, char,... ) int a; After we can use it: int a,b; a=5; b=a+1;... Pascal Rebreyend Programmeringsteknik DT143G Introduction A simple example #include int main() { int x; x = 5; printf("The value of x is %d\n", x); return 0; } %d tells printf to write an integer (decimal) number at its position Pascal Rebreyend Programmeringsteknik DT143G Introduction Conclusion C: A must-know language Programming: Practice is needed to be a good programmer. Start ASAP to program (Lab 1) and use tools like gcc, editor with syntax (emacs, Geany, Atom,... ) Skills: C but programming as a general way to solve problems Pascal Rebreyend Programmeringsteknik DT143G

Use Quizgecko on...
Browser
Browser