Download presentation
Presentation is loading. Please wait.
Published byFrederica Matthews Modified over 8 years ago
1
Introduction to Algorithmic Processes CMPSC 201C Fall 2000
2
Software Design Process Requirements specification – What should this application do? Analysis – What is needed to perform this task? Design – How will you accomplish this task (algorithm)? Implementation – Translate algorithm into a computer language (code). Reuse review – Are you reusing the objects correctly? Maintenance and upgrades – How should program be changed with use and time?
3
Requirement Specification Ask questions! What should this program do? Who will be using it? What is the program’s expected lifetime? Etc. Rewrite problem in your own words. Document. Do not skip this step!
4
Analysis Determine objects, variables, constants, etc. that you need to complete task. What properties do these need?
5
Design Develop the logic. Explore different approaches. Develop the algorithm. Diagram logic flow and interaction between different parts. Develop a set of test data. Documentation.
6
Implementation Translate algorithm to computer language. Compile (checks for syntax errors) and link (combines your code with library programs or other modules). Document code. Test. Modify code as needed to correct errors.
7
Reuse review Are items (objects, sections of code etc.) that you may want to reuse organized together and identified?
8
Upgrade and Maintenance Modify to meet changing needs. Modify to run smoother. Fix errors (“bugs”). Document.
9
Syntax Grammar rules Punctuation Semicolons (;) Braces ({) Slashes (/) Etc.
10
Style Rules Use meaningful, descriptive names. Capitalize in a consistent manner. Document. At beginning to define problem, variables, constants etc. Throughout code to explain specific sections. Use spacing and indentation to help delineate sections of code and logic flow. See figure 1.10
11
Questions ????
12
Memory
13
Operating system Your Program data
14
Variables and Constants Names for memory locations so the programmer does not have to use cell address! Variable - data stored in that memory location will change throughout execution of the program. Constant - data is set at compile time and cannot be changed without recompiling the program.
15
What is an Identifier? An identifier is the name used for a data object (a variable or a constant), or for a function, or for a data type, within a C++ source program. Names (identifiers) in C++ are dependent on case, e.g. someVariable is not the same as SomeVariable. A keyword (see appendix E) may not be used as an identifier.
16
Identifiers (Names) An identifier must start with a letter or underscore, and be followed by zero or more letters (A-Z, a-z), digits (0-9), or underscores. VALID age_of_dogTaxRate98 PrintHeading AgeOfHorse NOT VALID (Why?) age#98TaxRateAge-Of-Cat
17
More about Identifiers (Names) Some C++ compilers recognize only the first 32 characters of an identifier as significant. Then these identifiers are considered the same: Age_Of_This_Old_Rhinoceros_At_My_Zoo Age_Of_This_Old_Rhinoceros_At_My_Safari What about these? Age_Of_This_Old_Rhinoceros_At_My_Zoo AgE_Of_This_Old_Rhinoceros_At_My_Zoo
18
Variables Need variables for data that is input Need variables for data that is output Variable names should be descriptive and easily remembered. Variables need to be declared before they can be used in a program.
19
Variable Declaration & Assignment Variable declaration consists of the data type of the variable and the variable name. int sampleID double sulfurContent Variable assignment stores the result of an expression into the variable. variablename = expression The declaration may in some cases be combined with the assignment. double poundsDioxide = sulfurContent/100
20
Data Types Numbers Integers - whole numbers Floating Point - contain fractional parts Characters
21
Integers short -32766 to 32767 unsigned short0 to 65535 int-32766 to 32767 unsigned int0 to 65535 long-2147483647 to 2147483646 unsigned long0 to 4294967295
22
Integers Long integers require more memory space than int or short. However, errors may occur if int value is larger than 32767, e.g. 32768 may be represented as 1 or -1 depending on the compiler.
23
Floating Point Float 10 -37 to 10 38 with 6 significant digits double 10 -307 to 10 308 with 15 significant digits long double 10 -4931 to 10 4932 with 19 significant digits
24
Floating Point Required memory increases with increased range and significant digits. Required time for calculations increase with significant digits.
25
Character Used to represent characters - letters, spaces, numbers not used for arithmetic operations char variable can store a single character or an escape sequence. ‘A’, ‘b’, ‘ ‘, ‘\n’new line ‘\t’tab ‘\f’form feed (new page)
26
Arithmetic Operations Unary - one operand positive and negative +a or -zebra Binary - two operands addition+var1 + var2 subtraction-var1 - var2 multiplication*var1 * var2 division/var1 / var2 remainder (modulus)%var1 % var2
27
Precedence Parenthesis Unary operations Multiplication, Division, Remainder Addition, Subtraction
28
Questions?
29
Arithmetic Operations In general expression involving only integers will result in an integer and expressions involving only floating point numbers will result in a floating point number. Mixed expressions involving both floating point and integer numbers will result in a floating point number. However this result may be unexpected.
30
Integer Division Remember that integers are whole numbers. Integer division may have unintended results depending on the data type of the variables involved. int var1 = 10 int var2 = var1 / 8(1) float var3 = var1 / 8(1.0) float var4 = var1 / 8.0(1.25)
31
Integer Division (Cont.) The expression 5.5 * 7 /2 is not the same as the expression 7 / 2 *5.5
32
Data Type Casting Casting is the explicit conversion of data type within an expression. Suppose you have declared two int variables distance and time and the float variable speed. The expression speed = distance/time would lose the fractional component of speed. To avoid this loss you could do one the following. speed = float(distance) / time speed = distance / float (time) speed = float (distance) / float (time)
33
Data Type Casting (Cont.) Note that the expression speed = float (distance / time) would still lose the fractional part of speed.
34
Data Type Casting (Cont.) When a float variable is casted (converted) to an integer value, value is truncated not rounded. int (12.6) is 12 not 13 To round add 0.5 before converting. int (12.6 + 0.5) is 13 while int (12.1 + 0.5) is 12
35
Questions?
36
General Syntax Rules Statements that should be executed should end in a semicolon (;) Comments are designated with // or /* & */ Library header files require a line similar to #include
37
Input/Output cin >> variable name; cout<< “text”, variables, expressions; require the library header file iostream.h (the line #include must be included in your source code.)
38
Questions ????
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.