Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Variables in C Amir Haider Lecturer.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
Chapter 2: C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 1 Introducing C.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Chapter 2: C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 2 C Fundamentals.
Topic:  Reading Input  identifier,  if statement,  Arithmetic Operation CSE 102 – Programming Fundamentals.
1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Chapter 2: C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 2 C Fundamentals.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
CMSC 1041 Variables in C Declaring, Naming, Using Variables.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Gator Engineering Project 1 Grades released Re-grading –Within one week –TA: Fardad, or office hours: MW 2:00 – 4:00 PM TA Huiyuan’s office hour.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
1 Chapter 2 C Fundamentals. Computer Architecture Central Processing Unit CPU Main memory Data bus Address.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
COP 3275: Chapter 02 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
C Fundamentals Chapter 2 Copyright © 2008 W. W. Norton & Company.
Variables, Identifiers, Assignments, Input/Output
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
C Short Overview Lembit Jürimägi.
Computing with C# and the .NET Framework
CMSC 104, Section 4 Richard Chang
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Variables, Identifiers, Assignments, Input/Output
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Variables in C Declaring , Naming, and Using Variables.
C Fundamentals Chapter 2 Copyright © 2008 W. W. Norton & Company.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Module 2 Variables, Data Types and Arithmetic
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.

Gator Engineering Programming Exercises

Gator Engineering Programming Exercises 2.1 3

Gator Engineering Programming Exercises 2.4 4

Gator Engineering Programming Exercises 2.5 5

Gator Engineering Defining Names for Constants dweight.c and dweight2.c rely on the constant 166, whose meaning may not be clear to someone reading the program. Using a feature known as macro definition, we can name this constant: #define INCHES_PER_POUND 166 6

Gator Engineering Defining Names for Constants When a program is compiled, the preprocessor replaces each macro by the value that it represents. During preprocessing, the statement weight = (volume + INCHES_PER_POUND - 1) / INCHES_PER_POUND; will become weight = (volume ) / 166; Non-changeable Once and for all Easier understanding Rules 7

Gator Engineering Defining Names for Constants The value of a macro can be an expression: #define RECIPROCAL_OF_PI (1.0f / f) If it contains operators, the expression should be enclosed in parentheses. Using only upper-case letters in macro names is a common convention. 8

Gator Engineering Program: Converting from Fahrenheit to Celsius The celsius.c program prompts the user to enter a Fahrenheit temperature; it then prints the equivalent Celsius temperature. Sample program output: Enter Fahrenheit temperature: 212 Celsius equivalent: The program will allow temperatures that aren’t integers. The conversion formulas between °F and °C are: [°C] = ([°F] - 32) × 5/9 [°F] = [°C] × 9/

Gator Engineering celsius.c /* Converts a Fahrenheit temperature to Celsius */ #include #define FREEZING_PT 32.0f #define SCALE_FACTOR (5.0f / 9.0f) int main(void) { float fahrenheit, celsius; printf("Enter Fahrenheit temperature: "); scanf("%f", &fahrenheit); celsius = (fahrenheit - FREEZING_PT) * SCALE_FACTOR; printf("Celsius equivalent: %.1f\n", celsius); return 0; } 10

Gator Engineering Program: Converting from Fahrenheit to Celsius Defining SCALE_FACTOR to be (5.0f / 9.0f) instead of (5 / 9) is important. Note the use of %.1f to display celsius with just one digit after the decimal point. 11

Gator Engineering Identifiers Names for variables, functions, macros, and other entities are called identifiers. An identifier may contain letters, digits, and underscores, but must begin with a letter or underscore: times10 get_next_char _done It’s usually best to avoid identifiers that begin with an underscore. Examples of illegal identifiers: 10times get-next-char 12

Gator Engineering Identifiers C is case-sensitive: it distinguishes between upper-case and lower-case letters in identifiers. For example, the following identifiers are all different: job joB jOb jOB Job JoB JOb JOB 13

Gator Engineering Identifiers Many programmers use only lower-case letters in identifiers (other than macros), with underscores inserted for legibility: symbol_table current_page name_and_address Other programmers use an upper-case letter to begin each word within an identifier: symbolTable currentPage nameAndAddress C places no limit on the maximum length of an identifier. 14

Gator Engineering Programming guildlines Pascal case –Function, e.g. PrintMyName() –Global variables, e.g. int GlobalCounter Camel case –Local variables, e.g. int volume = 10 –Parameters, e.g. Add(int val1, int val2) 15

Gator Engineering Keywords The following keywords can’t be used as identifiers: auto enum restrict* unsigned break extern return void case float short volatile char for signed while const goto sizeof _Bool* continue if static _Complex* default inline* struct _Imaginary* do int switch double long typedef else register union *C99 only 16