CS115 Introduction to Programming

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
CSE 105 Structured Programming Language (C)
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Senem Kumova Metin // FALL CS115 Introduction to Programming Inst. Senem Kumova Metin Textbook : A Book on C, A. Kelly.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
BBS Yapısal Programlama (Structured Programming)
Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
By Senem Kumova Metin 1 DATA TYPES. by Senem Kumova Metin 2 DATA TYPE? …… x; // DECLARATION OF VARIABLE X printf(“Do you want to go on? \n”) printf(“Please.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
CS105 INTRODUCTION TO COMPUTER CONCEPTS INTRO TO PROGRAMMING Instructor: Cuong (Charlie) Pham.
Lecture 2 Introduction to C Programming
Chapter 1: Introduction
COSC 120 Computer Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
COMP205 Comparative Programming Languages
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?
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
C programming Language and Data Structure For DIT Students.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Computer Science 101 Introduction to Programming.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
High-Level Programming Languages: C++
CIS Computer Programming Logic
Hello World 2 What does all that mean?.
AS Computing Introduction to Programming. What is a Computer Program? A list of instructions that a computer must work through, in a logical sequence,
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
Chapter 1 Introduction to Computers In this chapter we describe the major components of a computer system and explain how information is represented in.
H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It.
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.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Computer Science 101 Introduction to Programming.
Patrick J. McSweeney MW: 5 – 8:30pm.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Programming Languages
Lecture 1 Introduction Richard Gesick.
CSCI-235 Micro-Computer Applications
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Choice of Programming Language
Hello World 2 What does all that mean?.
Lecture3.
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
C programming Language
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
An Overview of C.
CS105 Introduction to Computer Concepts Intro to programming
Presentation transcript:

CS115 Introduction to Programming Inst. Senem Kumova Metin senem.kumova@ieu.edu.tr Textbook : A Book on C, A. Kelly and I.Pohl Lecture Notes : http://homes.ieu.edu.tr/~skumova/ Office hours : TBA Office : 408 Senem Kumova Metin

WHAT is LANGUAGE ? Senem Kumova Metin

WHAT is PROGRAMMING?? scheduling or performing a task or / and event WHAT is COMPUTER PROGRAMMING?? creating a sequence of steps for a computer to follow in performing a task Senem Kumova Metin

WHAT is a PROGRAMMING LANGUAGE ? A set of rules, symbols, and special words used to construct a computer program Senem Kumova Metin

Programming language rules consist of: Rules of Syntax which specify how valid instructions are written in the language (like natural language rules subject + verb +object ) Rules of Semantics which determine the meaning of the instructions (what the computer will do) (like natural language rules A book has bitten a car ) Senem Kumova Metin

A COMPUTER PROGRAM ? A set of machine instructions which in turn are represented as sequences of binary digits (0001010….111011) The execution sequence of a group of machine instructions is known as the flow of control. Senem Kumova Metin

FLOW OF CONTROL x > 0 print x int x and int y x = y+1 x = y-1 SCENARIO : you have 2 integers : x,y if x is greater than 0 then do x= y+ 1; else do x= y-1; print the value of x int x and int y x > 0 YES NO x = y+1 x = y-1 print x Senem Kumova Metin

Will we write codes in binary ?? SCENARIO : you have 2 integers : x,y if x is greater than 0 then do x= y+ 1; else do x= y-1; print the value of x 000…110001 100010….01 YES NO 1011..0101 10…1010000 100..11100010 Senem Kumova Metin

ASSEMBLY LANGUAGE Assembly language (or assembler code) was our first attempt at producing a mechanism for writing programs that was more palatable to ourselves movl #0x1,n compare: cmpl #oxa,n cgt end_of_loop acddl #0x1,n bra compare end_of_loop: Of course a program written in assembly code, in order to “run”, must first be translated (assembled) into machine code. Senem Kumova Metin

HIGH LEVEL LANGUAGE From the foregoing we can see that assembler language is not much of an improvement on machine code! A more problem-oriented (rather than machine-oriented) mechanism for creating computer programs would also be desirable. Hence the advent of high(er) level languages starts with the introduction of “Autocodes”, and going on to Algol, Fortran, Pascal, Basic, Ada, C, etc. Senem Kumova Metin

PROGRAM PROCESSING A program written in a high level language (source code) can only be run in its machine code equivalent format. SOURCE CODE  MACHINE CODE There are two ways of achieving this: Interpretation, and Compilation Senem Kumova Metin

1. INTERPRETATION Interpretation requires the use of a special program that reads and reacts to source code. Such a program is called an interpreter. During interpretation run-time errors may be detected and “meaningful” error messages produced. Senem Kumova Metin

2. COMPILATION Compilation requires the use of a special program (called a compiler) that translates source code into object code. SOURCE CODE  OBJECT CODE Sometimes various library files must be “linked in” using another special program called a linker, which produces executable code. OBJECT CODE  MACHINE CODE Senem Kumova Metin

LIBRARIES Libraries (in computer programming terms) contain chunks of precompiled (object) code for various functions and procedures that come with a programming language that requires compilation For example functions and procedures to facilitate I/O. Senem Kumova Metin

Why C? Native language of UNIX Standard development language for personal computers Portable (can be moved to other machine !) Powerful set of operators and powerful libraries (some operators: ++,--….) Basis for Java, C++….. Senem Kumova Metin

A SHORT BREAK ! 20 min … Senem Kumova Metin

INTRODUCTION TO C Your First C programs Basic I/O functions : printf / scanf Including libraries Writing comments Defining variables …. if statements Senem Kumova Metin

Learn printf #include <stdio.h> // library file void main(void) { printf("from sea to shining C\n"); } Senem Kumova Metin

Learn printf #include <stdio.h> void main(void) { printf("from sea ”); printf(“to shining C\n"); } Senem Kumova Metin

Learn printf / scanf #include <stdio.h> void main(void) { int x=0; printf(“x= %d”,x); // print x = 0 scanf(“%d”,&x); /* scan the value from screen and assign this value to x */ printf(“%d”,x); } Senem Kumova Metin

Comments /* Ignored part by the compiler */ // Ignored part by the compiler (only this line) void main() { //….. } Senem Kumova Metin

Comments Comments are arbitrary strings of symbols placed between the delimiters /* and */ Comments are not tokens but white spaces for the C compiler a) /* a comment */ c)   /**********    *  a comment *    ************/ b)    /*     * a comment     */ d)  /*************/      /*  a comment */     /*************/ Senem Kumova Metin

Variables and Assignment #include<stdio.h> void main(void) { int kurus; // declarations of variables (int is a keyword, takes integer values) int lira=0; // declaration and initialization of a variable int toplam_kurus; lira =13; // Assignment statement, “=“ is the assignment operator kurus=56; // Assignment printf(“ Money is %d lira %d kurus\n”, lira, kurus); // printf statement toplam_kurus = lira*100+ kurus; printf(“ \n Total kurus is %d kurus\n”, toplam_kurus); // first part of the printf statement is a control string } Senem Kumova Metin

Variables and Assignment OUTPUT: Money is 13 lira 56 kurus Total kurus is 1356 kurus Senem Kumova Metin

The use of #define #include<stdio.h> #define PI 3.14 /* Lines starting with # are called preprocessing directives Preprocessor first changes all occurences of identifier PI to 3.14 */ #include<stdio.h> #define PI 3.14 void main(void) { printf(“PI equals : %f\n”,PI); // %f is used for floating numbers } Senem Kumova Metin

If Statements C CODE SCENARIO/ MISSION : void main() { int x; int y; if( x>0) x=y+1; else x=y-1; printf(“%d”, x); } SCENARIO/ MISSION : you have 2 integers : x,y if x is greater than 0 then do x= y+ 1; else do x= y-1; print the value of x Senem Kumova Metin

if statements int mymaximum( int a , int b) { if(a>b) return a; MISSION : Write a function called mymaximum that gets 2 integer values (as input parameters) and returns back the greater one int mymaximum( int a , int b) { if(a>b) return a; else return b; } Senem Kumova Metin

Functions and if statements #include <stdio.h> int mymaximum(int a, int b); // FUNCTION PROTOTYPE void main(void) { int max, x, y =7; // DECLARE 3 VARIABLES, INITIALIZE Y printf("please give the value for x: "); scanf("%d",&x); // GET THE VALUE OF VARIABLE X max= mymaximum(x,y); // CALL TO THE MYMAXIMUM FUNCTION printf("Maximum = %d",max); // PRINT THE OUTPUT } int mymaximum( int a , int b) // DEFINE SUB-FUNCTION { if(a>b) return a; else return b; } Senem Kumova Metin