C++ Lecture 1 Friday, 4 July 2003. History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
True or false A variable of type char can hold the value 301. ( F )
C++ Basics Prof. Shermane Austin. Learning Programming Language Basics Data Types – simple Expressions Relational and Logical Operators Conditional Statements.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
CS150 Introduction to Computer Science 1
Lecture 1 The Basics (Review of Familiar Topics).
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 Engineering Problem Solving with C++ An Object Based Approach Chapter 2 Simple C++ Programs.
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Chapter 01: Introduction to Computer Programming
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Programming Languages
High-Level Programming Languages: C++
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Instructor - C. BoyleFall Semester
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
ECE 264 Object-Oriented Software Development Instructor: Dr. Michael Geiger Spring 2009 Lecture 2: Basic C++ Programs.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Semester Review. As we have discussed, Friday we will have in class time for you to work on a program, this program will come with instructions and you.
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Beginning C++ Through Game Programming, Second Edition
C++ Programming: Basic Elements of C++.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Programming Fundamentals. Summary of Previous Lectures Phases of C++ Environment Data Types cin and cout.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Computer Programming in C++ 黃鐘揚 教授 Prof. Chung-Yang (Ric) Huang Department of Electrical Engineering National Taiwan University 2007/06/26.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
Today Variable declaration Mathematical Operators Input and Output Lab
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 3 Selection Statements
Basic Introduction to C#
Introduction to C++ (Extensions to C)
Computing and Statistical Data Analysis Lecture 2
Engineering Problem Solving with C++, Etter/Ingber
1.13 The Key Software Trend: Object Technology
Introduction to C++ Programming
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
Capitolo 1 – Introduction C++ Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
The Fundamentals of C++
Presentation transcript:

C++ Lecture 1 Friday, 4 July 2003

History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm started with "Smalltalk" in 70s, C++ in 80s, and Java in late 90s.

Procedural v.s. Object-Based l Traditional programming languages are procedural - "what to do" in each step (Fortran, Pascal, C) l Object-oriented programming emphasizes "what is" (object, their properties, etc)

OOP l Object-oriented programming is much harder to learn, years of programming experience are needed to be proficient in C++ l C++ supports both procedural and object-oriented programming

Advantage of C++ l Industry standard for software development l Marketable skill in IT jobs l Most advanced features in object oriented languages l Graphical User Interface (GUI) environment (e.g., Visual C++)

What to Cover l Lecture 1, Ch 1,2 l Lecture 2, Ch 3,4 l Lecture 3, Ch 5,15 l Lecture 4, Ch 6 l Lecture 5, Ch 7 l Lecture 6, Ch 9 l Lecture 7, Ch 10 l Lecture 8, Ch 11 l Lecture 9, Ch 12 l Lecture 10, Ch 13, 14 l GUI with visual C++

Buy your textbook if you have not done so "C++ How to Program" 4th edition Deitel & Deitel

A Simple C++ Program, Fig 1.2 l // starts a comment line l for input/output library l The purpose of a header file is to include prototype declaration

Datatypes in C++ l Available built-in data types: int - integer double - double precision float - single precision char - character

Char v.s. String l c = 'a'; // c is a single character l s = "string"; // s may be a pointer // to an array of // 7 characters

Input/Output in C++ l cout << "string"; // for output // to standard out l cin >> variable ; // for input // from standard in to variable

Input/Output in C++ l cout << "string1" << x << "string2" << endl; // concatenating several outputs. l cin >> x >> y ; // input two // numbers

Fig.1.6 l Standard notations for + addition -- subtraction * multiplication / division % modulus

Conditional Statements l If (cond) statement ; l if (cond) { stat1 ; } else { stat2 ; } C.f. Fig.1.14

Logical Comparison l ==equal to l !=not equal to l >greater than l <less than l >=greater than or equal to l <=less than or equal to C.f. Fig.1.14

Result of logical expression is 0 or 1 l In C++, 0 means false, 1 means true (actually, any nonzero values mean true) l e.g. k = 2 < 3; // k gets 1

Loops with while( …) while ( condition ) { statements; } l Programming example, Fig.2.7. Class average grade.

Assignment Operators l X op= Y is equivalent to X = X op Y where op can be +, -, *, /, %, etc l E.g., c += 7;// same as c = c + 7; f /= 3;// same as f = f / 3;

Increment and Decrement Operators l ++ increases a value of a variable by one l decreases the value of a variable by one l ++i value of expression is the value after increment l i++value of expression is the value before increment l in any case, i is added by 1 c.f Fig.14

"for" Loop for( initialize; cond; incre ) { statements; } l E.g.; for(int j = 0; j < 10; j++) { … } C.f. Fig.2.21

I/O Control (iomanip) l setw(w) sets the width of next output to w. l fixed, fixed location for ‘.’ l setprecision(d) prints d digits after decimal point C.f. Fig.2.21

Multiple Choices with "switch" Switch (x) { case 'a': statements; break; case 'b': … default: … } C.f. Fig.2.22

Namespaces l New standard allows the implementation of namespaces. l Each software component (package) can declare a namespace, so name conflicts is minimized. l The standard C++ library has the name space std.

Namespaces l Use the double colon "::" to specify the namespace of a variable. l E.g., std::cout l The std prefix can be omitted if we say using namespace std;

Exercise p.66, 1.19 l A) What, if anything, is printed, assuming x = 2, y = 3. a) cout << x; b) cout << x + x; c) cout < < "x="; d) cout << "x = " << x; e) cout << x+y << " = " << y + x; f) z = x + y; g) cin >> x >> y;

What does the program print? (p.156, 2.15) #include int main() { int y, x = 1, total = 0; while( x <= 10) { y = x * x; cout << y << endl; total += y; ++x; } cout << "Total is " << total << endl; return 0; }

Exercise p.163, 2.38 l Write a complete program to compute exp(x), using the formula exp(x) = 1 + x/1! + x^2/2! + …