Computers and Programming CPC The 1 st lecture Jiří Šebesta Complete sources are available on the Web pages:

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Types and Variables. Computer Programming 2 C++ in one page!
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Chapter 2: Introduction to C++.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Chapter Introduction to Computers and Programming 1.
COMPUTER SCIENCE I C++ INTRODUCTION
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Computers and programming The 3 rd lecture Jiří Šebesta.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Input & Output: Console
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Cis303a_chapt03-2a.ppt Range Overflow Fixed length of bits to hold numeric data Can hold a maximum positive number (unsigned) X X X X X X X X X X X X X.
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Engineering Computing I Chapter 1 – Part A A Tutorial Introduction.
Input, Output, and Processing
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept.
Lecture #5 Introduction to C++
Week 1 Algorithmization and Programming Languages.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
By Mr. Muhammad Pervez Akhtar
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1: Introduction to Computers and Programming.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
The Machine Model Memory
Engineering Problem Solving With C An Object Based Approach
BASIC ELEMENTS OF A COMPUTER PROGRAM
ECE Application Programming
Microprocessor Systems Design I
Wel come.
Introduction to C++ Programming
C programming Language
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Presentation transcript:

Computers and Programming CPC The 1 st lecture Jiří Šebesta Complete sources are available on the Web pages:

TOPIC 1.Numeric systems 2.Basic structure of the program 3.Algorithms 4.Variables and data in C language

Numeric systems (1/3) General expression of integer number : Used systems :

Numeric systems (2/3) Used symbols are 0 – 9 and letters from alphabet for systems with basis over 10: e.g. for hexadecimal system: A = 10B = 11 C = 12 D = 13E = 14F = 15 Example for hexadecimal number expression: Hex. number 0x3CF0 represents decimal value: 3 · · · 16 = 15600

Numeric systems (3/3) - storage in memory (generally according to standard IEEE754) S is sign bit (+ = 0; - = 1) E is binary value of exponent M is binary value of mantissa General expression of rational (floating point) number:

Basic structure of the program (1/10) What is a computer program? How to create a computer program? Assembler = readable machine code using name abbreviations derived from instruction meaning, e.g. MOV, INC, ADD, and their operands (name of register, address in memory, numerical constant…

Basic structure of the program (2/10) inserted header files (libraries) #include // precompiled header files #include int main(void)// header of main function { // body of main function char c; // variable declaration printf("ahoj"); // printing fuct. (stdio.h) scanf("%c", &c);// wait until key pressed (stdio.h) return 0; } notices header of main function variable declaration body of function calling of library functions command for comeback from function with return value (0)

Basic structure of the program (3/10) Application solutions in C: CONSOLE APPLICATION (independent on platform) – ANSI C APPLICATION DEPENDENT ON PLATFORM (for given OS with utilize offered functions, for given microcontroller with utilize its peripheral) – extensive libraries, e.g. API, MFC, Active X Integrated Development Environment IDE – complete set of tools for application creation including wizards for project setting, e.g. MS Visual Studio - open source environments, e.g. Code::Blocks or Eclipse or CodeLite (license is not required)

Basic structure of the program (4/10) Code::Blocks – our programming tool Project new project open a previously created project console application = text output in DOS box projects for microcontrollers AVR 8 bits ARM 32 bits

Basic structure of the program (5/10) Compiler language setting

Basic structure of the program (6/10) Project name setting

Basic structure of the program (7/10) Kind of compiler setting GNU – open free software GCC = GNU Compiler Collection

Basic structure of the program (8/10) Debug version vs. release version DEBUG – excellent debugging, final code is not optimized RELEASE – final version – optimized code for distribution

Basic structure of the program (9/10) debugging and executing of an application – menu DEBUG start of debugging, program stops at breakpoints stepping in program including jumps to functions, by Step out given function can be early leaved stepping in program according to the source code without jumps to functions breakpoint inserting to given row (where the cursor actually is placed) Příklad: Ex01.c stop of debugging (program can be in undefined cycle state)

Basic structure of the program (10/10) Where you can obtain Code::Blocks ??

Algorithms (1/6) Algorithms defines a procedure of operations with data Fundamental aspects of algorithm: Finiteness – algorithm consists of elementary steps (of procedure or process), whereas their number must be finite Necessatarianism – algorithm must be punctually and clearly defined Inputs/outputs – algorithm has to defined unambiguous inputs and outputs (data, e.g. given structure of a file) Effectiveness – algorithm must be effective and optimally used system capability (effectiveness in point of view operation time vs. occupation of operation memory or code length)

Algorithms (2/6) Versatility – algorithm has to be able to work with required data set in required range Basic entities of algorithm: Variables Start of algorithm End of algorithm Steps of algorithm Subroutines Conditions (binary relations) Decision making Sequences Cycles Jumps (to use minimally)

Algorithms (3/6) Resources for algorithm definition (description): Lexical – native form: textual (intellectual) guide, order, law – often not too exact definition, then transcription to programming language is impossible Graphical – flowchart – transparent visualization of complex algorithms including branching by using defined flowchart symbols with description and oriented flowlines Symbolic – algorithm description by exactly defined syntax (key word of programming language; meta- language – generative grammar)

Algorithms (4/6) Flowchart - symbols: Algorithm start or algorithm end Common statement Conditional branching Cycle with defined number of repetitions Cycle with condition in the end Cycle with condition in the beginning Manual input (e.g. from keyboard) Output displaying File processing Data saving to a file Subroutine Joiner Oriented flowline

Algorithms (5/6) Program that compute roots of any quadratic equation: ax 2 + bx + c = 0 Read coefficients from keyboard. If roots are complex, print error message. Flowchart - example:

Algorithms (6/6) float a, b, c, y1, y2, r; printf("a = "); scanf("%f", &a); printf("b = "); scanf("%f", &b); printf("c = "); scanf("%f", &c); getchar(); r = b*b-4*a*c; if(r>=0) { y1 = (-b+sqrt(fabs(r)))/(2*a); y2 = (-b-sqrt(fabs(r)))/(2*a); printf("\n 1st root: %.3f", y1); printf("\n 2nd root: %.3f", y2); } else printf("\n Result is not real"); Příklad: Ex02.c

Data and variables (1/15) Data – I (Input), – O (Output), auxiliary (used for internal results) Data sources a targets – file (I/O – binary, text), keyboard (I), console (O), printer (O), communication port (I/O) – e.g. serial port, USB, LPT - often the functions for programming with data sources and targets are defined as functions for files Kind of data (variables) – numerical (integer or rational), characters and strings (string is array of characters terminated by character NULL), arrays (one-dimensional = vectors, multidimensional = matrix, 3D matrix, tensor …), pointer (reference to position in memory), structure (defined encapsulated set of variables with different types)

Data and variables (2/15) Named place in memory with the desired size (in bytes) GLOBAL – valid in whole program LOCAL – valid in body of function (only) Example: Ex03.c // precompiled header files #include // standard inputs and outputs int a = 5; // global variable int main(void) // main function { int b = 10; // local variable char c; printf("global: %d\r\n ", a); printf("local: %d\r\n ", b); scanf("%c ", &c); return 0; }

Data and variables (3/15) Types of variables in ANSI C language – numeric types

Data and variables (4/15) Numeric types – fixed point for integral numbers - unsigned number - storing in memory - signed number - storing in memory

Data and variables (5/15) Example unsigned char (8 bits) Example signed char (8 bits) – standard expression

Data and variables (6/15) Complementary code One is subtracted from absolu- te value of coded number and negated Example for signed char (8 bits) – complementary coded Simpler hardware implementation of ALU

Data and variables (7/15) Numerical floating point types - storage in memory (generally according to IEEE754 standard) S is sign bit E is binary value in exponent M is binary value in mantissa

Data and variables (8/15) Numerical floating point types Float (4 bytes)Double (8 bytes)

Data and variables (9/15) Float (4 bytes)

Data and variables (10/15) Double (8 bytes)

Data and variables (11/15) Types of variables – array Example: Ex04.c #include "stdio.h" int main(void) { int A[5] = {0, 1, 2, 3, 4}; int B[3][2] = {0, 1, 2, 3, 4, 5}; int i,j;char c; for( i=0; i<5; i++) printf("A[%d] = %d\r\n", i, A[i]); B[0][0] = A[4]; for( i=0; i<3; i++) { for( j=0; j<2; j++) printf("B[%d,%d] = %d\r\n", i, j, B[i][j]); } scanf("%c", &c); return 0; }

Data and variables (12/15) String: an array of characters (in memory: 1 byte/character – ASCII coding) NTS (Null Terminated Strings) : the last character of string null – spec. notation v C/C++ ’\0’ Array elements: pointers to characters

Data and variables (13/15) String as an array of ASCII codes of characters in memory:

Data and variables (14/15) Special characters: \b - backspace BS \f - form feed FF (also clear screen) \n - new line NL \r - carriage return CR \t - horizontal tab HT \v - vertical tab (not all versions) \“ - double quotes (not all versions) \' - single quote character ' \\ - backslash character \ \ddd - character ddd, where ddd is an ASCII code given in octal base \xhhh - character hhh, where hhh is an ASCII code given in hexadecimal base

Data and variables (15/15) Types of variables – pointer (= address of variable in memory) Example: Ex05.c #include "stdio.h" int main(void) { float x = 3.14, y = 2.27; float* p; // address of float variable p = &x; // address of x to p *p = y; // content of y on address in p return 0; }

TOPICS OF THE NEXT LECTURE 1.Expressions 2.Arithmetic conversions 3.Operators 4.Statements if-else and for THANK YOU FOR YOUR ATTENTION