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.
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.
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.
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:
.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.Complete the installation. This includes rebooting your laptop.
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:
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++.
In CLion, create a new project:
ex1
folder in this repository.
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.
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.
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.
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.
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.
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.
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.