Computer Science homework C++
C++
1. Name three principles of Object Oriented Programming.
2. What is the difference between public and private data members?
3. Name two rules to remember when defining a constructor.
4. When is a constructor called?
5. What is the default constructor?
6. Why would it be incorrect to add the modifier const to the declaration for a member function input()?
7. What are the differences and similarities between a call-by-value parameter and a constant call-by-
reference parameter?
8. When would you use an inline function definition?
9. When would you use a static variable?
10. How does a vector differ from an array?
11. Why would you want to overload operators?
12. How is a friend function different from an ordinary function?
13. Which of the following can be overloaded? [] << >> – ++
14. When overloading an operator, at least one parameter (one operand) of the resulting overloaded operator
must be what?
15. A C-string is the same thing as an array of _____________________.
16. A string variable uses __________________ to mark the end of the string stored in the array.
17. Can you assign a C-string value to a C-string variable using the assignment operator? ______(yes or no )
18. Can you compare the value in two C-string variables using the == operator? _____(yes or no)
19. What does the function cin.get do?
20. What function do you use to read a whole line of characters?
21. Which of the following are equivalent?
char stringVar[10] = Hello;
char stringVar[10] = { H, e, l, l, o, };
char stringVar[10] = = { H, e, l, l, o};
char stringVar[6] = Hello;
char stringVar[] = Hello;
22. What C-string will be stored in singingString after the following code is run? Assume that the code is
embedded in a complete program
char singingString[20] = DoBeDo;
strcat(singingString, to you);
23. What is the length (maximum) of a string that can be placed in the string variable declared by the following
declaration?
char s[6];
24. What string will be output when this code is run? (Assume that this code is embedded in a complete
program)
char song[10] = I did it ;
char franksSong[20];
strcpy (franksSong, song);
strcat(franksSong, my way!);
cout << franksSong << endl; 25. Declare p to be a pointer variable that can hold one pointer that points to a variable of type double. 26. Set the value of p that was declared in question #25 so that p points to the variable v. 27. Assign the value of pointer variable p1 to the pointer variable p2. 28. What is a dynamic variable? 29. What do you call an array whose size is determined when the program is running? 30. Write the code to destroy a dynamic variable p and return the memory it was using to the freestore? 31. What is the correct syntax for the destructor for MyClass ?
