The source is managed and stored on github.swarthmore.edu. By managed, changes to the source are kept track of with revision control. Revision control makes it easy to keep track of changes, maintain multiple versions of software, collaborate with others, and to revert to specific code versions.
You will need a Swarthmore git account for submitting assignments. If you don't have one already, instructions are here.
> mkdir cs91 > cd cs91 > git clone git@github.swarthmore.edu:cs91-s17/A0Hello-YOURUSERNAME.git A0Hello
You should now have a directory named A0Hello with code examples for this lab and this week's assignment.
> cd A0Hello > mkdir build > cd build > cmake .. > make
IMPORTANT: Do not check in temporary files in build!!! This should not occur because build* is listed in .gitignore.
Two executables are built. A simple C++ example and a simple OpenGL example. Try running them.
> ./HelloWorldThis will print the famous phrase, "Hello World" to the console.
> ./HelloGLThis should open a window and show a gray blue square.
Furthermore, tools such as man and apropos can be used to understand the features of any UNUX call.
Try looking at the man page for recordmydesktop to see how it can be used to record demos form the assignment. A tested workflow is also in the submission guidelines for the assignment. However, you can experiment with the tools available in the lab to discover the easiest and/or best ways to make high quality demos.
> man recordmydesktop
We will not go over using gdb and valgrind here. However, Tia Newhall has a very nice tutorial here as well as some additional tips.
void foo(const A& a); // by const reference, A cannot change void foo(A& a); // by reference, A can change inside foo void foo(A* a); // by pointer, A can change void foo(A a); // by value, A is copied and passed, // A can change in the function, but the changes don't presistQuoting Thinking in C++
References are like constant pointers that are automatically dereferenced by the compiler.For non-basic types, passing by reference allows us to avoid unnecessary object copying. Const references aid with type safety. Also, passing by const references allows to create 'throw-away' temporary objects on the stack, for example,
foo(vec3(0,0,0)); // pass a temporary class instance who won't live past the execution of the fn callIn this week's assignment, you will finish the implementation of a Shape helper class which implements several functions with const reference arguments.
Behind the scenes, C++ always creates default copy constructors and assignment operators for each class you create. However, it's best practice to define these yourself (For more information into why, please read Chpt 2, Item 5 from Effective C++). In short, the default version may have behavior you don't want.
In this assignment, we will ask you to implement the copy constructor and assignment operator.
A a; // call default ctor A a2; A a = a2; // call copy ctor A a(a2); // call copy ctor a = a2; // call assignment operator
Operator overloading is just “syntactic sugar,” which means it is simply another way for you to make a function call. The difference is that the arguments for this function don’t appear inside parentheses, but instead they surround or are next to characters you’ve always thought of as immutable operators.In this assignment, you are asked to implement the iostream out operator for Shape. This allows use to write code that looks like
#includeusing namespace std; ... Shape s(theQuadId); cout << s << endl;
vectorVectors are self-resizing arrays. Documentation for using vectors is here Note that we are not storing pointers in our vector.theShapes;
A consistent coding style is important for making readable code. Please adhere to the style of the assignments when writing code. Use camelCase for variables. Prepend global variable with 'the'. Prepend local variable with 'm'. Use aligned brackets {} for code blocks. Use comments heavily for explaining algorithm implementations in technical functions. Use all CAPITALS for global constants.
The basecode will use shared libraries for solutions. Be aware that if you change the header files, linking against precompiled libraries will not work.