Exercises
Submission
To submit your solutions you are required to create a repository in the VNAV2024-Submissions organization in github.mit.edu (this will be your first exercise).
VNAV staff will clone your repository from github.mit.edu on Wednesday, September 11 at 1:00 p.m. This will be considered as your submission and will be graded accordingly.
Late Submission.
We will assume your repository is ready to be graded at the deadline, so please email us if you want to submit later than the deadline.
Exercises
Git (5 pts)
In this exercise you are required to set a git repository inside the VNAV2024-Submission organization. This is require for the correct submission of all the exercises of the class.
- Create a repository for your personal submissions
- Go to https://github.mit.edu/organizations/VNAV2024-submissions/repositories/new to create a new repository
 - Create a new Private repository and call it as your Kerberos username, e.g. if your MIT email is astark@mit.edu, call it astark
 - Create a folder for your VNAV materials with 
mkdir ~/vnav - Clone your personal submission repository to 
~/vnav/personal-submissions(you will have a team submission repo later) runninggit clone git@github.mit.edu:VNAV2024-submissions/YOUR_USERNAME.git ~/vnav/personal-submissions(replaceYOUR_USERNAMEwith the name of the repo you just created) - Create a folder called 
lab1in your submission repo 
 - Clone the lab materials (https://github.com/MIT-SPARK/VNAV-labs) with 
git clone https://github.com/MIT-SPARK/VNAV-labs ~/vnav/starter-code. Note that this repo contains all the labs, and we may change them to include fixes and updates. So make sure to pull the repo frequently. 
You are required to put your solutions in the repository you created in the first Git exercise.
Warning.
If you created the repository in your personal account instead of VNAV2024-submissions you need to transfer the ownership in order to complete your submission. Scroll to the bottom of the page for instructions.
Validating Ubuntu Setup (5 pt)
To make sure that everyone has a computer setup that can handle the simulator-based excersises in Lab 3, you will now try to download and run the simulator. We will ask you to follow the next several steps, and then report whether the simulator successfully launched. Getting it launched successfully is not required for full points – we just want to prepare for future labs accordingly.
- Download https://vnav.mit.edu/material/lab3.zip. (You will need to follow the link in a browser to download; 
wgetwill fail to download it for some reason.) - Decompress with 
unzip lab3.zip - Inside 
lab3makelab3.x86_64executable (chmod +x lab3.x86_64) - Run the simulator with 
./lab3.x86_64 
Hopefully a new window will appear, and you will see a drone sitting on the ground. The current framerate is displayed in the top-left corner.
Submission: Please create a file called simulator.txt in ~/vnav/personal_submissions/lab1 that contains the simulator framerate (if it launched successfully), or a brief description of what isn’t working (e.g., you do not have a working Ubuntu installation yet, or you can run the program but no graphical window appears)
Shell (35 pts)
- Exercise 1 - Answer to the following questions
- Download 
https://raw.githubusercontent.com/dlang/dmd/master/druntime/benchmark/extra-files/dante.txt(try usingwget) - Create a file called 
exercise1.txtin~/vnav/personal-submissions/lab1and answer to the following questions- How many lines does it contains?
 - How many words does it contains?
 - How many lines are not blank?
 
 - Push the file to git
 
 - Download 
 - Exercise 2 - Output redirecting
- Install 
fortune-modusingapt - After installation, type 
fortunein your terminal to see a (hopefully) interesting proverb/quote - Run 
fortune5 more times and each time redirect the output to a file calledfortunes.txtin~/vnav/personal-submissions/lab1(Hint: do not recreate the file 5 times - each time a new proverb should be added to the end offortunes.txt) - Push the file to git
 
 - Install 
 
Hint: For the first exercise you might want to use the command
wc(Word Count).
C++: Warm-up Exercises (20 pts)
Feel free to refer to this when answering the following questions. Some of the questions below are based on C++ Primer, which is also an excellent resource for C++ programming. Put all answers into a text file called cpp-warmup.txt and push it to git.
Operators
- What are the values of 
iandjafter running the following code?int i = 0, j; j = ++i; j = i++; - What does the following code print?
int i = 42; std::string output = (i < 42) ? "a" : "b"; std::cout << output << std::endl; 
References and Pointers
- What does the following code print?
int i; int& ri = i; i = 5; ri = 10; std::cout << i << " " << ri << std::endl; - What does the following code print?
int i = 42; int* j = &i; *j = *j**j; std::cout << *j << std::endl; - What does the following code print?
int i[4] = {42,24,42,24}; *(i+2) = *(i+1)-i[3]; std::cout << *(i+2) << std::endl; - What does the following code print?
 
void reset(int &i) {
    i = 0;
}
int j = 42;
reset(j);
std::cout << j << std::endl;
Numbers
- What are the differences between 
int,long,long long, andshort? - What are the differences between a 
floatanddouble? What is the value ofiafter running the following code snippet?int i; i = 3.14; - What are the differences between an unsigned and signed type? What is the value of 
cin the following code snippet assumingcharsare 8-bit?unsigned char c = -1; - What will the value of 
ibe after running the following code snippet?int i = 42; if (i) { i = 0; } else { i = 43; } 
C++: RandomVector (40 pts)
In this exercise we will implement the class RandomVector. Inside ~/vnav/personal-submissions/lab1 create a folder called RandomVector and copy the content from https://github.com/MIT-SPARK/VNAV-labs/tree/master/lab1.
The class RandomVector defined in the header file random_vector.h abstract a vector of doubles. You are required to implement the following methods:
RandomVector(int size, double max_val = 1)(constructor): initialize a vector of doubles of sizesizewith random values between 0 andmax_val(default value 1)double mean()returns the mean of the values in random vectordouble max()returns the max of the values in random vectordouble min()returns the min of the values in random vectorvoid print()prints all the values in the random vectorvoid printHistogram(int bins)computes the histogram of the values usingbinsnumber of bins betweenmin()andmax()and print the histogram itself (see the example below).
To do so complete all the TODOs in the file random_vector.cpp. When you are done compile the application by running
g++ -std=c++11 -Wall -pedantic -o random_vector main.cpp random_vector.cpp
Note: we expect you to not use the function from the <algorithm> header.
If you complete correctly the exercise you should see something like
$ ./random_vector
0.458724 0.779985 0.212415 0.0667949 0.622538 0.999018 0.489585 0.460587 0.0795612 0.185496 0.629162 0.328032 0.242169 0.139671 0.453804 0.083038 0.619352 0.454482 0.477426 0.0904966
Mean: 0.393617
Min: 0.0667949
Max: 0.999018
Histogram:
***     ***
***     ***
***     ***
***     ***
***     ***
***     ***
***     *** ***
*** *** *** *** ***
Optional (10 pts): Try to implement the methods with and without the functions available in the header
<algorithm>.
Transfer ownership of Git repository
If you created the repository in your personal account instead of VNAV2024-submissions you might want to transfer the ownership in order to complete your submission.
- On GitHub, navigate to the main page of the repository.
 - Under your repository name, click Settings. 

 - Scroll down until your reach the Danger Zone, then click Transfer. 

 - Type the name of your repository in the first row and VNAV2024-submissions in the second, then click I understand, transfer this repository. 

 - Done!