CS 010 -
Introduction to Computer Science I
Assignment 8:
DUE: March 3rd before 2:00pm
Limited collaboration is OK. You may do the following while writing a programming assignment: discuss general solution ideas with your study group members or have members observe a run of your program, and offer their ideas on its behavior. You should *never* look at someone else's code for the assignment to figure out how to do your own program. It is very hard to write your own unique solution once you have seen someone else's. If you need someone to look at your code to give advice, you should see your TA or instructor. Of course, copying code from ANY source (any book, current or past student, past solutions, or the web) is STRICTLY FORBIDDEN.
Code that is turned in, must be contained in a .cpp file named main.cpp. Files of any other format will not be graded (e.g. main.doc, main.txt, etc…).
You must turn your work in from a lab computer on campus.
Turn in online to as8 folder. If you turn your assignment in to the wrong folder, your assignment may not be graded. If it is graded, you will lose 20 pts (out of 100).
Programs that do not compile will receive a 0 out of 100!
Programs that do not have the readme file turned in with the main.cpp file will not be graded.
Remember to include the following header information at the top of your program, failure to do so will result in lose of points.
// Course: CS 10
//
// Lecture Section: ... 001 or 002
// Lab Section: ... 021, 022, etc)
//
// Assignment #: ... assignment 2, 3, etc.
//
// Last Name: Enter your LAST (family) name here (eg, Doe)
// First Name: Enter your FIRST (given) name here (eg, John)
//
// ID Number: Enter your ID number here (eg, 860-00-0000)
// lab login id: Enter your cs10 login here (eg, jdoe)
//
// Email address: Enter your UCR email address here (eg, jdoe@cs.ucr.edu)
//
// =======================================================================
For this assignment, you will write a program that
prints out a message indicating a number of randomly placed circles that the
person must click. Each circle will
appear sequentially at a random spot, and remain there until the player clicks
it. Once the person clicks all the
circles, the screen will be cleared, and the amount of seconds that it took to
click all the circles is displayed in the graphics window.
At
the start of your program a random number of circles between five and ten
(inclusive) is chosen. This number
should be displayed in the graphics windows, along with a prompt telling the
user to “click the window to start.” The points representing the center of
the circles should be randomly chosen with x and y values between 1 and 9
(inclusive) and stored in a vector of Points. After the user clicks the window, you
will get the start time, and display the circles one at a time using a for
loop. Each circle should have a
radius of one when it is displayed.
You will loop through the vector one point at a time, not drawing the
next circle until the person clicks the inside of the circle currently
displayed. To do this you will need
to write a distance function.
The
distance function takes two points as parameters, and returns the distance
between them. The formula for
finding the distance between two points is:
distance = square root(square(x1 – x2) + square(y1 – y2));
So
your program should not continue, until the point that the user clicks is less
than 1 unit (the radius) away from the center of the circle. Each
circle should be fully visible in the window when it is displayed.
After
all the circles are clicked, the time it took to do so should be printed in the
graphics window.
Hints:
- Use the sqrt() and pow() (pow(x,2) = x*x) functions in the cmath library for the distance
function
- One of the previous labs required you
to time yourself typing a
sentence, use the Time class as you did in that lab, to see how long it takes to
click all the circles.
- Make your window's coordinates
cwin.coord(0,10,10,0)
- include both ccc_win.h and ccc_time.h at the top of your main.cpp
Example program download
main
12.5 pt(s): Function is used to find distance
between two points and returns correct value.
12.5 pt(s): Points are correctly
stored in a vector using a for loop.
12.5 pt(s): Continues to ask the
user to click the window, until they click inside the circle.
12.5 pt(s): For loop is used to
print out the circles, and next circle isn't drawn until current circle is clicked.
12.5 pt(s): The number of circles to click is
randomly chosen and displayed in the window at start of program
12.5 pt(s): Circle's position is randomly
selected (x,y between 1 and 9), and circle is fully visible when drawn
12.5 pt(s): The correct time it
took to click all the circles (from users start click) is displayed IN the
graphics window.
12.5 pt(s): Style
- comments
- line wraps
- header info included at top
- spacing
- Indentation
- Good constant/variable names
- No magic numbers
Fill
out the following form, and turn it in with your program:
readme.txt
Note
that you will lose points for style on this assignment!
For coding style requirements see the following link:
http://www.cs.ucr.edu/cs10/cs10_05win/requirements/coding_std.html