6 Consider the following main function: int main() { Time t(2, 50); t.setHour(5)
ID: 3868577 • Letter: 6
Question
6 Consider the following main function: int main() { Time t(2, 50); t.setHour(5); t.setMinute(20); cout << "The time is " << t << endl; } What is necessary in the Time class to make this main function compile? None of the above. A friend function called t is needed. The << operator must be overloaded for the Time class The Time class must have the data member t defined in the public area of the class.
7 In which of the following ways can you write an operator overload? (Select all that apply) in a class member function in a friend function in a nonmember function in the main function
8 Suppose cursor is a pointer that points to a penguin node in a linked list using a penguin class that includes a member function get_link(). You wish to move cursor to point to the next node (to the next penguin) in the list. Which statement do you use? cursor++; cursor = cursor->get_link( ); cursor.get_link(); cursor = get_link();
9 Suppose cursor points to a penguin node in a linked list using a penguin class, which includes functions called get_data() and get_link(). What Boolean expression should be true when that penguin node is the ONLY node in the list? cursor->get_data( ) == 0.0 cursor->get_link( ) == NULL cursor == NULL cursor->get_data( ) == NULL
10. The following steps have been performed for deleting a node from a linked list. The nodes have the member accessor function get_link(). The head_ptr points to the head node of a list. Step 1: Set up a local variable called remove_ptr and set it equal to head_ptr Step 2: Set head_ptr equal to the head_ptr->get_link() Step 3: Delete remove_ptr Which of the following situations should use these steps? To delete ALL nodes from a list To delete a node from the middle (neither front nor end) of a list. To delete a node from the front of a list To delete a node from the end of a list
11. Which operation is better for storing items in an array than storing items on a linked list? deleting an item at the beginning (position 0). inserting an item at the beginning (position 0). Growing the size of the container. retrieve a copy of the item at location i.
12. You are working with a node class named node. Suppose that f is a non-member function with a prototype like this with a missing data type in the parameter list: void f(________ head_ptr); // Precondition: head_ptr is a head pointer for a linked list. // Postcondition: The function f has done some computation with // the linked list, but the list itself is unchanged. What is the best data type for head_ptr in the parameter list of this function? node node* & node* node&
13. A virtual function provides you with the ability to have several different functions with the same name in a parent and children classes and have C++ figure out which one to call at run-time. True False
14. Suppose cursor points to a node in a linked list (using the node definition with member functions called get_data and get_link). What Boolean expression will be true when cursor points to the tail node (last node) of the list? cursor == NULL None of the above cursor->get_link( ) == NULL cursor->get_data( ) == NULL
15. You wish to convert a container class to a template container class. Which of the following should you consider? Make sure operations on container data are not type specific. For example, don't use string functions on container data. Make the class visible to the client. One way to do this is to include the main function in the header file. Make implementation visible. One way to do this is to include both interface and implementation in the header file. Make sure all return statements that return container data only return container data. If a return statement returns container data under certain conditions, but another return statement returns something that is not container data under other conditions, there could be a data type conflict when a different data type is used for this template.
Explanation / Answer
#include "stdafx.h" #include #include using namespace std; class Time { private: int hour, minute; //declare hour & min public: Time(); //constructor Time(int h, int m); //initialize hr and min to input void setHour(int); //sets hours void setMinute(int); //sets mins void DisplayTime() const; int GetHour(int&); int GetMinute(int&); int addHour(); int addMinute(); }; void Time::setHour(int hours) { if (0Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.