Download presentation
Presentation is loading. Please wait.
1
Lecture2
2
Lecture Outline The Software Development Method Exercise
C Language Elements Preprocessor Directives Function Main Declarations Executable Statements Reserved Words, Standard Identifiers & User-Defined Identifier User-Defined Identifier Rules Reading: Chapter 2
3
The Software Development Method
1. Specify the problem requirements. 2. Analyze the problem. 3. Design the algorithm to solve the problem. 4. Implement the algorithm. 5. Test and verify the completed program. 6. Maintain and update the program. C Language Elements
4
Exercise Write a program to process a collection of daily temperatures. Your program should count and print the number of hot days (85 or higher), the number of pleasant days ( ), the number of cold days (less than 60). It should also display the category of each temperature. C Language Elements
5
Exercise 1. Specify the problem requirements
A program is required to process daily temperatures and provide the total number of hot, pleasant, and cold days. 2. Analyze the problem Input: Output: temperature total number of days in each category 3. Design the algorithm to solve the problem 1. Get the temperature. 2. Determine category of that temperature and increment counter for that particular category. 3. Display categories and total number of days that fell under the category. C Language Elements
6
Flowcharts (Continue)
Start or End Input or Output Process or Calculation Decision Course Introduction
7
Exercise Yes >=85? No Yes <=60? No Start Get Temp Add 1 to Hot
Print Hot, Cold, and Pleasant <=60? No Add 1 to Cold Yes Add 1 to Pleasant No End C Language Elements
8
C Language Elements Preprocessor Directive
A C program line beginning with # that provides an instruction to the preprocessor. Preprocessor A system program that modifies a C program prior to its compilation. Two important preprocessor directives are: #include #define C Language Elements
9
#include Preprocessor Directive
Syntax #include <library> Examples #include <stdio.h> #include <math.h> C Language Elements
10
#define Preprocessor Directive
Syntax #define NAME value Examples #define PI 3.14 #define section7 18 C Language Elements
11
C Language Elements Function Main
It marks the beginning of any C program. Function Main Syntax int main(void) { } (declarations) (Executable statements) C Language Elements
12
C Language Elements Declarations
The part of a program that tells the compiler the names of memory cells in a program Declarations Executable Statements Program commands that are converted to machine code by the compiler. C Language Elements
13
Declarations Syntax Data type variable; Examples int count, large;
float area; char first; int count, large; C Language Elements
14
Data Types It is a set of values.
It defines operations that can be performed on those values. The most used data types are: int float char C Language Elements
15
int The int data type represents integers in C.
Integers are whole numbers. ANSI defined the range of integers as being between and 32767 Examples: -5235 13253 -35 32767 C Language Elements
16
Float The float data type represents real numbers in C.
A real number has an integral part and a fractional part separated by a decimal point. Examples: 3.643 0.325 3.4 C Language Elements
17
char The char represents one individual character in C. Examples: 'D'
'5' '*' C Language Elements
18
Reserved Words, Standard Identifiers & User-Defined Identifier
A reserved word is a word that has a special meanning in C and cannot be used for other purpses. Example: int, double, char, void. A standard identifier is a word that has a special menning in C but can be used for other purposes or redefined. Example: printf, scanf. A user-defined identifier is a name gevin to a variable. Does not have a special meanning in C and needs to be declared. Example: PI, large, hot. C Language Elements
19
User-Defined Identifier Rules
An identifier must consist only of letters, digits, and underscores. An Identifier cannot begin with a digit. A C reserved word cannot be used as an identifier. A standard identifier should not de redefined. C Language Elements
20
User-Defined Identifier Rules
Examples: letter2 21etter Begins with a digit letter_2 int Reserved word joe's Character ’ not allowed variable cent_per_inch C Language Elements
21
C Language Elements #include <stdio.h>
#define KMS_PER_MILE 1.609 int main(void) { float miles, kms; } (Executable statements) C Language Elements
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.