Presentation is loading. Please wait.

Presentation is loading. Please wait.

If You Missed Last Week Go to www.cs.iit.edu/~cs105, Click on Syllabus, review lecture 01 notes, course schedule Contact your TA (email on website) Schedule.

Similar presentations


Presentation on theme: "If You Missed Last Week Go to www.cs.iit.edu/~cs105, Click on Syllabus, review lecture 01 notes, course schedule Contact your TA (email on website) Schedule."— Presentation transcript:

1 If You Missed Last Week Go to www.cs.iit.edu/~cs105, Click on Syllabus, review lecture 01 notes, course schedule Contact your TA (email on website) Schedule going over Lab 0 with them AS SOON AS POSSIBLE!!!

2 Write Pseudocode (Design) Translate Pseudocode into C++ Source Code in Visual C++ Edit Code Compile Link Writing a C++ Program

3 Every Programmer’s Way of Writing Down Steps in Solving a Problem Steps in Creating Pseudocode: –Understand the Problem –Decide How to Solve the Problem –Write the Solution Using a Logical Sequence of Statements Design Issues Apply to almost ANY Vocation What Is Pseudocode?

4 Writing Source Code Source Code Is the Actual Program Code that Will Run Once Compiled and Linked Pseudo Code Should Be Easily Translated into Source Code

5 C++ Required Elements Every C++ Program Must Have: int main() { }

6 Preprocessing Preprocessing Is the Actions Taken Before a Source File Is Handed Off to the Compiler Outcome of Preprocessing Must Still Be a Correct Source Code File Example Preprocessing Statement: –#include : Includes Text of Other Source Files –#include Usually Occur at Top of Program –Pound Sign ( # ) Must Be in First Position on Line –Example: #include for Typical Input and Output Operations in C++

7 Your First Program // Jon Hanrath // CS105 // Section 042 #include using namespace std; int main() { cout << “Hello World!!” << endl; }

8 Compiler Converts Source Code into an Object File or Machine Code Each Change to Source File Requires a Recompilation Compiler Detects Syntax Errors Syntax Error: a Non-Proper, Not Allowable, Sequence of Characters or Words Given a Particular Language

9 Syntax Errors Spelling Errors Examples: –Undefined Variable Name –Unrecognized Keyword –Cannot Find Include File or Library Punctuation Errors Examples: –Missing Curly Braces –Missing Semicolons –Malformed Comments Syntax Errors Are Listed at Bottom of Screen When Compilation Is Complete

10 Syntax Errors (Cont) Syntax Errors Are Listed at Bottom of Screen When Compilation Is Completed Two Kinds of Messages: –Warning: Compiler Thinks There Is a Problem, but Lets It Go By Without Failing –Error: Compiler Finds an Error and Fails to Compile First Error in Program May “Cause” Other Errors to Show Up General Rule: Fix First Error (and Any Obvious Errors); Then Recompile

11 Linking Links (Connects) Object Code with External Libraries, which Contain Functions (Already Written and Compiled Code) to Use with Another Program Creates an Executable File An Executable File (e.g..exe File) Can Be Run If Linker Cannot Find Libraries, Error Message Are Generated

12 Logic Errors – “Bugs” Also Called Semantic or Run-Time Errors Program Compiles, but Doesn’t Produce the Expected Results Examples: –Program Keeps Running Forever (Infinite Loop) –Nothing Happens –Program Output Is Incorrect –Error Message at Run Time (e.g. Dividing by 0) –Errors May Be Intermittent May Be Able to Find Semantic Problems with Debugger

13 Detecting “Bugs” Running Program Should Be Tested Several Times with Different Inputs Test Plan – Series of tests (e.g., inputs) that have predetermined expected outputs. Running Program Should Be Tested Several Times under All Potential Conditions When Errors Detected: Analysis Needed: Debugging Mechanism

14 Comments Comments: Describe a Program // Comment to end of line /* Comment until first occurrence of star slash */ Difficult to Understate Importance of Good Comments Should Be at Beginning of Program (Overall Summary) Should Be Next to Variable Declaration Briefly Describing Uses of Variable Should Be Anywhere in Program Where Unobvious Coding Is Performed

15 Elements of a Program Summary Comments Preprocessor Statements (e.g., #include ) Main Function: int main() { // statements; return 0; }

16 Program Format White Space: –Not Recognized by Compiler –Indent (e.g. 3 Spaces) for Each New Function, Selection, or Loop

17 Identifiers Used to Store Values that May Change Every Variable Has a Type : What Kind of Value (e.g., Integer, Floating Point Number, Character) Is Begin Stored Every Variable Has a Value which Is Assigned and Can Be Changed Every Variable Must Be Declared, which Sets Aside Memory for the Storage Location Variables

18 Declaration Normally Comes after a Function Definition Opening Curly Brace: int main() { int num1; //variable declaration num1 = 10; // variable assignment cout << num1; // variable output } Declaration Includes Type and the Name of the Variable All Variables Must Be Declared before Being Used Declaring a Variable

19 Variables and Main Memory int num; num = 10; num = 15; num 10 num Main Memory 15 num

20 Storage Location of Data in a Computer Used When a Program Is Running “Wiped Clean” When Computer Rebooted Byte: Basic Unit of Storage (Can Store One Letter of the Alphabet) Kilobyte (KB): 1000 (or 1024) Bytes (Pages of Text) Megabyte (MB): 1,000,000 Bytes (Large Pictures) Gigabyte (GB): 1,000,000,000 Bytes (Music Files, Video Files) Main Memory

21 Initialization: Value Given to Variable at Declaration Assignment: Value Given to Variable in Execution Statement Initialization and Assignment

22 int main() { int num1 = 10; //variable declaration // with initialization cout << num1; // variable output } Variable Initialization

23 int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer part, decimal part, and exponent part) Range of Typically 10e-38 to 10e38 double : Larger Real Number (10e-308 to 10e308) char : Character Built-In (or Primitive) Data Types for Variables

24 Can Use Letters: Remember That C++ is Case Sensitive (e.g., NumWidgets Is Not the Same as numwidgets ) Can Use Digits 0-9, and Underscore Cannot Start with a Digit Cannot Contain Spaces or Other Characters Typically Maximum of 32 Characters Cannot Use C++ Keywords Naming Variables in C++: Identifiers

25 Should Use a Meaningful, Descriptive Name so that Variable’s Use Is Easily Understood: Examples: counter, second, minute, length, width Be Consistent with Case; Usually Lower Case with Upper Case for Second Part of Variable Name Examples: averageRainfall, totalStudentGrades, maxBuildingHeight, minPackageWeight; Naming Variables (Cont)

26 Scope: Area of a Program within which a Variable Can Be Referenced Variable Definitions Are Recognized in the Curly Braces in which They Were Defined Variables Declared Outside of Functions Are Recognized from the Point Declaration through the Rest of the Program Variable Scope


Download ppt "If You Missed Last Week Go to www.cs.iit.edu/~cs105, Click on Syllabus, review lecture 01 notes, course schedule Contact your TA (email on website) Schedule."

Similar presentations


Ads by Google