Home > Flashcards > Print Preview
The flashcards below were created by user
on FreezingBlue Flashcards. What would you like to do?
What is a function?
A set of steps that performs a task. It can be called using it's name.
What is a member function?
A function in a class that performs one of the class's tasks.
Must you create an object before a function can be used?
Yes, you must create an object of a class before a program can perform the tasks the class describes.
What is a member-function call?
A message sent to an object that tells the object to perform a task.
How are attributes specified in the object's class?
As data members.
What does a class definition contain?
- data members that define the attributes
- data functions that define the behaviors
What keyword begins a class definition?
A class definition begins with the keyword class followed immediately by the class name.
What is the convential form used for user defined class names?
It begins with a capital letter and each subsequent word begins with a capital letter. This is known as camel case.
What is the format of the class? (does it use braces or parenthesis, a semi-colon or no)
Every class's body is enclosed in a pair of braces and ends with a semicolon.
Which access specifier allows member functions to be called by other functions and by member functions of other classes?
public access specifier
Access specifiers are always followed by a _____.
________ is a special return type which indicates that a function will perform a task but will not return any data to its calling function when it completes its task.
What does an empty set of parenthesis after a function name indicate?
The function does not require additional data to perform its task.
How is a function's body delimited?
- with left and right braces
Can you call a member function before you create an object of its class?
Name a reason why C++ is known as an extensible language.
Each new class you create becomes a new type in C++ that can be used to declare variables and create objects.
A _____ can require one or more parameters that represent additional data to perform a task.
A _____ supplies arguments for each of the function's parameters.
How is a member function called?
- following the object name with a dot (.) operator
- the function name
- a set of parentheses containing the function's arguments
What is a string?
- A string represents a string of characters.
- defined in the header file <string>
- the name string belongs to namespace std
What does the function
- reads characters from its first argument until a newline character is encountered
- then places all the characters (minus the newline) in the string variable specified as its second argument
- then discards the newline character
How do you indicate that a function does not require any parameters?
The number of (a) in a function call must match the number of (b) in the parameter list of the called function's header.
- (a) arguments
- (b) parameters
Do the argument types in the function call need to be consistent with the types of the corresponding parameters in the function header?
What are local variables?
Variables declared in a function's body that can only be used from the point of their declaration in the function to the immediately following closing right brace. When a function terminates, the values of its local variables are lost.
A local variable must be _____ before it can be used in a function.
Can a local variable be accessed outside the function in which it is declared?
no, only inside the function
Are data members normally public or private?
Are variables or functions available only to the member functions of the class in which they are declared?
yes, only available to the class's data members and functions
When a program creates an object of a class, what happens to the private data members?
The private data members are encapsulated (hidden) in the object and are only accessible by member functions of the object's class.
When does a function return a result to its calling function?
This happens when the function specifies a return type other than void and completes its task.
What is the initial value of a string?
an empty string (does not contain any characters, or nothing appears on the screen when an empty string is typed)
Do classes often provide member functions to allow clients of the class to set or get private data members?
Yes, and the names of these member functions normally begin with set or get.
What is the purpse of providing public set and get functions for private data members?
It allows clients of a class to indirectly access the hidden data. The client knows that it is attempting to modify or obtain the object's data, but the client does not know how the object performs these operations.
Since data members of a class can access the private information directy, should they use the set and get functions of the class to manipulate the private data?
Yes. If the class's data representation is changed, member functions that access the data only via the set and get functions will not require modification - only the bodies of the set and get functions that directly manipulate the data member will need to change.
Why must a public set function carefully scrutinize any attempt to modify the value of a data member?
to ensure the new value is appropriate for that data member
What is a constructor and why is it needed?
- Each class you declare should provide a constructor to intitialize an object of the class when the object is created.
- A constructor is a special member function that must be defined with the same name as the class, so that the compiler can distinguish it from the class's other member functions.
How are constructors different from functions?
- Constructors cannot return values
- Constructors cannot specify a return type (not even void)
- Constructors are normally declared public
What does C++ require at the time each object is created that helps ensure the object is initialized before it is used in a program?
a constructor call
What is a default constructor?
- A constructor that takes no arguments.
- In any class that does not include a constructor, the compiler provides a default constructor.
- The class programmer can also define a default constructor explicitly. If the programmer defines a constructor for a class, C++ will not create a default constructor.
Can class definitions be reused by programmers worldwide?
Yes, when packaged properly.
Where is a class normally defined?
It is customary to define a class in a header file that has a .h filename extension.
Should the class's clients be required to change if the implementation changes?
What are interfaces?
Interfaces define and standardize the ways in which things such as people and systems interact.
What does the interface of a class do?
- It describes the public member functions (also known as public services) that are made available to the class's clients.
- The interface describes:
- what services clients can use
- how to request those services
- does not specify how the class carries out the services
Why is it considered a fundamental principle of good programming to separate interface from implementation?
- It makes the programs easier to modify.
- Changes in the class's implementation do not affect the client as long as the class's interface originally provided to the client remains unchanged.
What does a function prototype contain?
- a function's name
- it's return type and the number
- types and order of the parameters the function expects to receive
When should the member functions be defined in a separate source-code file?
once a class is defined and its member functions are declared (via function prototypes)
What must precede the function name for each member function defined outside of its corresponding class definition?
- the class name
- the binary scope operator ::
What does class string's length member function return?
the number of characters in a string object
What does class string's member function substr (short for substring) return?
- a new string object created by copying part of an existing string object
- The function's first argument specifies the starting position in the original string from which characters are copied.
- Its second argument specifies the number of characters to copy.
In the UML, each class is modeled in a class diagram as a rectangle with three compartments. What are in these compartments?
- top: class name, centered horizontally in boldface
- middle: the class's attributes (data members in C++)
- bottom: the class's operations (member functions and constructors in C++)
The UML models operations by _____.
- listing the operation name followed by a set of parenthesis()
- a + sign = public
The UML models a parameter of an operation by _____.
listing the parameter name, followed by a colon and the parameter type in parenthesis
Do all the UML data types have the same names as the corresponding C++ types?
no, UML has its own data types
The UML represents data members as attributes by _____.
- listing the attribute name, followed by a colon and the attribute type
- a - sign = private
How does the UML indicate the return type of an operation?
by placing a colon and the return type after the parenthesis following the operation name
Do UML class diagrams specify return types for operations that do not return a value?
How does the UML model constructors?
- as operations in a class diagram's third compartment
- to distinguish a constructor from the operations, the UML places the word "constructor" between guillemets (<< and >>) before the constructor's name