CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Similar documents
Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

Introduction to Programming

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Chapter 1 Introduction to Computers and C++ Programming

Fundamentals of Programming. Lecture 1: Introduction to C Programming

IS 0020 Program Design and Software Tools

C++ Programming Language Lecture 1 Introduction

by Pearson Education, Inc. All Rights Reserved.

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

C: How to Program. Week /Mar/05

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Object Oriented Design

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

Your First C++ Program. September 1, 2010

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Fundamentals of Programming Session 4

Lab # 02. Basic Elements of C++ _ Part1

Chapter 2, Part I Introduction to C Programming

Chapter 2 - Introduction to C Programming

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Chapter 1 & 2 Introduction to C Language

Chapter 1 Introduction to Computers and C++ Programming

0 Introduction: Computer systems and program development

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Chapter 1 Introduction to Computers and Programming

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Computer Programming : C++

Chapter 1 Introduction to Computers and C++ Programming

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Chapter 1: Why Program? Computers and Programming. Why Program?

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

IS 0020 Program Design and Software Tools

Chapter 1 INTRODUCTION

2 nd Week Lecture Notes

Fundamentals of Structured Programming

6.096 Introduction to C++ January (IAP) 2009

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

BITG 1233: Introduction to C++

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Understanding main() function Input/Output Streams

Full file at C How to Program, 6/e Multiple Choice Test Bank

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Scientific Computing

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

(0) introduction to the course. how to learn a programming language. (0) course structure

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Chapter 2: Overview of C++

Programming with C++ as a Second Language

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

A A B U n i v e r s i t y

Chapter 2 Basic Elements of C++

UEE1302 (1102) F10: Introduction to Computers and Programming

Introduction. Arizona State University 1

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

A First Program - Greeting.cpp

Programming for Engineers Introduction to C

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Chapter 1: Introduction to Computers and Programming

Program Organization and Comments

C++ Programming Basics

1a Computers, Problem Solving!

Fundamentals of Programming (Python) Basic Concepts. Ali Taheri Sharif University of Technology Spring 2018

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CSCI 1061U Programming Workshop 2. C++ Basics

C++ Support Classes (Data and Variables)

Welcome Application. Introduction to C++ Programming (Solutions) 2004 by Deitel & Associates, Inc. All Rights Reserved.

A SHORT COURSE ON C++

Chapter 2 C++ Fundamentals

EC 413 Computer Organization

Chapter 1 Overview of Programming and Problem Solving By C.K. Liang

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Introduction to C++ IT 1033: Fundamentals of Programming

Objectives. In this chapter, you will:

last time in cs recitations. computer commands. today s topics.

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 2: Introduction to C++

Computing and compilers

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA

This watermark does not appear in the registered version - Slide 1

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

INTRODUCTION TO THE COURSE

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Some Computer Preliminaries

Unit 1 : Principles of object oriented programming

download instant at Introduction to C++

Maciej Sobieraj. Lecture 1

Course Outline. Introduction to java

Welcome (back) to CS1007!

Introduction to Computers and Visual Basic.Net Pearson Education, Inc. All rights reserved.

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

LECTURE 02 INTRODUCTION TO C++

Transcription:

CS 241 Computer Programming Introduction Teacher Assistant Hadeel Al-Ateeq 1

2 Course URL: http://241cs.wordpress.com/ Hadeel Al-Ateeq

3 Textbook HOW TO PROGRAM BY C++ DEITEL AND DEITEL, Seventh edition.

4 Grades Evaluation Type Midterms (Midterm 1) (Week # 7) (Midterm 2) (Week # 12) Grade 10% 15% Lab works (HW-Evaluation Quiz) 15% Final Lab 20% Final 40% Total 100% MIGHT Change Hadeel Al-Ateeq

5 Topics Topics to be covered Introduction Data types, variables, values, assignment Sequence, iteration, branching statements Functions Arrays Pointers and Strings Recursion Hadeel Al-Ateeq

6 Outline Introduction. Computer languages: Machine Languages. Assembly Languages. High-Level Languages. C++ System. C++ Standard Library. Basics of a Typical C++ Environment. Structure of C++ program. Input/Output. Program #1: Printing a Line of Text. Program #2: Adding Two Integers. Memory Concepts.

7 Introduction (1-3) Computer Device capable of performing computations and making logical decisions Software Computer programs. Instructions to command computer to perform actions and make decisions. Programs that run on computer

8 Introduction (2-3) Hardware Computer hardware is any physical device (e.g. the computer monitor), something that you are able to touch. Various devices comprising computer Keyboard, screen, mouse, disks, memory, CD-ROM, processing units,

9 Computer Languages Used to write instructions to computer. Some are directly understandable by computers. Others require intermediate translation steps. Types of Computer Languages Machine Languages Assembly Languages High-Level Languages

10 Machine Language (1-2) Only language that computer directly understands. Natural language of computer. Generally consist of strings of numbers (Ultimately 0s and 1s). Instruct computers to perform elementary operations one at a time. Cumbersome for humans. Too slow, tedious and error prone for most programmers.

11 Machine Language (2-2) Example: Adding overtime pay to base pay and storing the result in gross pay +11001101 +00000110 +11110111

12 Assembly Languages (1-2) English-like abbreviations representing elementary computer operations Clearer to humans Incomprehensible (ambiguous) to computers Assemblers: Translator programs. Convert to machine language.

13 Assembly Languages (2-2) Example: Adding overtime pay to base pay and storing the result in gross pay LOAD ADD STORE BASEPAY OVERPAY GROSSPAY

14 High-level Languages (1-2) Similar to everyday English, use common mathematical notations. Single statements accomplish substantial tasks. Assembly language requires many instructions to accomplish simple tasks Compilers: Translator programs. Convert to machine language. Take a considerable amount of time.

15 High-Level Languages (2-2) Example: Adding overtime pay to base pay and storing the result in gross pay grosspay = basepay + overpay Most Used high-level languages: C, C++, VB.NET, etc.

C++ System Program development environment Language C++ Standard Library Hadeel Al-Ateeq

17 C++ Standard Library C++ standard library Rich collections of existing classes and functions Common math calculations e.g. sqrt, sin, cos. Input/output Date/Time Building block approach to creating programs Software reuse.

Basics of a Typical C++ Environment (1-2) Phases of C++ Program: 18 Edit: Programmer types a C++ program (source code.cpp ). Preprocess: obeys commands called preprocessor directives. Indicate that certain manipulations are to be performed on the program before compilation. e.g. include other text files to be compiled. Compile: translates the C++ program into machine language code.

Basics of a Typical C++ Environment (2-2) Phases of C++ Program: 19 Link: links the code with the code for the missing functions to produce an executable program with no missing pieces. Load: load the executable code on memory. Execute: CPU executes the program one instruction at time.

Editor Disk 20 Program is created in the editor and stored on disk. Preprocessor Compiler Linker Loader Disk Disk Disk Disk Primary Memory... Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Loader puts program in memory. CPU Primary Memory... CPU takes each instruction and executes it, possibly storing new data values as the program executes.

21 Structure of a C++ program (1-2) #include<iostream> using namespace std; int main() { return 0; } ; also is important at end of each statement

22 Structure of a C++ program (2-2) #include<iostream> using namespace std; void main() { } ; also is important at end of each statement

Input/ Output cin cout cerr Hadeel Al-Ateeq

24 cin Command Description Standard input stream. Normally keyboard. Used to get input form the user. Syntax cin >> ;

25 cout Command Description Standard output stream Normally computer screen Used to print a specified message on the output screen. Syntax cout << ;

26 Comments Description Document programs. Improve program readability. Ignored by compiler. Used to describe the code segments briefly. Single-line comment begins with //. Multi-line comments begins with /* and ends with */ Syntax // Single line comment /* Multil-ine Comment */ Hadeel Al-Ateeq

27 Preprocessor directives Description Processed by preprocessor before compiling Begin with # Syntax #

Program #1 28 Printing Line of Text (1-6) Question Write a program that prints Welcome to C++. Hadeel Al-Ateeq

Program #1 29 Printing Line of Text (2-6) Preprocessor directive to include input/output stream header file Left brace { begins function body. <iostream>. A keyword indicates that the main returns integer value Function main appears exactly once in every C++ program.. Name cout belongs to namespace std. Corresponding right brace } ends function body. Statements end with a Keyword return semicolon is one of ;. several means to exit function; value 0 indicates program terminated successfully.

Program #1 30 Printing Line of Text (3-6)

Program #1 31 Printing Line of Text (4-6) Standard output stream object std::cout Connected to screen << Stream insertion operator. Value to right (right operand) inserted into output stream. Namespace std:: specifies using name that belongs to namespace std. std:: removed through use of using statements.

Program #1 32 Printing Line of Text (5-6) Escape characters \ Indicates special character output.

Program #1 33 Printing Line of Text (6-6) Escape characters Escape sequence \n \t \r Description Newline: Position the screen cursor to the beginning of the next line Horizontal tab: Move the screen cursor to the next tab stop. Carriage Return: Position the screen cursor to the beginning of the current line; do not advance to the next line. \a Alert: Sound the system bell. \\ Backslash: Used to print a backslash character. \ Double Quote: Used to print a double quote character.

34 Modifying Printing Line of Text (1-4) Multiple stream insertion statements produce one line of output.

Modifying Printing Line of Text (2-4) 35

36 Modifying Printing Line of Text (3-4) Using newline characters to print on multiple lines.

Modifying Printing Line of Text (4-4) 37