Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

  1. What C++ references are linked in the NavBar on myCourses? Why are they useful?

    Visual C++ resources on Visual Studios Microsoft website (msdn), Visual C++ resources on Microsoft Developer Network website, Visual C++ Reference on Microsoft Developer Network website (msdn), C++ FAQ on Bjarne Stroustrup’s website, C++ FAQ on Marshall Cline’s website, and cplusplus website are all C++ references on the myCourses’ NavBar.  They all give different resources for C++ needed to use C++ in a person’s programs, and the FAQ websites allow C++ programmers to ask specific questions about C++.  For example if a person did not know how to create a struct in C++, he or she would consult the Visual C++ resources on the msdn website.

  2. What is C++11?

    C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ programming language.


  3. VS2012 doesn’t implement all of C++11. Give a link that summarizes the features.


    http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx

     

  4. What is a declarator?

    Declarators are the components of a declaration that specify names of objects or functions. Declarators also specify whether or not the named object is an object, pointer, reference or array. While declarators do not specify the base type, they do modify the type information in the basic type to specify derived types such as pointers, references, and arrays. Applied to functions, the declarator works with the type specifier to fully specify the return type of a function to be an object, pointer, or reference.


    Source: http://msdn.microsoft.com/en-us/library/tb971bed.aspx

     

  5. Explain the difference between declaration and definition. Given Give an example using a function.
    A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier.  A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities.
    http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration

  6. What is a translation unit?

    translation unit is the basic unit of compilation in C++. It consists of the contents of a single source file, plus the contents of any header files directly or indirectly included by it, minus those lines that were ignored using conditional preprocessing statements.

    A single translation unit can be compiled into an object file, library, or executable program.

    The notion of a translation unit is most often mentioned in the contexts of the One Definition Rule, and templates.

    source: http://www.efnetcpp.org/wiki/Translation_unit

    helpful resource: http://stackoverflow.com/questions/1106149/what-is-a-translation-unit-in-c

     

  7. What is an object file?

    An object file is a file containing object code, meaning relocatable format machine code that is usually not directly executable. Object files are produced by an assemblercompiler, or other language translator, and used as input to the linker, which in turn typically generates an executable or library by combining parts of object files. There are various formats for object files, and the same object code can be packaged in different object files.

    In addition to the object code itself, object files may contain metadata used for linking or debugging, including: information to resolve symbolic cross-references between different modules,relocation information, stack unwinding information, comments, program symbols, debugging or profiling information.


    Source: http://en.wikipedia.org/wiki/Object_file

     

  8. When you compile a C++ program, what are the basic steps the C++ compiler follows?

    http://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html

     

  9. What is a pre-processor macro?
    Short version - a fragment of code which is given a name, wherever the name is used, it is replaced by the contents of the macro.

    Long Version - a pre-processor macro is expression, statement, a block of code, or anything that is defined by a name and the #define preprocessor directive.  Here is the format of a pre-processor macro: #define identifier replacement.  Anywhere in the program where the pre-processor macro name is used, it is replaced by its replacement before compile time.

    Example:

    #define NUMBER_OF_ELELMENTS 2

    int array[] = new array[NUMBER_OF_ELEMENTS];

    Before compile time:

    int array[] = new array[2];

     

  10. Demonstrate how to write an include-guard without using “once.”

    #ifndef WITHOUT_ONCE
    #define WITHOUT_ONCE

    //code here
    #endif

  11. What is a pointer?

    In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.


  12. What is a reference?
    References allow us to address a variable/method in a manner similar to how we use pointers, but with some fundamental differences. For example when you "pass by reference" into a function, you don't create a new object with the same data as that which was passed in; you instead "point" to the existing variable and pull the data from there. This allows us to act upon the stored data indirectly - we can even go so far as to destroy our reference without destroying the original object. To further passing by reference, if we modify the "reference" we actually are updating the variable it refers to.
    References can't be null, unlike pointers - they always refer to data/an object, and after assigned they can't be "reseated" or reassigned, unlike pointers.
    Source: http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

     

  13. Explain the difference between an L-value and an R-value. Demonstrate your response via an example with pointers on either side of an assignment.
    An L-value appears on the left side of an equals sign, where as an R-value is on the right.
    int x = 5;

    int* ptr = &x;

    int refVal = *x;

     

  14. Explain the difference between a pointer and a reference.

    See answers 11 and 12; a pointer can be recast to a different type of pointer, point to different values, etc. where a reference is bound to point to one value only of a certain type. Pointers CAN be null, where references can't be. Extending from this, a reference cannot be uninitialized where a pointer can be (a reference HAS to point to something)

    Sources:
    http://en.wikipedia.org/wiki/Pointer_(computer_programming)http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

     

  15. Demonstrate how to pass by reference via pointers.

    1. int x = 5,*p = &x, &r = (*p); //This is not right.  Pass by reference refers to passing in parameters of a function by reference.

    2.  

      void print(int* x) //print(int* &x) <- this doesn't make any sense. Pass by reference != pass "as" a reference. Just use a pointer. http://stackoverflow.com/questions/1257507/what-does-this-mean-const-int-var

      It actually does make sense.  If you google pass by reference, you will get results passing in arguments of a function by reference.  http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr233.htm

       //Nothing on that page says to do (int * &x), writing this means a reference to a pointer to an int. You can do this in C++, but all that happens when you use it is the Reference gives you the pointer which then you dereference anyway, to get the value you want.

      {

       

                    cout << "x = " << *x << "\n";

       

      }

       

      int x = 5;

       

             int* y = &x;

       

      print(y);

    3. The first answer is correct.  Spoke to Swartz today about clarification about this problem.  It should be pointers passing around a reference not passing in a pointer by reference to a function parameter as part of the definition of passing by parameters.

  16. What operator gives you a short-cut for code like (*p).x?

    "->"


  17. Explain the difference between NULL and nullptr. Why should you switch to nullptr?

    Null is nothing/garbage data, nullptr is a pointer to nothing. Use nullptr because its type safe, because null is an int under the hood. (http://www.devx.com/cplus/10MinuteSolution/35167)

     

  18. Should you pass by value or reference (or even pointer) when passing an array (or other “large” object)? Give a brief of example how bad memory gets and how to fix the issue.

    Passing large arrays by value copies the entire array contents into a second object. Sending by reference only sends the address of the array and doesn’t copy the data.
    Ex: array of a million items, copied makes two million items. 

     

  19. Demonstrate how to allocate an array via a pointer. In the same example, demonstrate how to access and store values in the array, also using pointers. No [] notation allowed!

    http://www.ics.uci.edu/~dan/class/165/notes/memory.html 

    *b = 1;

    *(b + 1) = 2;

    *(b + 2) = 3;

    int x = *(b + 2);

    cout << x // 3


  20. Refer to the above question and give the relationship between pointers and arrays.


    Pointers can be used to represent arrays.

  21. Demonstrate via an example how to create a 2-D array of 3 rows and 2 columns.

    Int n[3][2] = {{1,2},{3,4},{5,6}}; //this is one way of doing it with an initializer, see http://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new

  22. Demonstrate via an example how to create a 2-D array of a user-input number of rows and columns.

    cout<< "Input sizeX of 2D array: ";

    int sizeX;
    cin>>sizeX;

    cout<< "Input sizeY of 2D array: ";

    int sizeY;
    cin>>sizeY;
    int **ary = new int*[sizeY];
    for(int i = 0; i < sizeY; ++i)  
    { 
    ary[i] = new int[sizeX];  
    }


    http://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new

     

  23. Now that you’ve used arrays and pointers, are pointers and arrays the same?

    No.

  24. Read http://c-faq.com/aryptr/aryptr2.html. Now answer the above question again. In your own words, explain the difference(s).

    An array is a named location of items while a pointer points to the starting location of a series of items. Because the array is a named set of items it cannot get items from other areas, but a pointer can change where it is pointing to and get new information.

     

  25. Demonstrate how to store the address of a variable in another variable.
    int otherInt = 4;
    int* x = &otherInt;


  26. Demonstrate how to print the address of a variable.

    Printf(“%i”, &x);

     

  27. What is const correctness and why should you maintain it?

    Const gives you the ability to document your program more clearly and actually enforce that documentation. By enforcing your documentation, the const keyword provides guarantees to your users that allow you to make performance optimizations without the threat of damaging their data. For instance, const references allow you to specify that the data referred to won't be changed; this means that you can use const references as a simple and immediate way of improving performance for any function that currently takes objects by value without having to worry that your function might modify the data. Even if it does, the compiler will prevent the code from compiling and alert you to the problem. On the other hand, if you didn't use const references, you'd have no easy way to ensure that your data wasn't modified.

    Source (and more details!): http://www.cprogramming.com/tutorial/const_correctness.html

     

  28. Demonstrate the difference between a pointer to a constant, a constant pointer, and a constant pointer to a constant. Under what circumstances can you change values for each?

    1. Int Const* x : can change the pointer but not the value of whats being pointed at
    2. Int* const y; : can change the value of whats being pointed at, but cannot change what to point to
    3. Int const * const z; cannot change either the value of whats being pointed at or change what to point to

     

  29. Are references automatically constant? Justify your response with examples.
    Yes, because a reference does the following:

    • It is not possible to refer directly to a reference object after it is defined; any occurrence of its name refers directly to the object it references.
    • Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers.

    This means that a reference once created cannot be changed - if this occurs, then we are dealing with a const.

    Example: 

    int x = 3;
    int &y = x;
    cout<<"value of x is:"<< x <<endl;
    cout<<"value of y is:"<< x <<endl;
    cout<<"X mem address: " << &x <<endl;//note the address
    cout<<"y refers to mem address: "<< &y <<endl;//note the address

    //now lets do some basic math
    x++;
    cout<<(y==4)<<endl; //should be true, aka 1
    y++;
    cout<<(x==5)<<endl; //should be true, aka 1

    //Lets try to assign new values/refs!
    int z = 10;
    cout<<"z mem address is: "<< &z <<endl;
    y=z;//should assign x to be 10 (the value of z). However, it doesn't now refer to z, just copies the data.
    cout<< "y refers to mem address: "<< &y <<endl;//should be the same address as before - we're referring to the same thing

    //the following code is commented out as it CAN'T work -- there cannot be any re-assignment after creating a reference. The value it refers to may change, but where it's pointing is constant
    //&y= z;
    //y= &z;

     

  30. Explain the difference between a C-string and C++ string.
    A C string is a char array terminated by '\0' whereas a C++ string is an actual class/data type.
    http://cs.stmarys.ca/~porter/csc/ref/c_cpp_strings.html

     

  31. Does char s[] = {'h','e','l','l','o','\0'}; create a C-string? Why or why not?
    Yes it creates a C-string, because it is an array of chars with a null-terminating char, ‘\0’.

  32. Demonstrate how to convert a user-input string into its numerical equivalent, i.e., what is C++’s way of doing int.Parse()? Better yet, include exception handling.

    try

              {

                       int integerInput;

                       string stringInput;

                       cin >> stringInput;

                       stringstream converter(stringInput);

                       converter.exceptions(ios::failbit | ios::badbit);

                       converter >> integerInput;

              }

              catch(exception& e)

              {

                       cout << "exception occurred: " << e.what() << endl;

    }

  33. Define the function for the declaration int length(char* c), which returns the length of an input string. You must not use array notion ([]) anywhere in the solution. Hint: you must use pointers.

    int length(char* c) {

    int length = 0;

    while ( *c != NULL ) {

     c++;

      length++;

    }

    return length;

    }

  34. Demonstrate how to allocate and free memory via malloc/free.

    int main()
    {
    	int *p;
    
    	p = (int *)malloc(sizeof(int));
    	if (p == 0)
    	{
    		printf("ERROR: Out of memory\n");
    		return 1;
    	}
    	*p = 5;
    	printf("%d\n", *p);
    	free(p);
    	return 0;
    }

    Source:
    http://computer.howstuffworks.com/c29.htm

     

  35. Demonstrate how to allocate and free memory via new/delete.

     int* number = (int*)malloc(sizeof(int));

    free(number);

  36. Can (or even should) you “mix” malloc/delete or new/free? Why or why not?

    Always delete what you new, and free what you malloc, never mix new with free or malloc with delete. 

    The reason for this is that if you do that, then the behavior is technically undefined because there is no guarantee thatnew would internally use malloc, or that delete would internally use free.

    Source:
    http://www.codeproject.com/Articles/6555/To-new-is-C-To-malloc-is-C-To-mix-them-is-sin

     

  37. What is a memory leak, and why is it bad?

    A memory leak occurs when the program incorrectly does memory management.  Memory leaks can slow down programs by requesting for more memory than needed for the programs, eat up all of the available memory on the device and then request for more memory causing the program to crash, and cause additional crashes such as when shared memory is not released when appropriate to do so.

  38. What operator do you call to prevent memory leaks?
    delete

  39. What tools/functions could you use to detect memory leaks?

    Instruments for Xcode and Visual Leak Detector and Microfocus for Visual Studios are tools used to detect memory leaks.  Use the CRT library to detect and report back memory leaks. 

     

  40. What is a smart pointer, and how does it help with memory leaks?

    A smart pointer is an abstract data type that simulates a pointer while providing additional features such as automatic memory management or bounds checking.  It prevents most situations of memory leaks because of its automatic memory management feature.

     

  41. Which smart pointers does VS2012 support?

    Many types:

    unique, shared, weak

    http://msdn.microsoft.com/en-us/library/vstudio/hh279674.aspx


  42. What is an initializer? Give some examples of different kinds of initializers.

    An initializer is the programming construct that performs the initialization.  It consists of the ‘=’ character followed by an expression or comma-separated list of expressions placed in curly brackets. 

    Examples:

    int x = 0; // = 0 is the initializer

    int array[2] = {1, 2};// = {1, 2} is the initializer

    Person person = new Person(); //= new Person() is the initializer

  43. Demonstrate how to create and initialize an array.

    int arrayOfNumbers[] = {1, 2, 3, 4, 5};

  44. Explain the differences between expressions, statements, and expression-statements. Given C++ examples of each.

    Expressions is the smallest unit of computation consisting of one or more operands and usually an operator to produce a result, but a statement are actions that a program can take and can contain 0 or more expressions.  Expression statements are expressions followed by a semicolon.

           Examples:

           2 + 3 //Expression

           if(thisIsAStatement) cout << “This is a statement” << endl; //Statement

           int i = 2 + 3; //Expression-statement

  45. Does C++11 support a native for-each statement? Does VS2012 support it?
    Yes, they both support native for-each statement.

  46. Explain instance variables, data members, and fields with respect to classes. Do the concepts to which these terms refer differ in any great fashion?

    Instance variables are variables that are an instance/copy of a class.  Fields are variables declared inside of a class.  Data members are members declared in the class along with all members (except constructors and destructors) declared in all classes in its inheritance hierarchy. Members include the following: fields, constants, properties, methods, operators, events, indexers, and nested types.

    Sometimes fields and members are mixed up with each other even though data members contain fields along with other member types.

  47. Explain the differences and similarities of plain-old data types and structs.

    Plain-old data type is a struct or class without constructors, destructors, user-defined copy assignment operator,  private or protected non-static data, no base classes, and virtual members functions whereas structs have a very similar structure to classes except the members and base classes are default set to public in structs.  Therefore structs can have everything that a plain-old data type doesn’t have.  However both can be used to store data within a structure.

  48. Explain the differences and similarities of structs and classes.

    In c++ they are pretty much the same except for syntax and structs’ methods and fields are by default public while classes are by default private.

    http://stackoverflow.com/questions/2750270/c-c-struct-vs-class


  49. Give an example of a struct that might help graphics programming.

    struct point3d {

    float x;

    float y;

    float z; 

    };


  50. You probably never covered unions in your prior course, but they sometimes get asked at an interview. What are they?

    union is a user-defined data or class type that, at any given time, contains only one object from its list of members
    http://msdn.microsoft.com/en-us/library/5dxy4b7b.aspx


  51. Explain the difference between the stack and the heap with respect to OOP.

    Stack is "scratch-space" memory for the program while it is executing. Heap stores dynamically allocated memory and it not allocated per each new scope like the stack.
    http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap


  52. Actually, what’s wrong with the above question with respect to C++? Hint: who invented C++? What did he call “the heap?”

    Bjarne Stroustrup. He called it the “Free-Store”.

    http://stackoverflow.com/questions/1350819/c-free-store-vs-heap 


  53. Demonstrate how to create a stack-allocated object from a class.
    Person person;

  54. Demonstrate how to create a heap-allocated object from a class.
    Person* person = new Person();

  55. Why are memory alignment and the heap a “big deal” with respect to game engines?
    If you do not use memory alignment correctly, the dynamically allocated memory on the heap will become fragmented.  Because of this fragmented memory, you will have a hard time to find appropriate chucks of memory that can be dynamically allocated and cause performance issues in the long run.

  56. Under what circumstances do object fields get zero-initialized in object creation? Does it matter if the object is stack or heap allocated?
    The object fields are zero-initialized by default when the object’s constructor is called at object creation time, and the object must be heap allocated because the constructor needs to be called to zero-initialize the object fields.

  57. C++ supports static. Demonstrate how to assign and use static data members, global values, and static functions.

    static int x = 5;//static data member

           static int y = 6;//static global value

           static int calculateSumOfTwoNumbers(int x, int y)

           {

                   return x + y;

           }

           void printResult()

           {

                   int result = calculateSumOfTwoNumbers(x, y);

                   cout << result << endl;

           }

  58. Think about const and how it relates (if at all) with static. Since const means “not changeable” and static seems to mean something similar, why did the creators of C++, Java, C#, … actually use the keyword static given the possible confusion. Hint: What’s the antonym of “static?”

    Static exists only in one spot, i.e. it belongs to a class or a function, but it can be changed. When it is changed, it is changed for any and all instances of that class or for anyone who calls that function.

    Const means that it cannot be changed. Multiple objects may have different const variables, but their individual copies of it cannot be changed.

    The two keywords can be used together also.

    http://stackoverflow.com/questions/2216239/what-is-the-difference-between-a-static-and-const-variable


  59. Explain the meaning of “special member function” and give examples using the “Big-Three” of C++.
    A special member function is a function that the compiler automatically generates if it is used and not declared explicitly by the programmer.  Examples of special member function using the “Big-Three” of C++ are copy constructor, copy assignment operator, and destructor.

  60. If you do not provide special member functions for a class, which ones does C++ provide by default?

    Default constructor, copy constructor, move constructor, copy assignment operator, move assignment operator, and destructor.

  61. When should you provide special member functions?
    When you need to override the special member function.  For example, you override the default constructor with a custom one that initializes the number of ships field of a spaceship captain class to 5.

  62. Explain the difference between a copy constructor and copy assignment operator overload.

    A copy constructor is used to initialize a previously uninitialized object from some other object's data.

    An assignment operator is used to replace the data of a previously initialized object with some other object's data.


  63. Speaking of overloading, is it the same principle as overriding? (Schwartz asks this question every year, and students continue to get it wrong. Hint: look up inheritance.)

    Overriding is writing a new behavior onto a new function. Overloading is creating a function with the same name and more parameters.

    Thus if you overload you create a new function, that has the same name as another, but is totally separate and identified from the other via the parameters.


  64. What is a destructor? Give an example of when you need to define one.

    Destructors deallocate memory and do other cleanup tasks for an object when it is destroyed.

    If you want your object to print a message to the console when it is being destroyed then you need to define your own destructor.

    http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr380.htm


  65. Demonstrate a conversion constructor.

    class Point
    {
    public:
       Point(); // constructor
       Point( int ); // conversion constructor
       //...
    };

    http://msdn.microsoft.com/en-us/library/s2ff0fz8.aspx 


  66. Demonstrate a conversion function.

    struct Money {
      operator double() { return _amount; } //conversion function

    private:
       double _amount;
    };

    int main() {
      Money Account;
      double CashOnHand = Account;
    }

    http://msdn.microsoft.com/en-us/library/5s5sk305.aspx 


  67. Demonstrate a function pointer.

    void *(*foo)(int *); 

    http://www.cprogramming.com/tutorial/function-pointers.html


  68. You’ll notice size_t quite a bit in C++ reference pages, e.g., http://msdn.microsoft.com/en-us/library/y1w9bk0b.aspx and many others. What is it?
    size_t is an alias to one of the fundamental unsigned integer types that is able to represent the size of any object in bytes and is widely used to represent sizes and counts in the standard library.

  69. What is structure padding and how should you avoid it?

    Structure padding occurs when members of a structure must appear at the correct byte boundary and the compiler adds padding bytes to achieve this.  It can be avoided by looking at the order of the members in a struct and ordering them in such a way that is taking byte boundary for different data types into consideration so that padding bytes are not added on unnecessary in order to have the next member be at the correct byte boundary.

    Example:

    struct example {

    char c1;

    short s1;

    char c2;

    long l1;

    char c3;

    }//16 bytes because of structure padding

    struct example {

    long l1;

    short s1;

    char c1;

    char c2;

    char c3;

    }//12 bytes because of no structure padding

  70. Explain the difference between an unsafe and static cast. Which should you generally use when not worrying about inheritance or polymorphism?
    Unsafe cast is an implicit or explicit cast that has run-time checking while static cast way to cast to one type to another without run-time type checking.  You should use a static cast when not worrying about inheritance or polymorphism.

  71. How do you “do” a “this” in C++? Give a few examples.

    "this" is actually a pointer, as described here:
    http://www.tutorialspoint.com/cplusplus/cpp_this_pointer.htm

     

  72. How do you a “ToString” in C++? Give an example. Demonstrate your response via code that would work in VS2012.

    std::ostream& operator<<(std::ostream &strm, Point const &point)

           {

                   return strm << “Point: (”point.x << “, “ << point.y << “)”;

           }

  73. What is purpose of friend? Demonstrate how to use friends in classes.

    It is often useful for one class to see the private variables of another class, even though these variables should probably not be made part of the public interface that the class supports. For instance, if you were writing a binary tree, you might want to use a Node class that has private data, but it would still be convenient for the functions that actually combine nodes together to be able to access the data directly without having to work through the Node interface. At times, it may not even be appropriate for an accessor function to ever give even indirect access to the data. C++ provides the friend keyword to do just this. Inside a class, you can indicate that other classes (or simply functions) will have direct access to protected and private members of the class. When granting access to a class, you must specify that the access is granted for a class using the class keyword.


    Example:

     

    class Node 
    {
        private: 
        int data;
        int key;
        // ...
    
        friend class BinaryTree; // class BinaryTree can now access data directly
    };

     

     

    class Node 
    {
        private: 
        int data;
        int key;
        // ...
    
        friend int BinaryTree::find(); // Only BinaryTree's find function has access
    };


    Sources:
    http://en.wikipedia.org/wiki/Friend_class

    http://www.cprogramming.com/tutorial/friends.html

     

  74. Why do you need both #include <iostream> and using namespace std;? What happens if you leave one out? What does each line do? Demonstrate how to avoid writing using namespace std;.

    You need #include <iostream> to do any stream writing or reading and the using namespace std to use any standard library functionality.  If you leave one of them out, then neither will work. 

           std::cout << “hello world << std::endl;

  75. Why do you need to split your code into header and CPP files?

    The header serves to be the template of the class while the CPP files contains the implementations of the class.

  76. What is a circular class definition, how do you resolve it?
    Circular class definitions occur when two or more classes are dependent on one another in order to be initialized. This can be resolved either by changing the code to follow a different design pattern (ex. MVC, so that only one thing can modify the other, while a third thing displays the changes) or by using forward declaration when creating the objects.
    http://en.wikipedia.org/wiki/Forward_declaration

     

  77. What happens if you attempt to write a class (or struct) called Point in VS2012. Does the compiler accept the name? If not, what should you do to fix the problem?
    The compiler does accept the name.

  78. What is an abstract data type, and why does that term arise when discussing the design and implementation of data structures?

    An abstract data type is a data type that combines the common functionalities from different related objects into one package and can be used for design and implementation of data structures that wish to inherit from the abstract data type.

  79. What kind of list should you use to limit memory allocation?
    Use an array to limit memory allocation as arrays have a defined size while linked lists can have an indefinite size by adding more nodes onto the linked list.

  80. Does C++ have a class Object/object?

    No. You can sort of fake them with templates (and technically all instantiated classes are "objects" conceptually, but are only of that class type, not an object).

    Source: http://www.cplusplus.com/forum/beginner/25721/

    Source: http://stackoverflow.com/questions/11747439/c-object-class

     

  81. A Thing is a creature with a single letter (A-Z) for its name. When they’re born they get a random letter for their name. Things can have the same name. Write a list class, node class, and a test class in which you generate a list of four random Things. Use header and C++ files. You can skip using inheritance for now.

    //Thing.h

    #pragma once

    #include <stdlib.h>//for rand

    #include <iostream>

     

    class Thing

    {

    public:

           char name;

           Thing(void);

           ~Thing(void);

    private:

           void generateName();

    };

     

    //Thing.cpp

    #include "stdafx.h"

    #include "Thing.h"

     

    Thing::Thing(void)

    {

           generateName();

    }

     

     

    Thing::~Thing(void)

    {

    }

     

    void Thing::generateName()

    {

           //Generate a random number that corresponds to the characters A - Z in the ASCII chart

           name = char(rand() % 25 + 65);

           std::cout << "Name of thing: " << name << std::endl;

    }

     

    //Node.h

    #pragma once

    #include "Thing.h"

    class Node

    {

    public:

           Node* next;

           Node(void);

           Node(Thing* thing);

           ~Node(void);

    private:

           Thing* data;

    };

     

    //Node.cpp

    #include "stdafx.h"

    #include "Node.h"

     

    Node::Node(void)

    {

     

    }

     

    Node::Node(Thing* thing)

    {

           data = thing;

    }

     

     

    Node::~Node(void)

    {

           delete data;

           data = nullptr;

    }

     

    //List.h

    #pragma once

    #include "Node.h"

    class List

    {

    public:

           List(void);

           ~List(void);

           void addNodeToList(Thing* thing);

    private:

           Node* head;

           Node* currentNode;

           Node* tail;

           void removeAllNodesInList();

    };

     

    //List.cpp

    #include "stdafx.h"

    #include "List.h"

     

    List::List(void)

    {

          

    }

     

    List::~List(void)

    {

           removeAllNodesInList();

    }

     

    //Add nodes onto the end of the list

    void List::addNodeToList(Thing* thing)

    {

           //Initialize the head if it is null, otherwise just add another node onto the list

           if(head == nullptr)

           {

                  head = new Node(thing);

                  currentNode = head;

           }

           else

           {

                  currentNode->next = new Node(thing);

                  currentNode = currentNode->next;

           }

           tail = currentNode;

    }

     

    void List::removeAllNodesInList()

    {

           //Start deleting nodes from the beginning of the list

           //until the last node is reached

           while(head->next != nullptr)

           {

                  currentNode = head;

                  head = head->next;

                  delete currentNode;

                  currentNode = nullptr;

                 

           }

           //Head and tail are now pointing at the last node

           delete head;

           head = nullptr;

           tail = nullptr;

    }

     

     

     

    //Test.h

    #pragma once

    #include <time.h>

    #include "List.h"

    #include "Thing.h"

     

    class Test

    {

    public:

           Test(void);

           ~Test(void);

           void generateThings(int numberOfThingsToGenerate);

    private:

           List* list;

    };

     

    //Test.cpp

    #include "stdafx.h"

    #include "Test.h"

     

    Test::Test(void)

    {

           srand(time(NULL));

           list = new List();

    }

     

     

    Test::~Test(void)

    {

           delete list;

           list = nullptr;

    }

     

    void Test::generateThings(int numberOfThingsToGenerate)

    {

           for(int i = 0; i < numberOfThingsToGenerate; i++)

           {

                  list->addNodeToList(new Thing());

           }

    }

     

    //LinkListThings.cpp

    #include "stdafx.h"

    #include "Test.h"

     

    int _tmain(int argc, _TCHAR* argv[])

    {

           Test* test = new Test();

           test->generateThings(4);

           system("pause");

           delete test;

           test = nullptr;

           return 0;

    }

  82. Explain the difference(s) between a stack and queue.

    Both are linear data structures; the only difference is really in HOW they add/remove/access data within the structure. Simply put, stacks are LIFO (last in first out) and queue are FIFO (first in first out) in how they access the "first" object in the data structure (i.e. the top of the stack or the front of the queue).
    http://www.cs.cmu.edu/~adamchik/15-121/lectures/Stacks%20and%20Queues/Stacks%20and%20Queues.html

     

  83. Explain the difference between an array-based queue and a list-based queue. Under what circumstances should you use an array-based queue, and what is its name?
    An array-based queue is a circular buffer backed by an array while a list-based queue is a single linked list with a head and tail pointer.  You should use an array-based queue when you need to quickly access an element.  In a link-based queue, you would have to traverse through the linked list to get the element you want to access.  The name of an array-based queue is a heap.

  84. If you were asked to write a binary search tree with parent pointers on a white board for a technical interview, could you do it? What should you do in the meantime?
    I could possibly do it with clarification on what parent pointers are.  I would first ask what are parent pointers and then proceed with designing the binary search tree with parent pointers.  Once I got the design down, then I would write on the white board the solution with an explanation for each step of my algorithm.

  85. What is asymptotic complexity? What does it mean if you refer to space or time complexity of an algorithm?
    Asymptotic complexity is the usage of the asymptotic analysis, analysis of limiting behavior, for the computational complexity estimation of algorithms and computational problems.  It is most commonly associated with the usage of big O notation.  Space complexity of an algorithm refers to the amount of memory which is needed by the algorithm to run to completion while the time complexity of an algorithm is how long it takes for the algorithm to run to completion.

  86. Explain the difference between Big-O and Big-Omega complexity classes. What are the Big-O and Big-Omega of “get” and “search” in a priority queue.

    1. Big-Omega of “get” and “search” in a priority queue.

           Big-O complexity assumes the worst case scenario of the algorithm while Big-Omega assumes the best case scenario of the algorithm.  get: O(log n), Big-Omega(1)  search: O(n), Big-Omega(1)

  87. By the way, how does a priority queue differ from a queue?

    A priority queue is similar to a queue, but its elements each has a priority associated with it.  The elements are ordered according to their priority with the highest priority being popped off first and the lowest one last.  If there is two elements that have the same priority, then their order of being inserted into the queue is considered instead.

  88. Draw an example of a directed acyclic graph (DAG).
    Draw circles around the numbers and have the circles point to each other as shown below. DAG is essentially a graph that has arrows that go one way and cannot loop back.
    1 -> 2 -> 3

  89. How does knowing how to explain a DAG help you to understand C++? See http://msdn.microsoft.com/en-us/library/84eaw35x.aspx.
    Class hierarchies in C++ is similar to a DAG, because the relationship of classes in inheritance only goes in one direction from child class to the parent class and can never be in a cyclic relationship.

  90. Explain the difference between breadth-first vs. depth first for graph search.
    Depth first searches use a stack, and breadth first searches use a queue, resulting in their respective search behaviors as elements are added and removed from the corresponding data structure.
    It's worth noting that you can parallelize a breadth first search, but not a depth first search as well... 

    (source/reference: http://stackoverflow.com/questions/10602392/why-is-bfs-better-suited-to-parallelization-than-dfs)

  91. Can you drag a file into a C++ VS2012 project and make it “stick?” For example, see if you can drag a file in from elsewhere, zip up the project, and submit it.
    Yes.

  92. Without doing any “cleaning,” look at the size of a VS2012 project from one of the problems in this assignment. How can you reduce the project size such that the zip file is manageable?
    You can reduce the executable of the project significantly by following these steps: changing the build from debugging to release mode, changing the runtime library to Multi-threaded, change ignore all default libraries to Yes, change entry point to WinMain, change generate manifest to no, change randomized base address to Disable Image Randomization, change merge sectoins to .rdata=.text, change optimization to Minimize Size(/O1), change enable instrinsic functions to No, and change whole program optimization to NO.  You can also remove the .sdf file with contains Visual Studios Intellisense.

  93. Give one review question we should ask next time not already covered in this assignment.