All of the work in this project is my/our own! I/We have not left copies of my code in public folders on university computers. I/We have not given any of this project to others. I will not give any portion of this project to others taking this class. I realize that the penalty for turning in work that is not my own can range from an "F" in the class to dismissal from Trinity University.
If an answer key is placed on my door, you may not examine the answer key unless you have you have answers to at least 90% of the questions.
Print Name __________________________ Time Required = ______.____ Hrs.
Signature __________________________ (pledged)
Team Mate:
Print Name __________________________ Time Required = ______.____ Hrs.
Signature __________________________ (pledged)
OOP-2 Homework
10 Points
Individual or Team (1-2 Persons)) Assignment
Each Person Must Turn In
His/Her Own Copy! Must Be Hand Written- No Electronic Solutions Accepted.
May be done as a team if and only if both team members participate in answering
each and every question!
Problems Will Not Be Individually Graded - Spot Checked - Mostly Graded As
Totally Complete Or Not!
It is a violation of Academic Integrity at Trinity University to share a copy of
this assignment with anyone outside your team, either during the semester or
after. You are welcome to discuss individual questions with others!
1] ______________________ _?_ is a collection of objects treated as one unit..
2] _____ {T/F} A struct is not an aggregate.
3] _____ {T/F} A class is an aggregate.
4] _____ {T/F} A array is an aggregate.
5] ______________________ A(n) _?_ is an aggregate in which all of the arguments have to be of the same type.
6] ______________________ A(n) _?_ and
A(n) _?_ are aggregates in which all of the arguments do not have to be of the
same type.
7] Write the C/C++ code to create a struct, called Employee, that has a short integer component called Age and a 30 character string component called Name.
8] Write the C/C++ code that could be added to main to create an Employee structure, called Employee1.
9] Write the C/C++ code for a function,
called EmployeeSet, that could be used to place the argument NewName
and the argument NewAge, into the argument pointed to by argument
EmployeePtr.
10] Write the C/C++ code that could be added to main to use the EmployeeSet function to fill the Employee1 struct with your name and age.
11] ______________________ The _?_ is a special class method that does all that is necessary to initialize the class object.
12] ______________________ The _?_ is a special class method that does all that is necessary to destroy the class object.
13] _____ {T/F} The constructor is automatically called each time an object is created.
14] _____ {T/F} The destructor is not automatically called each time an object is goes out of scope.
15] _____ {T/F} Every class must have a destructor.
16] ______________________ ______________________ The slides discuss two specific times that destructors are required. List them.
17] ____________________________________________ If the constructor allocates dynamic memory, then the destructor should generally _?_.
18] ____________________________________________ If the constructor opens a file, then the destructor should generally _?_.
19] Write the C++ code to create a class, called Employee, that has a short integer component called Age and a 30 character string component called Name. You need not include the prototypes for any member functions/methods.
20] Write the complete C++ code for an Employee constructor which will accept the following declaration. Do not overload this constructor.
Employee
Employee1 ("Nancy", 20);
21] Write the C++ code for an Employee constructor which will accept the following declarations. Overload a single constructor in such a way that it will accept all of the signatures. Set the numeric defaults to 0. Set the character defaults to blank.
Employee
Employee1,
Employee2 (30),
Employee1 (20, "Nancy");
22] Write the C++ code that could be added to main to create an array, called BlockBuster, of 20 class Employees.
23] Write the C/C++ code for a method, called Set, that could be used to place the argument NewName and the argument NewAge. Overload a single constructor in such a way that it will accept the same signatures as the constructor in problem 21.. Set the numeric defaults to 0. Set the character defaults to blank.
Employee
Employee1;
Employee1.Set();
Employee1.Set(20);
Employee1 (20, "Nancy");
22] Write the C++ code that could for an Employee Destructor which simply displays the message "Evoking Destructor ~Employee( )".
24] ___________________ The scope operator is _?_.
25] ___________________ A C++ function/method is overloaded if it will accept more than one _?_.
26] One of the signatures for the the function
foo below can be abreviated as(s,l,b). List the other acceptable signatures.
26] Write the C++ code for a function, called
Display, which which is passed an optional Message. If the Message is not blank,
display it on the first line. On a new line, display
"Employee Name:
" + the respective Name. On a new line,
display "Employee
No..: " + the respective No.
27] Circle the functions, in the Student class below, are overloaded correctly and box those functions which are overloaded incorrectly.
class Student
{
public:
Student (char NewName[], long int NewNo=0, bool NewSex=0);
~Student (void);
void Set (char NewName[]="", long int NewNo=0, bool NewSex);
void Display(char Message[]="");
}
28] ___________________ A "Memory Leak" occurs when dynamic memory is allocated but _?_.
29] ___________________ ___________________ ___________________ ADT is an acronym for _?_
30] ___________________ Operators are _?_ in order to enable the programmer to compare a class with a string, numeric, or an other object. Used For Searching & Sorting/Ordering.
31] Write the complete C++ code to create the operator overload that will enable the programmer to make the following comparison: [The explicit return should be boolean!]
if (Employee1 == "Nancy")
32] Write the complete C++ code to create the operator overload that will enable the programmer to make the following comparison: [The explicit return should be boolean!]
if (Employee1 > 111)
33] Write the complete C++ code to create the Name-Oriented operator overload that will enable the programmer to make the following comparison: [The explicit return should be boolean!]
if (Employee1 <= Employee2)
34] ___________________ A "Memory Leak" occurs when dynamic memory is allocated but _?_.
35] The slides describe the 5 things that should be in each and every .hpp file is to contain. List them in the general order that they should appear..
1. _________________________________________________________________
2. _________________________________________________________________
3. _________________________________________________________________
4. _________________________________________________________________
5. _________________________________________________________________
36] ___________________________ Each .hpp also contain an appropriately named #ifndef, #define, and #endif combination to avoid _?_ of variables.
37] In order to avoid duplication of declarations, each .hpp also should contain an appropriately named #ifndef, #define, and #endif combination. Write that sequence for the Employee Class.
38] The slides describe the 2 things that should be in each and every .cpp file is to contain. List them in the general order that they should appear..
1. _________________________________________________________________
2. _________________________________________________________________
39] Partitioning a class into .hpp and .cpp files improves software design in many ways. The slides only specify four of those reasons. List them.
1. _________________________________________________________________
2. _________________________________________________________________
3. _________________________________________________________________
4. _________________________________________________________________
40] Why is compilation faster when you partition a large project, with several classes, into .hpp and .cpp components?
41] Why is project time and cost reduced with good generic .hpp and .cpp class components?
42] Why is better design accomplished through
generic .hpp and .cpp class components?
class Person
{
public:
Name (char NewFirst[] = "", char NewLast[] = "");
~Name(void);
void Set (char NewFirst[] = "", char NewLast[] = "");
private:
int
NoCharsInFirstName,
NoCharsInLastName;
char
*First,
*Last;
};
43] ___________________ In the Person class above, NoCharsInFirstName & NoCharsInLastName would be considered _?_ {Indigenous, Exogenous} data.
44]
___________________ In the Person class above, *First and *Lastwould be
considered _?_ {Indigenous, Exogenous}
data.
45]
___________________ _?_ {Indigenous,
Exogenous } data is not part of the structure, but accessed through pointers
that are in the structure. (i.e. First & Last)
46] ___________________ _?_ {Indigenous, Exogenous } data is completely contained by the structure. (i.e. No)
47] Briefly describe those topics or ideas, from the slides and lecture, that were new to you. ["All of it is not sufficient". Be sepecific --> i.e. ADT, operator overloads, default arguments, etc.]