Exercise 1: Roar

This assignment is about installing CLion and the associated C and C++ compilers. If possible, do this before class time to avoid flooding the local wireless network. These directions assume you are using a Windows box such as your school computer; Mac and Linux users can ask your instructor for help if they need it, but CLion is pretty easy to install on those systems as well.

  1. If you have not done so yet, create a (free) student account with JetBrains by visiting the student account page and clicking on the Apply now button. The simplest is to use your school email address. Let your instructor know if you have problems with this step.

  2. Visit https://www.jetbrains.com/clion/. If necessary, log in to your account. Make sure the right operating system is selected (Windows/macOS/Linux) and click on the Download button.

  3. Install the downloaded executable. If necessary, give it permission to change your system. When you get to Installation options, you can accept the defaults but consider the following:

    • You may want to enable Add "Open Folder as Project" to the menus, but you can also open folders from within CLion if you prefer to not have the extra options in your context menus.
    • Strongly consider not associating CLion with .cpp, .h, and .c files. Starting CLion just to view a file is slow. It will save you time to install Notepad++ and associate that with source files.
  4. Complete the installation. This includes rebooting your laptop.

  5. If you have not done so yet, fix the Windows problem that it hides file name extensions by default. The file name extensions are critical for this course, and in fact for all computing and engineering folks. To fix this problem:

    1. Hold down the Windows key and press 'e'. This opens a File Explorer window.
    2. Click on the View menu.
    3. In the Show/hide group (far right), put a check mark in File name extensions.
    4. Less critical, but you might also put a check mark in Hidden items.

  6. Open CLion. By default CLion enables some checks that are helpful to professionals but misleading to students. Fix them by visiting Settings..., Editor, Inspections, C/C++, and disabling Static Analysis Tools. This disables both CLang-Tidy and CLazy, two tools that assume you know all of C++.

  7. In CLion, create a new project:

    1. From the File menu, select New and then Project....
    2. Set the Location to a reasonable location. The default is CLionProjects\untitled, but you will want to change that. We highly recommend creating a Git repository for the class and putting all of your assignments in that repository. Ask for help creating the repository if you need it. You would then put the code for this assignment under a ex1 folder in this repository.
    3. You will likely get a popup in the lower right corner of CLion talking about your Microsoft Defender configuration. Click on Automatically and approve allowing elevator.exe to make changes to your computer. If you miss the box, you can find it in the notifications section of CLion by clicking on the bell in the upper right corner.
    4. Open main.cpp and click on the green run arrow. You may get a prompt about using the built-in compiler, MingW. Accept the defaults. When your program runs, you will see Hello, World! in the Run window.

  8. Modify your program so it reads a number from the user and prints its cube. A sample run will be the following:
          Enter a number: 5
          The cube of 5 is 125
    (where the user entered the 5). In particular, add using namespace std; below the #include, change the output line to print "Enter a number: " (do not forget the space after the colon and to delete the endl at the end of the line), add a declaration for an integer variable, read that variable, then print the last line. Absolutely ask for help if those directions are unclear to you!! Your neighbor is a fine source for this - there is no concern about plagiarism with exercises like this.

  9. Test that your code works on other inputs like 0 and -3. You may notice that it seems there is no space after the colon when you run the program; this seems to be a feature of how CLion runs code; the space will be there in other contexts.

  10. So you know how, set a break point at the cin line in your code by clicking on the line number. Click on the bug icon at the top of the window and notice that it shows the value of your variable before the cin statement. The value may be 0, but it might also be some random value. Step one statement and go to the Console window to enter a value. You might even try entering something like "6x3" (that is, a number with an illegal character in it). If you do, notice the program runs without errors. C++ is like most languages in not automatically checking inputs for validity.

  11. For full credit for this assignment, demonstrate your solution to your instructor. You can go on with the next steps while waiting for a check off.

  12. It is often very convenient to be able to build and run programs outside of CLion. It is not required, but it can be helpful to install a standalone C++ compiler. A simple way to do this is to install Chocolatey from https://chocolatey.org/ (follow the directions to use an administrative shell) and then type
          choco install mingw
    Some people also like to install the Gnu On Windows library by typing choco install gow. In any case, you can then type
          g++ main.cpp
          a.exe
    to run your program. We will discuss this in more detail later in the term.

  13. The default formatting is fine for this course, but organizations (especially Google) are switching to a two-character indent. To do this, click on the "hamburger" menu (three horizontal lines in the upper corner), select File | Settings..., open the Editor and Code Style items, click on C/C++, and change Tab Size, Indent, and other items appropriately. Do not enable "Use tab character" - putting tab characters in source files will reduce your grade.