Lecture 19 CIS 208 Wednesday, April 06, 2005. Welcome to C++ Basic program style and I/O Class Creation Templates.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ fundamentals.
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Introduction to C++ Systems Programming. Systems Programming: Introduction to C++ 2 Systems Programming: 2 Introduction to C++  Syntax differences between.
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:
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
CPSC 252 Operator Overloading and Convert Constructors Page 1 Operator overloading We would like to assign an element to a vector or retrieve an element.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chapter 9 Strings. Learning Objectives An Array Type for Strings – C-Strings Character Manipulation Tools – Character I/O – get, put member functions.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
Object-Oriented Programming (OOP) and C++
LESSON 2 Basic of C++.
CS116 SENEM KUMOVA METİN. Outline What is C++ ? Some features of C++ Input and Output Operations Manipulators C++ header files Namespaces and scope resolution.
Slide 1 Chapter 9 Strings. Slide 2 Learning Objectives  An Array Type for Strings  C-Strings  Character Manipulation Tools  Character I/O  get, put.
Prepared by Andrew Jung. Contents A Simple program – C++ C++ Standard Library & Header files Inline Functions References and Reference Parameters Empty.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Lecture 3: Getting Started & Input / Output (I/O)
Chapter 15 - C++ As A "Better C"
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Review 1.
Introduction to C++ (Extensions to C)
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.2 Introduction to C++ Programming
LESSON 2 Basic of C++.
Introduction to C++ Systems Programming.
Basic Elements of C++.
CS3340 – OOP and C++ L. Grewe.
C++ Classes & Object Oriented Programming
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Course websites CS201 page link at my website: Lecture slides
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Chapter 15 - C++ As A "Better C"
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Chapter 2 part #3 C++ Input / Output
Functions Imran Rashid CTO at ManiWeber Technologies.
TOPIC: FUNCTION OVERLOADING
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Lecture 19 CIS 208 Wednesday, April 06, 2005

Welcome to C++ Basic program style and I/O Class Creation Templates.

C++ OOP Allows for more complex programs C starts to break down Better data protection Much more programmer control

some C++ features Exception Handling an actual string type and bool type Function Overloading/Constructors Operator overloading. redefine what the + operator can do

OOP basics Encapsulation Polymorphism Inheritance.

Encapsulation Binding Data and functions together in nice, neat packages. Private and public data and functions Implemented as Classes.

Polymorphism ‘One interface, multiple methods’ Multiple functions with the same name. Don’t care how something works on the interior, just that it does something

Polymorphism Example In c, abs(), fabs(), labs(): Absolute value functions. Each takes different type of parameter. Annoying to remember which one does which.

Function Overloading in C++, define a single function name that can handle multiple types of data. in C++, there is just a abs() function.

Inheritance An object may acquire properties of another. Example. Red Declicious apple is a type of apple, which is a type of fruit, which is a type of food.

Our first C++ program #include using namespace std; int main() { cout << "this is output. \n"; cout << "Enter a number: "; int i; cin >> i; cout << i << " squared is " << i*i <<"\n"; for (int j =0; j < i; j++) cout << "iteration " << j << '\n'; return 0; }

Compiling best to use g++ Same commands as gcc. (-o for name of executable)

#include using namespace std; iostream == stdio. Don’t need.h if using namespace

C libraries Can use old C headers (math.h, string.h) math.h == cmath string.h == cstring

namespace ignore for right now. #include == #include using namespace std;

function declaration nearly same as C int main() {… Don’t need to put void as a parameter, still need void if no return. Must still have function

Local Variables Can be declared anywhere. Normal scope rules. Only know in current code segment and only after declaration. Declaring at beginning might make better code though

Basic output cout << “This is output\n”; prints ‘This is output’ to console. May still use any of the old functions printf, puts, putch, etc

cout << << is the output symbol cout is the destination (console) Arrows point towards destination cout << “hello” << “ world”;

cout << works on any basic data type. No format specifiers. Can chain multiple types together int j; char k; float m; cout << j << k << m;

cout << use casting to alter appearance float j = 1.5; cout << (int) j;

cout << can use expressions or function calls int j = -2; cout << j *j << “ “ << abs(j);

Basic input int j; cin >> j; Reads an int from the keyboard and stores it in variable j. No & necessary. cin >> knows what to do.

cin >> again, arrows point to destination. Will still want to flush buffer. Works on all basic types, and strings

cin >> multiple reads. char x, y, z; cin >> x >> y >> z; takes first 3 chars and stores in x,y,z; blank spaces don’t count

cin >> use multiple types int x; char y; float z; cin >> x >> y >> z; be careful, this can get tricky.