Part 3 - Control Structures, Operators, Classes and Objects Flashcards
What 3 types of control structures exist?
Selection: if, else, switch
Repetition: while, do, for
Exception: try/catch
What is the difference between break and continue?
break will take you completely out of the loop
continue will start the next iteration of the loop
What does declaring a function inline do?
Causes a copy of the code to be inserted into the code generated by the compiler instead of a function call
If a function is a member of a class it must be applied to _________________ unless it is defined as static
An object of that class
How can one give the value 5 a leading 0 when outputting?
cout << setfill(‘0’) << setw(2) << val << endl;
What does setw do?
Sets the field width of the next item to be output
What does setfill do?
Sets the fill character to be used for all subsequent outputs
What 3 visibility specifiers exist in C++?
public
private
protected
What is private visibility?
Private members can only be accesses in functions of the class and its friend functions
What is protected visibility?
Protected members can only be accessed in functions and friend functions of the class or subclasses of the class
What is public visibility?
Public members can be accessed anywhere in the program as long as the class is in scope
What is the default visibility level?
Private
If no constructor is provided for a class the compiler will generate a __________
No argument constructor
What does a default no argument constructor do?
Calls the no argument constructors of any members of the class that are class objects
Will NOT initialise any primitive objects
Where should default parameters for constructors be specified?
In the constructor definition in the header file