Termbank
  1. A
    1. API
    2. ASAN
    3. Access specifiers
  2. C
    1. Constructor
    2. const
  3. G
    1. GDB
    2. g++
  4. M
    1. Make
    2. Memory Leak
  5. P
    1. Pointer
  6. R
    1. Recursion
  7. S
    1. std
  8. V
    1. Valgrind
Completed: / exercises

MP_INTRO: Makefiles

Due date: 2024-03-26 23:59.
Welcome to your first solo assignment! Unlike your lab assignments,, you will work on and submit all MPs individually, without a partner. While you'll be working independently, remember that we are here to support you. Feel free to ask us questions about the MPs during labs or on Piazza.

Getting the files

Start with downloading and unzipping the provided files from here: mp_intro.zip.
There will be many files in your mp_intro directory, but you will only need to modify the following files:
All other files including any testing files you might add will not be used for grading.

Adding your RGBAPixel class to this project

Before starting this MP, make sure you have finished lab_intro.
Once you have copied the files, please do not make any further modifications to them, as our autograder will not evaluate them.

Part 1: Create a Makefile

To fully grasp the structure of C++ projects, it's important you understand the compilation process. Go through the Makefile Tutorial and create a Makefile for this assignment. You may use lab_intro/Makefile as convenient starting point as it already includes all of the necessary tags for PNGs.
Your Makefile must compile together your own solution files, namely main.cpp, intro.h, intro.cpp, and files in the RGB directory. Do not have typos in your file names or your Makefile! For example, make sure your Makefile compiles a file named main.cpp, NOT a file named main.C or test.cpp or any other such thing.
Please make sure your Makefile does not compile extra files that are not part of this MP. For example, do not add in files from the Makefile tutorial by mistake; the only files the Makefile should be dealing with are the few listed above.
Your Makefile must produce an executable called intro (all lowercase). Once you are done, you should be able to compile your code and run your newly created executable. However, in order for it to produce interesting results, we should fix the code, too.

Part 2: Rotate an Image

Open intro.cpp and complete the rotate function. This function must:
Here’s reindeer.png:
Reindeer
And here is its rotated by 180 degrees self:
Reindeer rotated by 180 degrees
In order to complete this past of the MP, you will need to make use of the PNG class from RGB/png.h, .cpp, which you learned about in lab_intro.
Hint: Take a piece of paper and draw a 5x5 grid on it. Mark the box at (0, 1). Rotate that paper 180 degrees and note where the marked box is now located. Repeat for other squares if necessary. Can you find the pattern/formula for how the pixel moves?

Testing Part 2

The Makefile you created in Part 1 must produce an intro executable. The following command will compile the code and will create the executable intro:
make
The main function (located in main.cpp) has been provided for you that will call the rotate function to read in in.png and output out.png. With that, you may use the given files in_01.png, out_01.png, in_02.png, out_02.png, in_03.png, and out_03.png to test your program. First, copy in_01.png to in.png by typing
cp in_01.png in.png
Then run your program:
./intro
Finally, compare the output by opening each file and looking at them or using diff to compare your output to the expected output:
diff out.png out_01.png
If diff exits without any output, then the files are the same! :)

Part 3: Getting Creative

Open up intro.cpp and complete the myArt function. The myArt function must:
That’s it – everything else is up to you! You are highly encouraged to use gradients, fractals, or other designs in your art. More than anything else, have fun! Feel free to share it both on Discord and with your friends and family!

Testing Part 3

The main.cpp provided for you will produce your artwork if you run ./intro with a command line parameter. If you provide a number after ./intro, it will save your artwork as art.png. For example:
./intro 800
You can now open your newly generated art and marvel at it! You just created something beautiful and unique that never existed before - congratulations!

Submitting Your Work

You can now upload your Makefile and intro.cpp in the box below.
Double check that you implemented the functions called rotate and myArt in intro.cpp file that you are about to submit.

Allowed filenames: Makefile, intro.cpp

Warning: You have not logged in. You cannot answer.

Acknowledgments

We would like to express our gratitude to prof. Cinda Heeren and the student staff of the UIUC CS Data Structures course for creating and sharing the programming exercise materials that have served as the basis for the labs used in this course.
Revised by: Elmeri Uotila and Anna LaValle
?
API stands for Application Programming Interface. In the context of this course, you can consider the header files to be such interfaces, as they determine what class functions and properties are public and thus accessible from anywhere.
AddressSanitizer (ASAN) is a memory error detector for C/C++. In this course, the makefiles will typically compile an executable that uses ASAN, with "-asan" at the end of its name.
The two notable access specifiers are:
  • public: class members defined after the public keyword are accessible from outside the class.
  • private: class members are generally private by default and thus not accessible from the outside
Constructor is a special non-static member function of a class that is used to initialize objects of its class type. A constructor is called upon initialization of an object. A constructor without arguments is a default constructor, but constructors that take arguments can be defined.
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
  • Start your program, specifying anything that might affect its behavior.
  • Make your program stop on specified conditions.
  • Examine what has happened, when your program has stopped.
  • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program.
Memory leak means that the program is not freeing up memory it reserves. The memory will be freed when the program terminates, but if a program keeps leaking more and more memory without terminating, it can become a huge issue!
A typical way for memory leaks to occur is reserving memory with new and not calling delete before the pointer goes out of scope.
Pointer variables store a memory address as their value. In other words, they point to some data. The data can be accessed by dereferencing the pointer. (Either like *p or p->...)
A recursive function calls itself from within it. The recursion call must be conditional or it would lead to an infinite loop.
Valgrind is another tool besides ASAN that you can use in this course. It can detect many memory-related errors that are common in C and C++ programs and that can lead to crashes and unpredictable behaviour.
const is a keyword meant to mark something as immutable
  • A const object cannot be modified: attempt to do so directly is a compile-time error, and attempt to do so indirectly (e.g., by modifying the const object through a reference or pointer to non-const type) results in undefined behavior.
  • const keyword on an object's member function prevents the object from being modified in the function
  • Pointer declarations can have 2 const keywords, one to make the data that's pointed at unable to be modified and one to make the pointer itself unable to be modified
Using const improves code readability and prevents accidental modification of objects.
g++ is a C++ compiler that we primarily use for this course. It is the C++ compiler for the GNU compiler collection. You may sometimes see gcc being used instead of g++, which was originally the GNU C compiler, but calling gcc generally also compiles .cpp files as C++. However, calling g++ is preferred.
In C++, std stands for Standard Library, which is a collection of commonly useful classes and functions. Typically, these are defined in the std namespace.