CSE101-Lec#2 Programming Methodologies

Slides:



Advertisements
Similar presentations
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Advertisements

1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Program Flow Charting How to tackle the beginning stage a program design.
C programming Language and Data Structure For DIT Students.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
CSC141 Introduction to Computer Programming
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Programming With C.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
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.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
The Hashemite University Computer Engineering Department
Week 1 Lecture 2SE1SA51 Introducing C SE1SA5 Sue Walmsley.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
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.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Chapter 1 Introduction 2nd Semester H
Basics of Computer A Computer is Electronic device that can
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
Unit 3: ALGORITHMS AND FLOWCHARTS
CSCI-235 Micro-Computer Applications
Key Ideas from day 1 slides
C Programming Hardik H. Maheta.
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.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 1: An Overview of Computers and Programming Languages
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
C++ Programming: From Problem Analysis to Program Design
Choice of Programming Language
Visit for more Learning Resources
Unit# 9: Computer Program Development
Chapter 11 Introduction to Programming in C
Programming Fundamentals (750113) Ch1. Problem Solving
1) C program development 2) Selection structure
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
Programming Fundamentals Lecture #3 Overview of Computer Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Programming Fundamentals (750113) Ch1. Problem Solving
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
C programming Language
Introduction to Computer Programming
Programming Fundamentals (750113) Ch1. Problem Solving
Computer Programming-1 CSC 111
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Getting Started With Coding
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

CSE101-Lec#2 Programming Methodologies C Program Development Environment Algorithm and Pseudo code

Outline Program Development in C Structured programming (Algorithm and Pseudocode)

C Program Development Environment A C program must go through various phases such as: Creating a program with editor Execution of preprocessor program Compilation Linking Loading Executing

Editor Disk Preprocessor Compiler Linker Loader CPU Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, Editor Preprocessor Linker   CPU . Disk Primary Memory

C Program Development Environment(cont.) Phase 1: Create your program with an editor program Phase 2: A preprocessor find some preprocessor directives (#include <stdio.h>) to include other files. Phase 3: Compiler compiles the program into machine languages Phase 4: A linker links the object code with the code in library or other places to produce an executable image. Phase 5: A loader loads the executable image into memory (RAM). Phase 6: CPU executes the program one instruction at a time. The load process in Windows OS is just input the name of the executable file.

Program Development Tools Algorithm Flow chart Pseudo-code

Algorithm Quick yak: Various daily routine algorithms can be shared Deciding on an Ice cream out of a lot Chapati selection Algorithm is defined as “ the finite set of steps, which provide a chain of action for solving a problem” It is step by step solution to given problem. Well organized, pre-arranged and defined textual computational module

Characteristics of good Algorithm Correctness - terminates on ALL inputs (even invalid inputs!) and outputs the correct answer. Simplicity - each step of the algorithm performs one logical step in solving the problem. Precision - each step of the algorithm is unambiguous in meaning. Comprehensibility - the algorithm is easy to read and understand. Abstraction - presents the solution steps precisely and concisely without referring to low-level (program code) details. Efficient - Gives results rapidly based on the problem size; does not waste any space or time. Easy to Implement - relatively easy to translate into a programming language.

Steps to create an Algorithm Quick yak: Formulate examples on conversation… Ask a question When would you be 34 years old Let them craft a logic for answer!!! 1. Identify the Inputs What data do I need? How will I get the data? In what format will the data be? 2. Identify the Outputs What outputs do I need to return to the user? What format should the outputs take?

Steps to create an Algorithm 3. Identify the Processes How can I manipulate data to produce meaningful results? Data vs. Information 4. Break the Solution to steps By breaking the solution to the steps we can easily understand the logic of program

Example of Algorithm To establish a telephone communication Step 1: Dial a phone number Step 2: Phone rings at the called party Step 3: Caller waits for the response Step 4: Called party picks up the phone Step 5: Conversation begins between them Step 6: After the conversation, both disconnect the call

Algorithm: Add 2 Numbers Problem: To add two numbers. Step1. Start. Step2. Take the two numbers. Step3. Add them. Step4. Print the result. Step5. Stop.

Pseudocode Pseudocode is similar to everyday English language, its convenient and user friendly It’s not a actual computer programming language. Pseudocode consist only of action statements In pseudocode representation Each of steps will be written via operators and statements equivalent to some programming language instructions. The only difference will be that the exact syntax of the programming language will not be followed.

Pseudo code: Add 2 Numbers Set A = 4. Set B = 2. Calculate Sum = A + B. Print Sum.

Flow Chart Flow Chart is pictorial representation of an algorithm. Whatever we have done in algorithm we can represent it in picture. It is easy to understand. Shows the flow of the instruction

Flow Chart Symbols

Flow Chart: Add 2 Numbers Quick yak: Ask students to draw a flow chart for going to a movie… START TAKE TWO NUMBERS A and B FIND SUM=A+B PRINT SUM STOP

Program in C: Add 2 Numbers #include<stdio.h> void main() { int a=4; int b= 2; int sum; sum=a+b; printf(“Sum is: %d”, sum); } Sum is: 6

Program in C #include<stdio.h> #include<conio.h> int main() { int pr_per_kg = 45; float no_of_kg = 7.5; float t_pr; t_pr = pr_per_kg * no_of_kg; printf(“%f”, t_pr); getch(); } 337.5

Structure of C program

Explanation A simple C program consists of Comments (optional) // /*….*/ Including header files #include<header file name> Functions main function as special function Other user defined functions (optional) Let’s discuss these in detail..

Comments Two forward slashes ‘ // ’ (double forward slashes), are used to write single line comment The next combination ‘ /*……..*/ ’ (forward slash with asterisk) is used for commenting multiple lines These comments are not being executed by compiler * comment can appear anywhere in a program where a white space can appear

Comments Enhances readability of program Real life example C code example //Prog. Name: addition of integers //Another format /*Prog. Name: addition of integers Student Name: Chandra Prakash UID: 11121415 Section: M4571 */ #include<stdio.h> #include<conio.h> int main() { } Fuel consumption: 16.0 L/100 km Carbon fiber engine bonnet Front tyre: 255/35 ZR19

Header files The next two lines are command for including header files These two lines must be included in every C program stdio.h: standard input output header file for functions printf(),scanf(),... and so on conio.h: console input output header file for functions getch()…. and so on Here ‘ # ‘ is called preprocessor directive

Header files Ferrari car as output Real life example C code example Header for tires Header for oil Header for speakers //Sample program #include<stdio.h> //header file for printf() #include<conio.h> //header file for getch() int main() { //stdio.h is providing printf() function printf(“Car is under process”); //conio.h is providing getch() function getch(); } Ferrari car as output Output: Car is under process

Function main() as special function, execution starts from here A program must have a single main() function A program without main() function wont work main() function will call other functions

main function in real life Real life example C code example Before driving the car, we must start the car, a car won’t be driven without starting Similarly our program must have a main function to start a program //Prog. Name: display name #include<stdio.h> #include<conio.h> int main() { printf(“My name is Aman”); getch(); } Starting engine Driving car Output: My name is Aman

Next Class: Components of C Identifier and Keywords Data Type