730 likes | 742 Views
Welcome to CS 105! This course introduces programming in C++ for beginners. Learn fundamentals through lectures, labs, quizzes, and exams. Explore course materials, grading criteria, lab procedures, and ethical guidelines. Find help resources and course philosophy on the web page. Join us to enhance your problem-solving and programming skills!
E N D
CS 105 - Sec. 02 Summer 2015 • George Koutsogiannakis – office: 112 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
Lecture/Lab: T,R 5:00 P.M. – 8:00 P.M. SB 108
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.
CS 105 – Required Textbook and Lab Manual • “C++Programming: From Problem Analysis to Program Design” By D.S. Malik, • 5th (red) Edition • You can use other editions but note that the schedule of assignments is based on the 5th edition (page numbers differ from edition to edition)
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
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.
Lab Grading procedure • Start lab on assigned date in class when the instructor finishes the lecture part. • Ask questions about the lab. • Finish lab at home if not completed during the class session. • 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. • The grade will be available on Blackboard.
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.
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.
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!!
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.
Excuses • Exam, Quiz Dates Already Posted. No make ups except in case of emergency. • If Emergency: • Doctor/Hospital Note
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!!!
CS 105 - Ethics • Exams: • Closed Book, Closed Notes, Closed Everything • Nothing in Ears (mp3 players, cell phones, etc.) • Labs Should Be Done Independently
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!!!
CS 105 – Web Page • http://www.cs.iit.edu/~cs105 • Click on Syllabus • Weekly Assignments • Quiz and Exam Dates • Lecture Slides • Other Course Information
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
Course Philosophy • Computer Science Side • Problem Solving • Logical Thought • Programming in C++ • “Real World” Side • Human Nature • Corporate World • Surviving during and after College
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?
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”
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
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
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.
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.
C++ Required Elements • Every C++ Program Must Have: int main() { }
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 ().
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.
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 }
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.
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.
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.
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.
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.
Your First Program • // George Koutsogiannakis • // CS105 • // Summer Section 2 • #include <iostream> • using namespace std; • int • main() • { • cout << “Hello World!!” << endl; • return (0); • }
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.
Writing a C++ Program • Write Pseudocode (Design) • Translate Pseudocode into C++ Source Code in Visual C++ • Edit Code • Compile • Link
What Is Pseudocode? • 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
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
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 <iostream> for Typical Input and Output Operations in C++
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
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
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
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
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
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
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
Program Format • White Space: • Not Recognized by Compiler • Indent (e.g. 3 Spaces) for Each New Function, Selection, or Loop
Variables • 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
Declaring a Variable • 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