Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome to IIT and cs105! 1. CS 105 - Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB 312-567-5288 Best way to communicate.

Similar presentations


Presentation on theme: "Welcome to IIT and cs105! 1. CS 105 - Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB 312-567-5288 Best way to communicate."— Presentation transcript:

1 Welcome to IIT and cs105! 1

2 CS 105 - Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB 312-567-5288 koutsogiannakis@iit.edu Best way to communicate with me outside of class is via email or In my office after class – 12 noon-1:00p.m. T & Th. Course web site: www.cs.iit.edu/~cs105 2

3 Lecture/Lab: T,R 8:50 A.M. – 12:00 P.M. SB 108 3

4 CS Intro Courses CS 105: 1-Semester Requiring Little or No Previous Programming Experience, Programming in C++ The course covers programming fundamentals. Practice exercises are assigned. 4

5 CS 105 – Required Textbook and Lab Manual “C++Programming: From Problem Analysis to Program Design”By D.S. Malik, 2 nd (YELLOW) OR 3 rd (GREEN) OR 4 th (brown) OR 5 th (red) Edition or Sixth Editions Note that the schedule is based on the 5 th edition 5

6 CS 105 - Quizzes/Exams & Grading 2 Quizzes – Each 5% of Grade 2 Exams: – Exam I - Lecture Exam - 10% –Exam II - Lecture Exam - 25% Final Exam - 35% Labs - 20% Must Take Final to Pass Course 6

7 CS105 Labs 11 Labs Assigned consist of: –Reading Assignment, and Lab Exercises from Textbook. –Programming Exercises (Located at End of Each Chapter in Textbook) Labs Due on specific dates as mentioned on the web site. Must be present in order to receive credit! Points are subtracted if late for lab session. Show answers to instructor to receive credit. Grades are posted on Blackboard. Labs 0-9: 1.8 points each Lab 10: 2 points Total: 20 points towards your final grade. 7

8 Lab Grading procedure 1.Start lab on assigned date in class when the instructor finishes the lecture part. 2.Ask questions about the lab. 3.Finish lab at home if not completed during the class session. 4.Have your lab graded by the instructor on the next session by showing your work. You will receive a grade when you show your work. 5.The grade will be available on Blackboard. 8

9 Other Class Work I will have practice exercises for you to do on the computer during lectures. You are required to do the practice exercise and not work on anything else!!!! No grading for practice exercises. Cover topics discussed in order to provide hands on understanding. 9

10 Exams 2 quizes : 5 points each Exam 1: 10 points Exam 2: 25 points Exam 3: 35 points Consist of : –questions about topics discussed –Small programs Hand written. 10

11 Expectations Attendance in Lectures and Labs –Take notes during lectures! Completion of Quizzes and Exams Four to Six Hours per Week on Homework No Cheating Have fun!! 11

12 Rules No Swearing or Other Inconsiderate Behavior Turn Off Cell Phones during lectures. Questions, Discussion, Ideas Welcome. No cell phones, no other material allowed on the desk during quizzes or exams. 12

13 Excuses Exam, Quiz Dates Already Posted. No make ups except in case of emergency. If Emergency: –Doctor/Hospital Note 13

14 Unacceptable Excuses Slept Late Felt Sick I’m Just a Freshman Roommate Ate My Alarm Clock/Textbook/Underwear Missed Bus Had a Game/Match/Practice Didn’t Know When Exam/Quiz Was If Any of Above Happen, Get to Class As SOON as Possible!!! 14

15 CS 105 - Ethics Exams: –Closed Book, Closed Notes, Closed Everything –Nothing in Ears (mp3 players, cell phones, etc.) Labs Should Be Done Independently 15

16 CS 105 – Where to Get Help www.cs.iit.edu/~cs105 Internet: Search for “C++ tutorial”, or “C++ help” GET HELP EARLY RATHER THAN LATER!!! 16

17 CS 105 – Web Page http://www.cs.iit.edu/~cs105 Click on Syllabus –Weekly Assignments –Quiz and Exam Dates –Lecture Slides –Other Course Information 17

18 CS105 Labs (Cont) All Labs Assigned from Textbook (Malik) Work on Labs on Personal PC, or Campus Computers Save.cpp File(s) to Floppy or flash drive, or send to yourself in email and Bring to Lab Section for Discussion and Questions 18

19 Course Philosophy Computer Science Side –Problem Solving –Logical Thought –Programming in C++ “Real World” Side –Human Nature –Corporate World –Surviving during and after College 19

20 Problem Solving Arrange a Deck of Cards by Suit and Rank How Would You Do This? How Would You Tell a Child to Do This? How Would You Tell a Computer to Do This? 20

21 Problem Solving CS 105 Develops Logic Skills to Solve Problems by Writing a Program A Program is a Problem Solving Tool Computers Follow Instructions Given to Them Computers Do Not Have “Intuition” Computers Do Not Make Decisions “on Their Own” 21

22 Why Use a Program? Computers Perform Tasks Many Times Faster than a Person Computers Are More Consistent than a Person Computers Can Work 24-7 22

23 Terminology Source Code: the Original Problem-Solving, Logical Solution Written in a Programming Language (e.g. C++) Compiling: the Action of Turning the Source Code into a Format the Computer Can Use Linking: the Action of Bringing in Already Written Code (Libraries) for Use in a New Program Executable: the Result of Compiling and Linking a Source Program; the “.exe” file that the Computer Can Run 23

24 Terminalogy Pseudocode: Writing your thoughts for solving the problem (the program) in a combination of English sentences and programming (i..e C++) instructions. –Could take many attempts before the solution make sense. 24

25 Syntax A programming language has: –Definite rules as to how to write instructions called the ”Grammar” and “Syntax” of the language. Pretty much like a spoken language. –Has definite words and symbols that make up the instructions called “keywords”. Pretty much like the dictionary of a spoken language. 25

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

27 Explanation In the previous slide: –int, main are keywords. –(), {, } are symbols –How the keywords and the symbols appear in our programm, is guided by the grammar/syntax of the language. – i.e. the syntax requires that every C++ program start with the keyword int followed by the keyword main followed by (). 27

28 Explanation The symbol { indicates that the programming instructions start after the symbol. The symbol } indicates the end of the programming instructions. The keyword main () indicates the name of a function (by the name main ). –function is a term used to describe a specific task that a program has to perform. 28

29 Explanation A program can have many tasks, therefore many functions. The Grammatical rule that we have learned so far is that: –EVERY C++ PROGRAM MUST HAVE A FUNCTION CALLED main –AND THAT THE SYMBOLS () MEAN FUNCTION –AND THAT THE INSTRUCTIONS FOR THE FUNCTION (TASK) START AFTER THE SYMBOL { AND END WITH THE SYMBOL } 29

30 How the program is understood by the computer A computer understands machine level instructions which consist of a series of 1 and 0. –In other words machine level instructions are coded instructions. 30

31 How the program is understood by the computer The program that we write has to: –Be checked for compliance to the grammar and syntax of the language. –Be converted to machine level instructions. A software tool called “ the compiler” is responsible for the above two tasks. 31

32 How the program is understood by the computer If the compiler finds errors (the first task of the compiler) : –It provides you with messages and clues as to the kind of grammatical or syntactical errors found. –It refuses to perform the second task (the translation to machine coded instructions), until all errors are corrected. 32

33 How the program is understood by the computer After you correct all errors the compiler will perform the second task: –You know that the second task of the compiler was performed because it produces the executable file (the file with the coded machine level instructions). Clicking on the executable file will cause the computer to execute the machine level instructions generated by the compiler based on your C++ level instructions. 33

34 Logical tasks Is my program performing the tasks I intended for it? Note: A compiler can not check for logical errors only grammatical and syntactical errors are checked. i.e. suppose the correct logic in the task that you want the computer to perform requires the addition of two numbers but instead your instruction is to multiply the two numbers. 34

35 Your First Program // George Koutsogiannakis // CS105 // Summer Section 2 #include using namespace std; int main() { cout << “Hello World!!” << endl; return (0); } 35

36 Your First Program Notice that certain information about who wrote the program, the class the person attends and the section number as well as the date are in written as comments. Same information must appear in every program you write in this class as part of the labs or exams/quizzes!!! Comments are disregarded by the compiler and they are marked with // in each line. 36

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

38 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? 38

39 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 39

40 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++ 40

41 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 41

42 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 42

43 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 43

44 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 44

45 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 45

46 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 46

47 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 47

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

49 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 49

50 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 50

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

52 Storage Location of Data in a Computer Used When a Program Is Running “Wiped Clean” When Computer Rebooted Bit: a logical single 1 or 0 value (sometimes referred to as True or False) Byte: Basic Unit of Storage (Can Store One Letter of the Alphabet) –Consists of 8 Bits. 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 52

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

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

55 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 55

56 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 56

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

58 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 58

59 Constant: An Identifier that Is Initialized to a Value that Cannot Change Usually Declared at Top of Program using Keyword const Standard Naming of Constants Is to Use All Upper Case Letter with or without Underscore between Words All Constants Must Be Initialized Syntax: const int MAXHT = 100; Named Constants 59

60 Easier to Understand Easier to Modify Example: Compare using Number 5000 in Program versus Constant MAXHT Advantages of Constants 60

61 const int MAXHT = 100; main() {... currentHeight > MAXHT... bridgeHeight == MAXHT... bridgeHeight + newAddition >= MAXHT... // used MAXHT 223 times in this program } Named Constants 61

62 Constants Whose values Are Already Known: Characters (Specified Inside Single Quotes): ‘A’, ‘a’, ’5’, ’ ‘, ’\n’ (newline), ’\0’ (NULL Character) Integers: 10, 1345, -34 Float or Double: 2.3, -45.18, 10.6e6 String (Specified Inside Double Quotes): “HELLO”, “What a great deal.”, “5” Literal Constants (Values) 62

63 Also Known as I/O Output Stream: cout << variable; Input Stream: cin >> variable; New Line: endl All C++ Statements End in Semicolon ( ; ) Input and Output 63

64 #include using namespace std; int main() { int numEntered; cout << “Please enter an integer:”; cin >> numEntered; cout << “Thanks, you entered: “ << numEntered << “.” << endl; } Input and Output Example 64

65 Standard Template Library (STL): Library of C++ Functions Used Worldwide String Type NOT Built-in in C++ String Type Defined in STL To Use STL Strings: #include using namespace std; string lastName; Characters and Strings 65

66 Declaration: string yourName; Assigning a Value to a String: yourName = “A. Goose”; String Constants (Values) Must Be Enclosed in Double Quotes STL Strings 66

67 #include using namespace std; int main() { string lastName; cout << “Enter your last name: “; cin >> lastName; cout << “Your last name is: “ << lastName << endl; return(0); } Input String Example 67

68 Expressions Expression: A Sequence of One or More Identifiers and Operators that Evaluates to a Value Operator: A Symbol Expressing a Way to Modify a Value or Values (e.g., + for Addition) Operand: A Value Being Modified by an Operator Example Expressions: 5 currentHeight currentHeight + 10 68

69 Arithmetic Expressions Standard Arithmetic Operations Can Be Performed: Addition, Subtraction, Multiplication, Division Standard Arithmetic Operators Can Be Used for These Operations: +, -, *, / Others: % - “Modulo (Mod)” – Remainder after Integer Division -- Decrement (Subtract 1) ++ Increment (Add 1) 69

70 Order of Operations Precedence: Level of Importance of Operations Multiplicative Operators Have Higher Precedence than Additive Operators: *, /, % Higher +, - Lower Associativity: Order of Operation for Equal Level Precedence Most Operators Have Left-to-Right Associativity Use Parentheses to Force Differing Precedence of Operations 70

71 Know for the Quiz 1- July 07 All Terms (Underlined Items) Variable Declaration, Initialization, and Assignment Constant Declaration Expressions Operators Input (cin) and Output (cout) 71

72 Know for the Quiz Read Chapters 1 & 2, pages 28-67, 67-77, 77-86, 86-100, 117-124. (Note: Edition 5 page numbers) Ask questions about the exercises if unable to complete Lab 0 OR Lab 1. Practice with additional exercises from text on your own. Study examples material distributed in class. Study Lect 01, 02, 03 slides. Also study the first 3 slides of Lect 04, 05 Quiz will be given at the end of class period, after the lecture part. 72

73 Quiz Format 15 questions where you are given a concept and you are asked to match it against a list of definitions (3/5 of the grade). Write one program (2/5 of the grade) that requires: –Declarations of constants and variables. –Input from user. –Arithmetic expressions including increment or decrement operators. –Display of program output 73


Download ppt "Welcome to IIT and cs105! 1. CS 105 - Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB 312-567-5288 Best way to communicate."

Similar presentations


Ads by Google