Functions Input and output Lecture 2. Constants #define – is a preprocessor directive Most common use.

Slides:



Advertisements
Similar presentations
Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
Advertisements

LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Procedures and Control Flow CS351 – Programming Paradigms.
1 CIS 205 Practice Test George Lamperti A word that has a predefined meaning in a C++ program and cannot be used as a variable name is known as.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Introduction to C++ Programming
Review of C++ Programming Part II Sheng-Fang Huang.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
Working with Strings Lecture 2 Hartmut Kaiser
Chapter 9 Defining New Types. Objectives Explore the use of member functions when creating a struct. Introduce some of the concepts behind object-oriented.
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.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
C ++ Programming Languages Omid Jafarinezhad Lecturer: Omid Jafarinezhad Fall 2013 Lecture 2 Department of Computer Engineering 1.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
1 Lecture 14 Functions Functions with Empty Parameter Lists Empty parameter lists  void or leave parameter list empty  Indicates function takes.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 25 December 1, 2009.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Functions Illustration of: Pass by value, reference Scope Allocation Reference: See your CS115/215 textbook.
LECTURE LECTURE 11 Constructors and destructors Copy constructor Textbook: p , 183.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
1 Advanced Topics in Functions Lecture Unitary Scope Resolution Operator Unary scope resolution operator ( :: )  Access global variable if.
Lecture 2 Functions. Functions in C++ long factorial(int n) The return type is long. That means the function will return a long integer to the calling.
More about strings in C++. String member functions The next three slides present information about functions that are members of the C++ string class.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Using Member Functions and Data Members.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Exploring the C++ Stream Library Copyright 2006 Oxford Consulting, Ltd1 February IO Streams  IOStreams are part of the Standard C++ library.
1 ENERGY 211 / CME 211 Lecture 7 October 6, 2008.
C is a high level language (HLL)
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
Lecture Overview Linked List quiz Finish last class' topic:
Hank Childs, University of Oregon
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
3 Introduction to Classes and Objects.
Chapter 2 part #1 C++ Program Structure
Working with Strings Lecture 2 Hartmut Kaiser
C++, OBJECT ORIENTED PROGRAMMING
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
METHODS AND BEHAVIORS AKEEL AHMED.
One-Dimensional Array Introduction Lesson xx
Value returning Functions
Working with Strings Lecture 2 Hartmut Kaiser
Operator Overloading.
File I/O.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
Announcements Exam 2 Lecture Grades Posted on blackboard
SPL – PS1 Introduction to C++.
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Functions Input and output Lecture 2

Constants #define – is a preprocessor directive Most common use

Constants Avoid global variables

Constants const

Constants Use if the variable is not going to need to be altered by the program

Static

Functions in C++ Return type Arguments (0 – n) Function body Known before main

What is the behaviour of this function?

Functions in C++ In main.cpp order matters

Functions in C++ In main order of declaration is important The keyword final in Java is ‘roughly’ the same as const in C++

Methods in C++

What is wrong with the following code?

Remove the modifier const and a member function can be made static

What happens if a class is made static? Use const arguments for passing variables when they are not going to be altered by the method

Output The static object cout is available through Using >> you ‘stream’ data into the object Favour C++ over C so std::cout over printf

Input The stream object std::cin will allow you to input data The data must have a variable to go into

Input This input assumes everything entered is accepted The function getline (1) istream& getline (istream& is, string& str, char delim); (2) istream& getline (istream& is, string& str);

Input validation

Something you need to do Look up Unified Modeling Language (UML)