Download presentation
Presentation is loading. Please wait.
1
CEG 221 Lesson 1: Review I Mr. David Lippa
2
Overview: Review of Required Concepts Basic data types –Normal basic types, size_t, time_t Basic programming structure –Flow control / Repetition –Scope –Documentation of code –Modular programming Libraries Pass by reference (in C, by pointer) vs. pass by value Basic algorithm development –Design document –Pseudo code
3
Basic Types – Signed & Unsigned Signed Types char –Range: [-127, 127] short –Range: [-32767, 32767] int –Range: [-2 31 -1, 2 31 -1] Long –Range: [-2 31 -1, 2 31 -1] Unsigned Types unsigned char –Range: [0, 256 - 1] unsigned short –Range: [0, 65536 - 1] unsigned int –Range: [0, 2 32 - 1] unsigned long –Range: [0, 2 32 - 1] size_t / time_t: vary
4
Basic Types – Signed v. Unsigned Signed Subtracting from MIN –char c = -127 –c-1 2 (8-1) - 1 = 127 Adding to MAX –char c = 127 –c+1 -2 (8-1) - 1 = -127 These apply for ++ as well as -- operators. Unsigned Subtracting from MIN –char c = 0 –c-1 2 8 - 1 = 255 Adding to MAX –char c = 255 –c+1 0 These apply for ++ as well as -- operators.
5
Basic Types – Signed v. Unsigned To Generalize for variable var: –Signed subtracting from MIN var - 1 2 (sizeof(var) * 8) -1 - 1 –Signed adding to MAX var + 1 -2 (sizeof(var) * 8) -1 – 1 –Unsigned subtracting from MIN var - 1 2 (sizeof(var) * 8) - 1 –Unsigned adding to MAX var + 1 0
6
Basic Programming Structure Flow Control using if/else Repetition of tasks using loops –for –while –do … while Scope –When you hit a }, non-pointer type declared within its matching { is GONE
7
Basic Programming Structure Documentation of code –ALWAYS document functions Inputs: arguments Outputs: return values, if applicable High level description (from design document) –ALWAYS document complicated loops Modular programming –Use a library when you can – why reinvent the wheel? –Flow control / Repetition –Scope –Pass by reference (in C, by pointer) vs. pass by value
8
Basic Programming Structure: Modular Programming Libraries –Predefined functions grouped together by purpose are put in a library. –The interface (how to use) is documented in a header file (.h) Pass by reference (in C, by pointer) vs. pass by value –Reference means the input values Δ –Value means a copy is made
9
Basic Algorithm Development What is an algorithm? Why develop algorithms? Steps –Data Types (data structures) –Interaction of/between Data Types (functions) –Process (using data structures and their functions to produce a result)
10
Basic Algorithm Development How do we develop an algorithm? –Use a design document to flush out the general aspects of the algorithm –Use pseudo code to flush out the specifics of the process What goes into a design doc? –What data types & Why –How will the types interact (if at all) –General view of what the algorithm does
11
Basic Algorithm Development: An Example - SAS Design doc for Side Angle Side Triangulation: –TYPES: Use doubles since acos, etc. take doubles & depending on size of the sides, we might need more accuracy –INTERACTION: The variables are related through the cosine laws formula, where a,b,c are sides and C the angle opposite side c: c 2 = a 2 + b 2 – 2ab cos C
12
Basic Algorithm Development: An Example - SAS PROCESS: –Ensure that all units are the same (a, b, c are the same units, all angles are in radians) –solve the equation for the variable needed: b = √( c 2 – a 2 + 2ab cos C ) –Flush out to use C functions (make sure to note what libraries are being used!) b = sqrt( pow(c, 2) – pow(a, 2) + 2*a*b*cos(C) ) –Ensure output values are in the proper units
13
Next Time Grouping/Organizing Data Types & Their Applications –Arrays –Data structures that we will briefly cover today, and in more detail later in the term: Lists Stacks Queues Trees
14
QUESTIONS
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.