1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Computing for management - Chapter 24

90 78 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • The C Programming

  • Summary of Previous Lecture

  • Slide 3

  • Today’s Lecture

  • Slide 5

  • Slide 6

  • From Algorithms to Programs

  • A C Programming Language

  • History of C

  • A High-Level Language

  • How to get started?

  • Turbo C++ IDE Version 3

  • Open a new window for writing a program

  • Set the Directories in Option Menu

  • Set the output directory path

  • Write your first program here

  • Compile to find errors

  • No Errors Found

  • Execute the program by Run option

  • See output by pressing Ctrl+F5

  • Basic Structure of a C Program

  • Slide 22

  • Main Function = Main Gate

  • Slide 24

  • Slide 25

  • Slide 26

  • Slide 27

  • Where to store data?

  • Character Representation

  • Slide 30

  • Slide 31

  • Remember: Variables

  • Variable

  • Variable Declaration: Examples

  • Slide 35

  • Slide 36

  • Slide 37

  • Slide 38

  • Slide 39

  • Keyword

  • Slide 41

  • Identifier

  • Assignment

  • Assignment: Examples

  • Slide 45

  • Slide 46

  • Constant Variables

  • Constant Variables: Examples

  • Slide 49

  • Slide 50

  • Slide 51

  • Slide 52

  • Slide 53

  • printf() function

  • Slide 55

  • Slide 56

  • Slide 57

  • scanf function

  • scanf example

  • Output of previous program

  • We have covered

  • Precedence in Expressions

  • Precedence in Expressions -- Example

  • More on precedence

  • Precedence in Expressions – Example

  • Precedence in Expressions –Example..

  • Precedence in Expressions – Example..

  • Slide 68

  • Precedence in Expressions ..

  • int and float

  • int and float – Example 2

  • Slide 72

  • int and float – Example 3

  • Unary operators

  • Increment and decrement operators

  • Slide 76

  • Slide 77

  • Slide 78

  • Slide 79

  • Slide 80

  • Slide 81

  • Slide 82

  • Comments

  • Comments ..

  • Errors in C Program

  • Types of Errors

  • Syntax Error

  • Logical Error

  • Run Time Errors

  • Summary

Nội dung

Lecture 24 - The C programming. After studying this chapter you will be able to understand: Algorithms and programs, a C programming language, history of C, how to get started with C, basic Structure of a C program, data storage and data types, printf() and scanf() functions and usage precedence, unary operations, increment and decrement operations.

The C Programming Lecture 24 Summary of Previous Lecture  Programming  Introduction  What  in real life is Problem Solving? Problem Solving process  Algorithm History  Working Definition  Examples   Algorithms to Programs Summary of Previous Lecture  Components of Algorithms Variables and values  Instructions  Sequences  Procedures  Selections  Repetitions  Documentation   Software Development Process  Top Down Algorithm Design Today’s Lecture  Algorithms and Programs A C programming language  History of C  C, A High level language  How to get started with C  Basic Structure of a C program  Data Storage and Data Types  Variables, Keywords, identifiers, Assignment Today’s Lecture  constant variable printf() and scanf() functions and usage  Precedence   int and float Unary operations  Increment and decrement operations  Today’s Lecture Comments  Error and its Types  Summary  From Algorithms to Programs   Both are sets of instructions on how to a task Algorithm:  talking to humans, easy to understand  in plain (English) language  Program:  talking to computer (compiler)  can be regarded as a “formal expression” of an algorithm A C Programming Language  Flexible language:  Structured language  Low level activities possible    It can produce lean and efficient code Wide availability on a variety of computers Widely used! History of C CPL Combined Programming Language (Barron et al., 1963)  BCPL Basic CPL (Richards, 1969)  B (Thompson, 1970)  C K&R C (Ritchie, 1972)  ANSI C American National Standards Institute C (X3J11, 1989)  C99 (JTC1/SC22/WG14, ISO/IEC 9899, 1999)  A High-Level Language #include int main() { printf(“Hello World”); return 0; } Source code  10100110 01110110 00100110 00000000 11111010 11111010 01001110 10100110 11100110 10010110 11001110 00101110 10100110 01001110 11111010 01100110 01001110 10000110 etc Executable code Compilers and linkers translate a high level program into executable machine code Example ­­ Simple Expressions  Evaluate an expression set result to 1+2*3-4/5 output result #include Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ set result to 1+2*3-4/5 output result Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ int main() { set result to 1+2*3-4/5 output result return 0; } Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ set result to 1+2*3-4/5 output result int main() { float result; return 0; } Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ set result to 1+2*3-4/5 output result int main() { float result; result = + * - / 5; return 0; } Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ set result to 1+2*3-4/5 output result int main() { float result; result = + * - / 5; printf(“%f\n”, result); return 0; } Example ­­ Simple Expressions  Evaluate an expression #include /* Evaluate an expression */ set result to 1+2*3-4/5 output result Output: 7.000000 int main() { float result; result = + * - / 5; printf(“%f\n”, result); return 0; } Comments Essential for documenting programs  Run from a /* to the next */  Examples:  /* THIS IS A COMMENT */ /* So is this /* ** and this ** */ */ Comments  Comments not “nest” /* Comments start with a “/*” and end with a “*/” but they don’t nest! */ Errors in C Program Do not get Fear of an Error!  All good programmers started with lot of Errors  Understand them and remove them!  Types of Errors  In c program you may get  Syntax error  Logical error  Run time errors Syntax Error  These errors occur because of wrongly typed statements, which are not according to the syntax or grammatical rules of the language  For example, in C, if you don’t place a semicolon after the statement (as shown below), it results in a syntax error printf(“Hello,world”) Logical Error  These errors occur because of logically incorrect instructions in the program  Let us assume that in a 1000 line program, if there should be an instruction, which multiplies two numbers and is wrongly written to perform addition  This logically incorrect instruction may produce wrong results Detecting such errors are difficult! Run Time Errors   These errors occur during the execution of the programs though the program is free from syntax and logical errors Some of the most common reasons for these errors are  When you instruct your computer to divide a number by zero  When you instruct your computer to find logarithm of a negative number  When you instruct your computer to find the square root of a negative integer Summary  High level language is converted into computer understandable by a compiler  Compiler converts source code into computer understandable code  C Programming is a way to program computers  It has a syntax  It has commands and structure  C can not be learnt! It can be understood by implementing it! ... software  http://turbo-c.soft32.com/  Install  it! Follow the step by step guide for your first program! Turbo C++ IDE Version Click New to open a program window Open a new window for writing a program... integer equivalent specified by its position in the ASCII table (pronounced “as-key”)   American Standard Code for Information Interchange Character Representation  The ASCII values range from... with a semi-colon (;) #include int main() { printf(“Hello World”); return 0; } Where to store data?  A data type is a representation of data that defines a size and valid range for data

Ngày đăng: 30/01/2020, 14:15