In-Class Exercise 1 - Getting Set Up & Started: Grading
In-Class Exercise 1 - Getting Set Up & Started: Grading
Started
The purpose of this In-Class assignment is to
1. properly set up the tools used for the course,
2. see what documentation you must include in every program and where to get it,
3. see how to submit your programs.
4. see if you can follow instructions
Read the whole assignment because you are responsible for the whole assignment. That's the first
instruction to follow. There is a Canvas quiz too, due Tuesday.
Grading
You will be graded on updating your Canvas profile as well as completing the programming
assignment.
At the top-left of the page, click on Account, then select Profile. Click the "Edit Profile" button,
and fill in information in the "Bio"section. Fill out a short personal blurb – your major, hobbies
or interests, why you're taking the course, and anything else fun that you'd like the rest of the
folks in the class to know.
You must upload a headshot of yourself by clicking on the circle towards the left of the screen.
Please use a picture where your face is clearly visible, not your favorite pic where your face is
only 10th of the image. You may not use a logo, avatar, or any image that does not have you in it.
Please, help me try to get to know you a little better!
By default, the little box circled in red is checked. UN-CHECK it, please, then click OK.
Now, your folder display (and open-a-file-to-submit-it pop up box) will show file
extensions like circled here:
Your file selection pop-up uses these same settings and will help you all to submit the
correct files when you are submitting your programs for grading. This alleviates a lot of
frustration for both students and us. Please do this.
Mac students should use XCode. You can get it at the App Store. At the bottom
of the Administrative Module on the class homepage, there are XCode
installation instructions and instructions on creating a XCode Project (i.e.
program). ***Never use spaces in file names or folder names. It causes
errors submitting your programs.
Windows students should use CodeBlocks this semester because that is what the TAs will be
familiar with. If you need help installing it, you should see us during office hours before the
second class. We will start the first program together in class.
Go to: http://www.codeblocks.org/downloads
Click on the Download the binary release
Save the file and execute it to install the software. We will look at this in class.
Each programming assignment that you work on in this class (whether it is a homework
assignment, and example, or an in-class exercise) should exist in a separate project in
CodeBlocks. This keeps your work well-organized and ensures that work that you do on one
assignment does not interfere with work on another assignment. I suggest you create a "cs1044"
folder and a "programs" folder in the cs1044 folder. Create your projects inside the cs1044/
programs folder. For example, for inclass1 create an inClass1 project in the cs1044/programs
folder.
Create a new Project for every assignment (keep old ones around):
You MUST
do this for
every
assignment!
4. Select a "Folder to create project in" where you want to save your projects, like
cs1044/programs
6. Click Next
7. Click Finish
8. Click the + sign next to Sources so you see the source program files, e.g. main.cpp
9. If you want to, you can right-click on the file main.cpp, and select Rename… to change
the file name to something like homework1.cpp (You must have the .cpp suffix!!!) BUT
you can only change the name of the file when the file is NOT open in the program
editing window pane.
10. You have just created a Project that holds your program, and you are ready to start editing
your program…
1. Double-click the .cpp file you just created (e.g. main.cpp) to open it in the source code
editing window pane. CodeBlocks starts you off with some code, although other editors
just start with an empty file. The following describes creating the code from an empty file,
but you should read through it to understand
2. We need to use the #include keyword to include "header files" that contain features that we
want to use in our programs. In this case, we need to include the iostream header, which
lets us read and write text output. So, type the following as the first line of the file:
#include <iostream>
As a rule, you'll want to include this line at the top of all of your programs, just under your
#include statements. This feature adds into your program a "namespace" named std. You can
think of namespaces as "folders" that contain functions and data types; for example, std::cout
refers to something named cout inside the std namespace. By having this line of code (using
namespace std; ) you can write shorter code by leaving off the std:: prefix.
4. Every C++ program must have a function named main. The main() function is the starting
point of your program – the code within the braces { } will be executed one statement at a
time (in order) whenever you run it. Add this code to your source file:
int main()
{
return 0;
}
This function is the smallest valid C++ program that you can write. What does it do?
Nothing! The int before the function's name is its return type; the main function must
return an integer that tells the operating system whether the program ran successfully or not.
In our case, we return 0, which means everything went ok. (Our programs in this class will
never return anything other than 0.)
The parentheses after the name of the function represent parameters that the function takes.
Parameters allow us to pass values into functions. In this case, since the parentheses are
empty, we're saying that the main function does not take any parameters. (It optionally can,
but we'll never use them.)
Lastly, the curly braces after the function are where we place the code that belongs to that
function. As we'll see throughout the course, we can separate the logic of our programs into
multiple functions that keep the responsibilities of different parts of our programs organized.
5. Now let's have this program do something. We'll use the cout stream to print this text to
the screen: (from http://www.imdb.com/title/tt0062622/quotes, 2001: A Space
Odyssey)
Dave Bowman: Hello, HAL. Do you read me, HAL?
6. To accomplish this, type code like the following around each quoted line you want to
print:
cout << "Dave Bowman: Hello, HAL. Do you read me, HAL?" << endl;
Not using copy-
paste is the The << symbol is an operator that we use to write data to an output stream; in this case,
single most cout, which represents the screen. (Other output streams can represent files on your disk.)
common
mistake Lastly, the endl symbol says that the cursor should be moved down to the next line.
Copy the Hal/Dave text above and Paste the text into CodeBlocks, and type the
“cout” and “endl” around the quoted lines!!!
7. Write cout statements for each line you want to print. Your code should look like this:
8. Now test your program by compiling and running it. Click the “Build and run” button in
the toolbar circled in the image below.
tt
When you run your program in CodeBlocks, you get a black window that your program runs in.
Beneath that popped up window in CodeBlocks, it shows you messages saying it has built and
run your code, which I have circled below.
10
If you do not see the black window pop up, CodeBlocks (or XCode) prints errors that are
in your code. The error messages mainly just tell you on which line CodeBlocks has a
problem understanding what you wanted; frequently, your error is on the line above the one
CodeBlocks indicates. If you have errors, you need to fix erros, and try building again:
11
There is an example of how to format and comment your code in the "EXAMPLE Code:
RockPaperScissors.cpp" on Canvas in the Administrative “Module” on the Canvas
homepage. ( GO find that file RIGHT NOW! )
11. HONOR CODE comment: Copy the entire comment at the top of the file from “/**”
down to the line that has just “*/” . This is the file header comment. Change it to have
your info: your name, your filename, the date, etc.
12. MAIN function comment: In the RockPaperScissors.cpp, go down to the /** comment
immediately above the "int main()" line. Copy that entire comment from /** to */
and modify it for your program: change the program description but leave the line that
has "* @return 0 ..."
13. You must include the honor code statement (#11) and the main program comment
(#12) for every one of your programs, or you will lose points. Do this when you start
writing your programs!
14. Step-by-step instructions will not be provided for each assignment. That is what you need
to learn to do on your own. Perform steps similar to the previous steps for future
assignments.
12