Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Functions Input and output Lecture 2. Constants #define – is a preprocessor directive Most common use."— Presentation transcript:

1 Functions Input and output Lecture 2

2 Constants #define – is a preprocessor directive Most common use

3 Constants Avoid global variables

4 Constants const

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

6 Static

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

8 What is the behaviour of this function?

9 Functions in C++ In main.cpp order matters

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

11 Methods in C++

12

13 What is wrong with the following code?

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

15 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

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

17

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

19 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);

20 Input validation

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


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

Similar presentations


Ads by Google