COMPUTER SCIENCE I C++ INTRODUCTION

Slides:



Advertisements
Similar presentations
EC-111 Algorithms & Computing Lecture #1 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Introduction to C Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 1 – Introduction to Computers and C++ Programming Outline 1.1 Introduction 1.2 What is a Computer?
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 1 – Introduction to Computers and C++ Programming Outline 1.6 Machine Languages, Assembly Languages,
Introduction Kingdom of Saudi Arabia Shaqra University
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline History of C and C++ C++ Standard Library Object Technology Basics.
 2008 Pearson Education, Inc. All rights reserved Introduction to C++ Programming.
Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved Computer Organization Six logical units of computer 1.Input unit “Receiving” section Obtains information.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
Introduction to C Programming
Chapter 01: Introduction to Computer Programming
Introduction to C++ Programming
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
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.
Input, Output, and Processing
 2006 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
 2008 Pearson Education, Inc. All rights reserved. 1 CISC 1600 – Computer Science I Fall 2010 Introduction to C++ Programming Chapters 1 and 2 (Deitel.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
Announcements Starting next week class 6-8 on Thursday Homework 1 on the web  Due January 29 – next class meeting  Homework policy No late assignments.
 2006 Pearson Education, Inc. All rights reserved Introduction to C++ Programming.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 Introduction to C++ Programming Outline Introduction Machine Languages, Assembly Languages, and High-Level Languages History of C++ C++ Standard Library.
 2003 Prentice Hall, Inc. All rights reserved Introduction Software –Instructions to command computer to perform actions and make decisions Hardware.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
1.2 What is a Computer? Computer Computer programs Hardware Software
Chapter 2 - Introduction to C Programming
Basic Elements of C++.
Chapter 2 - Introduction to C Programming
Basic Elements of C++ Chapter 2.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
1.13 The Key Software Trend: Object Technology
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 1 – Introduction to Computers and C++ Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Presentation transcript:

COMPUTER SCIENCE I C++ INTRODUCTION

LANGUAGES There are 3 types of Computer Languages 1. Machine Language Only language that the computer directly understands. “Natural language” of the computer Defined by the hardware design (Machine-dependant) Generally consists of strings of numbers (Ultimately 0’s and 1’s) Instructs computers to perform elementary operations - One at a time Cumbersome for humans (or computer science students) Example :

LANGUAGES (CONTINUED) 2. Assembly Language English-like abbreviations representing elementary computer operations Clearer to humans Incomprehensible to computers!!! -Translator programs (Assemblers) convert Assembly to Machine Language Example : LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

LANGUAGES (CONTINUED) 3. High-level languages Similar to everyday English, use common mathematical notations Single statements accomplish significant tasks - Assembly languages requires many instructions to accomplish simple tasks Translator Programs(Compilers) Convert high-level language to machine language Interpreter programs, directly execute high-level language programs Example : grossPay = basePay + overTimePay

HISTORY OF C++ This is an extension of C, it was developed in the early 1980’s by Bjarne Stroustrup (Bell Laboratories) Originally “Spruces up” C! … C++ Provides capabilities for object-orientated programming Objects : reusable software components - they Model items in the real world Object-oriented programs - easy to understand, correct, and modify C++ facilitates structured and disciplined approach to computer program design

C++ STANDARD LIBRARY C++ Programs are built from pieces called classes and functions C++ standard library are rich collections of existing classes and functions C++ is a “Building block approach” to creating programs KEY IDEA is SOFTWARE REUSE!!!

PHASES OF C++ PROGRAMS 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute

BASICS OF C++ ENVIROMENT Input/output - cin Standard input stream Normally keyboard - cout Standard output stream Normally computer screen - cerr Standard error stream Display error messages

PRINTING A LINE OF TEXT Comments - Document programs - Improve program readability - Ignored by compiler - Single-line comment Begin with // - Block comment Begin with /* Closes with */ // is best for one line, but when doing a heading to identify whose program this particular program is… Use block comment!!!

C++ Preprocessor directives - Processed by preprocessor before compiling - Begins with # List of Standard Libraries (you won’t need all of these) but its good to go through and read the libraries for now.

PRINTING A LINE (CONTINUED) 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 using namespace std;

ESCAPE CHARACTERS C++ Escape Characters - \ - Indicates “special” character output

VARIABLES -Locations in memory where value can be stored -Common data types -int – integer numbers -char – characters -double – floating point numbers -Declare variables with name and data type before use -int integer1; -int number2; -int sum; -Can declare several variables of same type in one declaration -Comma separated list -int integer1, number2, sum;

VARIABLES Variable names Valid identifiers - Series of characters (letters, digits, underscores) - Cannot begin with digit - Case sensititve

SIMPLE PROGRAMS Input stream object - >> (stream extraction operator) used with std :: cin Waits for user to input value, then press Enter (Return) key Stores values invariable to right of operator - convert value to variable data type - = (assignment operator) - assigns value to variable - binary operator (two operands) Example : sum = variable1 + variable2;

ARITHMETIC Arithmetic Calculations - * Multiplications - / Division Integer division truncates remainder - 7 / 5 evaluates to 1 - % Modulus operator returns remainder - 7 % 5 evaluates to 2

ARITHMETIC Rules of operator precedence Operators in parentheses evaluated first Nested/embedded parentheses - Operators in innermost pair first Multiplication, division, modulus applied next Operators applied from left to right Addition, subtraction applied last

DECISION MAKING : EQUALITY AND RELATION OPERATORS if Structure Make decision based on truth or falsity of condition If condition met, body executed Else, body not executed Equality and relational operators Equality operators same level of precedence Relational operators same level of precedence Associate left to right if (x == 1) { // do work } else { // do something else }

DECISION MAKING