Object-Oriented Programming in C++

Slides:



Advertisements
Similar presentations
Introduction to Programming in C++ John Galletly.
Advertisements

Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. About the book Ivor Horton, Beginning ANSI C++: The Complete.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Programming is instructing a computer to perform a task for you with the help of a programming language.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Introduction to C++ Programming
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
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.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
High-Level Programming Languages: C++
1Object-Oriented Program Development Using C++ Computer Science and Programming Languages Computers are ubiquitous Computer literacy is essential Computer.
CIS Computer Programming Logic
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
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.
1 Programming Language History and Evolution In Text: Chapter 2.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Fundamental Programming: Fundamental Programming Introduction to C++
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
C Language: Introduction
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
C++ Lecture 1 Friday, 4 July 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.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
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.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Learners Support Publications Introduction to C++
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Chapter 6: Data Types Lectures # 10.
Introduction to C++ October 2, 2017.
Computer science By/ Midhat Mohiey. Introduction to Programming using C ++ 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
Programming Funamental slides
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Summary Two basic concepts: variables and assignments Basic types:
High Level Programming Languages
Low Level Programming Languages
Chapter 2: Introduction to C++.
Capitolo 1 – Introduction C++ Programming
COMS 261 Computer Science I
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Object-Oriented Programming in C++ Lecture 1 Introduction

Introduction Staff Information Module Blackboard site Fred Pratt K319 Cathy French K233 Module Blackboard site Module Information Descriptor Timetable - 9 lectures + 9 practicals, plus revision/test preparation in Week 4 Assessment – portfolio test Resources – Visual Studio Books Study Space – lecture slides and practical exercises

Assumptions you have studied programming before you are new to C++ Java, C, algorithms, object-orientation you are new to C++ have you studied UML diagrams?

Why learn C++? one of the most widely used programming languages C++ applications are everywhere embedded systems, operating systems, games, real-time systems, servers, applications closely maps to hardware instructions strongly typed, supports OO programming but unlike C# and Java, not every variable and function needs to belong to a class flexible, efficient, stable related to other commonly-used languages C, C#, Java

Computer Science jobs http://www. itjobswatch. co For the 6 months to 29 June 2011, IT jobs within the UK citing Computer Science also mentioned the following programming languages in order of popularity. The figures indicate the number of jobs and their proportion against the total number of IT job ads sampled that cited Computer Science. 1 4253 (36.01 %) Java 2 3466 (29.35 %) C# 3 3278 (27.76 %) SQL 4 2909 (24.63 %) C++ 5 2426 (20.54 %)JavaScript 6 1514 (12.82 %) C 7 1103 (9.340 %) PHP 8 976 (8.264 %) Python 9 762 (6.452 %) Perl 10 490 (4.149 %) Ruby 11 476 (4.030 %) VB.NET 12 434 (3.675 %) T-SQL 13 329 (2.786 %) VB 14 276 (2.337 %) Shell Script 15 256 (2.168 %) Objective-C

Early programming languages Simula Lisp Algol60 Algol68 Fortran Pascal BCPL Classic C COBOL PL\1 Red==major commercial use Yellow==will produce important “offspring” 6 Stroustrup/Programming http://www.stroustrup.com/Programming/lecture-slides.html

Modern programming languages Lisp Python Smalltalk PHP Fortran77 Java95 Java04 Eiffel Simula67 C89 C++ C++98 C++0x Ada Ada98 C# Object Pascal Pascal Javascript COBOL04 COBOL89 Visual Basic PERL Stroustrup/Programming http://www.stroustrup.com/Programming/lecture-slides.html 7

Hello World #include <string> #include <iostream> using namespace std; int main() { string name; cout << "What is your name? "; cin >> name; cout << "Hello, " << name << "!" << endl; return 0; } How does this compare to Java? C? C#?

Comparison to Java main method syntax #include directive no parameter returns an int 0 for success – can omit syntax brackets, semicolons, variables #include directive copy the contents of the named file here using statement use a C++ namespace without qualification similar to importing a Java package

string part of the standard library namespace string is a class like String in Java unlike C-style strings null-terminated character array has useful methods s.size() s.length() s.insert(pos, x) s.append(pos, x) s.erase(pos) pos = s.find(x)

C++ primitive types Type Name Bytes Other Names Range of Values int 4 signed –2,147,483,648 to 2,147,483,647 bool 1 none false or true char –128 to 127 by default signed char –128 to 127 unsigned char 0 to 255 short 2 short int, signed short int –32,768 to 32,767 long long int, signed long int long long 8 –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 float 3.4E +/- 38 (7 digits) double 1.7E +/- 308 (15 digits) wchar_t __wchar_t 0 to 65,535 size is implementation-dependant table is from MSDN and refers to Microsoft Visual C++

Input and output defined in iostream library cin is the standard input stream from keyboard cout is the standard output stream to console window the streams contain a sequence of characters cin >> name; puts the characters in the input stream into the variable name cout << name; puts the characters in the variable name into the output stream

<< and >> operators << sends bytes to an output stream object insertion operator works for all standard C++ data types can concatenate output cout << "Hello, " << name << "!" << endl; endl replaces the C endline character '\n' >> reads bytes from the input stream up to a whitespace character use istream::getLine() function to read multiple words getline(cin, name);

C++ operators similar to Java and C need to know precedence http://msdn.microsoft.com/en-us/library/126fe14k.aspx the same operator can have a different meaning depending on the operand type + << operator overloading when we define C++ classes we can define our own operator overload be sensible!

C++ constructs sequence, selection, iteration constructs are the same as in Java, C and C# unlike C, can declare variables anywhere within a block doesn't need to be at the beginning C++ for loop for (int i=0; i < 5; i++) { cout << "Hello, " << "!" << endl; }

Example – read-ahead while loop int sum=0; int x; cin >> x; while (x!=-9999) { sum=sum+x; } cout << "The sum is " << sum << endl;

multiway if- example int x = 8; if ( x <= 5) cout << "The number is small: "; else if (x <= 10) cout << "The number is medium: "; else cout << "The number is big: "; cout << x << endl The number is medium: 8

C++ bool be careful with boolean operations int x = 5; C++ has a bool data type but integers and booleans are interchangeable (like C) 0 is false, non-zero is true false is 0, true is 1 == comparison operator = assignment operator int x = 5; if (x) true (x is non-zero) if (x==4) false (x is 5) if (x=4) true (x is now set to 4, which is non-zero)

Summary Today we have introduced the C++ language and compared it to other languages same data types and operators but their size can vary between C++ implementations program structure is similar input and output uses iostream sequence, selection, iteration constructs are the same as in Java, C and C# Practical exercises: getting started with Visual Studio and C++ a few simple C++ programs

Further reading “C++: A beginners guide” by Herbert Schildt http://go.microsoft.com/?linkid=8311584 string library http://msdn.microsoft.com/en-us/library/xabz5s9c.aspx fundamental types http://msdn.microsoft.com/en-us/library/cc953fe1.aspx C++ operators http://msdn.microsoft.com/en-us/library/x04xhy0h.aspx