Introduction to Algorithmic Processes CMPSC 201C Fall 2000.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
Chapter 2: Introduction to C++.
Introduction to C Programming
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
COMPUTER SCIENCE I C++ INTRODUCTION
A First Book of ANSI C Fourth Edition
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 2: Using Data.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
TK1913 C++ Programming Basic Elements of C++.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Lecture 3: Operators, Expressions and Type Conversion
Completing the Problem-Solving Process
Chapter 2: Problem Solving Using C++
Basic Elements of C++.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2: Introduction to C++
C++ for Engineers and Scientists Second Edition
Basic Elements of C++ Chapter 2.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS111 Computer Programming
Introduction to C++ Programming
Chapter 2: Introduction to C++.
Unit 3: Variables in Java
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

Introduction to Algorithmic Processes CMPSC 201C Fall 2000

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?

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!

Analysis  Determine objects, variables, constants, etc. that you need to complete task.  What properties do these need?

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.

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.

Reuse review  Are items (objects, sections of code etc.) that you may want to reuse organized together and identified?

Upgrade and Maintenance  Modify to meet changing needs.  Modify to run smoother.  Fix errors (“bugs”).  Document.

Syntax  Grammar rules  Punctuation  Semicolons (;)  Braces ({)  Slashes (/)  Etc.

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

Questions  ????

Memory

Operating system Your Program data

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.

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.

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

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

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.

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

Data Types  Numbers  Integers - whole numbers  Floating Point - contain fractional parts  Characters

Integers  short to  unsigned short0 to  int to  unsigned int0 to  long to  unsigned long0 to

Integers  Long integers require more memory space than int or short.  However, errors may occur if int value is larger than 32767, e.g may be represented as 1 or -1 depending on the compiler.

Floating Point  Float  to  with 6 significant digits  double  to  with 15 significant digits  long double  to  with 19 significant digits

Floating Point  Required memory increases with increased range and significant digits.  Required time for calculations increase with significant digits.

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)

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

Precedence  Parenthesis  Unary operations  Multiplication, Division, Remainder  Addition, Subtraction

Questions?

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.

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)

Integer Division (Cont.)  The expression  5.5 * 7 /2  is not the same as the expression  7 / 2 *5.5

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)

Data Type Casting (Cont.)  Note that the expression  speed = float (distance / time)  would still lose the fractional part of speed.

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 ( ) is 13 while  int ( ) is 12

Questions?

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

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.)

Questions ????