COMP 1010

ASSIGNMENT 1
DEPARTMENT AND COURSE NUMBER: COMP 1010
COURSE TITLE: Introduction to Computer Science 1
TERM: Fall 2019
1
Assignment 1
DUE DATE OCTOBER 4 2019 AT 11:59PM
Notes:
• Name your sketches using your name, the assignment number, and the question number, exactly as in this
example: LastnameFirstnameA1Q1.
• Your programs must run upon download to receive any marks.
• Submit one PDE file for each question.
• Assignments must follow the programming standards document published on the course website on UMLearn.
• After the due date and time assignments may be submitted but will lose 2% of marks per hour late or portion
thereof.
• You may submit a question multiple times, but only the most recent version will be marked.
• These assignments are your chance to learn the material for the exams. Code your assignments independently.

代做COMP 1010作业、代写Java,c++实验作业
We use software to compare all submitted assignments to each other, and pursue academic dishonestly
vigorously.
ASSIGNMENT 1
DEPARTMENT AND COURSE NUMBER: COMP 1010
2
Q1: An Animal
You should be able to do this question after Week 2 in the course.
Write a non-active Processing program (containing no setup() or draw()
functions) which will draw some sort of animal in the canvas. It can be anything
you like: a tiger, a dog, a mouse, any animal. Be creative. The rules are:
• It must contain from 6 to 16 shapes (lines, ellipses, rectangles, or other
shapes). The sample mouse shown here uses 11 shapes (2 rectangles, 5
ellipses, and 4 lines).
• It must contain at least one line, at least one ellipse or circle, and at least one square,
rectangle, triangle, or quadrilateral (quad).
• It should contain several different colours.
• It can be a very abstract animal, like the one shown. You don’t have to be a great artist.
• Don’t make it too complex. Stick to the limit of 16 shapes. That will make the
remaining questions easier.
• You must use a 500 x 500 canvas for this question.
• The animal must fill the canvas, either horizontally (as the mouse does), or vertically.
• It should be roughly centred in the window.
In Questions 2 and 3, your animal will grow, shrink, and move. As soon as any program is
“finished”, you usually have to start making changes to it, and that will happen with this
program, too. To make that easier to do, you must do the following things:
• All X coordinates, Y coordinates, heights, widths, and colours, must be defined by
constants. You will probably need at least 10, and perhaps as many as 30 if you choose to
do a very complex animal. There is no limit on the number of constants you use.
• The X and Y coordinates should be specified relative to the centre of the window. This
will make the following questions much easier. Heights and widths will be in pixels. For
example, this constant is used to define part of the example mouse.
final int BODY_WIDTH=width/2; //total width of body section
• All of your drawing commands should use your constants, the built-in height and
width variables, and perhaps simple numbers like 1 or 2. No other numbers. For
example, the ellipse that forms the main body of the mouse was drawn with the statement
below.
ellipse(width/2, height/2, width/2 , height/2 - bodyWidth);
• If some calculation is needed many times in many statements, do it only once and store
the result in a variable. Then use that variable many times. For example, a better version
of the above statement would be the one below, where MOUSE_BODY_WIDTH and
MOUSE_BODY_X were pre-calculated, since those values were needed many times to draw
the entire animal. (Hint: It would be a really good idea to pre-calculate the coordinates of
the centre of the canvas.)
ellipse(MOUSE_BODY_X, MOUSE_BODY_Y, MOUSE_BODY_WIDTH, MOUSE_BODY_HEIGHT);
ASSIGNMENT 1
DEPARTMENT AND COURSE NUMBER: COMP 1010
3
Q2: A Moving Animal
This question requires material from Week 3. Convert your
program from Question 1 into an Active Processing program,
with the mouse controlling both the size and position of the
animal. Make the following changes and additions to your
Question 1 program.
1. Save a copy of your original Question 1 program. You
must hand in the original static version, as well as this
modified active version. Rename this one so that it ends
with “A1Q2”.
2. Add five variables to your program, which control the
animal’s size and position. There should be an X
coordinate, a Y coordinate, size, and a MIN_SIZE and MAX_SIZE value. The X and Y
coordinates should specify the position of the approximate centre of the animal (the same
spot that used to be at the centre of the canvas, but could now be anywhere). The size
variables should give the minimum size the animal should reach when near the top of the
canvas and the maximum size the animal should reach when nearing the bottom.
3. Create the usual setup()and draw() functions. Create a drawAnimal() function (or
call it drawCat () or drawMouse(), or whatever name is appropriate for you). Create
a moveAnimal() function (or use a similar name).
4. Move all your existing code from Q1 into the appropriate place in these new functions.
All of the code that draws your animal should go into the drawAnimal() function, not
into the draw() function directly. The functions should call each other as needed.
5. The moveAnimal() function should use the mouse position to set the X, and Y, and size
values for your animal (the ones described in point 2). The X and Y values should exactly
match the mouse position. The size variable can be calculated by using the MIN_SIZE,
MAX_SIZE and mouseY such that, when the mouse is at the top of the screen, the animal
is at it’s MIN_SIZE, and when it’s at the bottom, it will be at it’s MAX_SIZE. This will
be a very short function.
6. Now you need to change all of the commands that draw your animal, so that they take
into account its position and size. If you took the hint in Question 1, controlling the
position should be very easy. To control the size, you will have to “scale” almost all of
the constants from Question 1, using the animal’s current size, and its original size (500).
For example, BODY_HEIGHT used to control the height of the example animal’s body.
Now it must be BODY_HEIGHT*animalSize/ORIGINAL_SIZE.
7. When using int values, be careful. BODY_HEIGHT*animalSize/ORIGINAL_SIZE
works but animalSize/ORIGINAL_SIZE*BODY_HEIGHT will usually just give you 0.
Always do the multiplication first. And don’t try to store
animalSize/ORIGINAL_SIZE in an int variable, as nice as that would be. You’ll just
get 0.
8. Now change the size of the canvas to 1000 by 1000 pixels, or to any other size. If you’ve
written your program well, everything should still work, with no modification. Did it?
9. Optional: If you want to use float, from Week 4 material, go ahead. It would make
things somewhat simpler. But it’s not required.
ASSIGNMENT 1
DEPARTMENT AND COURSE NUMBER: COMP 1010
4
Q3: A Self-propelled Animal
Convert your program from Question 2 so that your animal will move across the canvas, and
change size, all by itself. Here’s how it should work: When you click the mouse in the canvas,
your animal should slowly and smoothly move to that position (or close to it).
Make the following changes and additions to your Question 2 program.
1. Save a copy of your original Question 2 program. You must hand in that version, as well
as this new version. Rename this one so that it ends with “A1Q3”.
2. Add a mouseClicked() function (void mouseClicked()). This is a special
function, like setup() and draw(), which is automatically called every time there is a
mouse click in the canvas. The mouseX and mouseY variables give the location of the
click. The location of the last mouse click should be stored in appropriately-named state
variables.
3. Change your moveAnimal() function (or whatever you have chosen to name it) so that
your animal will now move slowly and steadily toward the location of the most recent
mouse click. Use a constant to control your animal’s speed. In each frame, it should move
1/Nth of the way from its current position to the location of the mouse click. (But don’t
call the constant N – use a better name.) Note: When the animal gets close to the desired
location, it will reach a point where its position will change by less than 1 pixel per
frame. Since you are using int variables, you will get a change of 0 pixels per frame,
and your animal will stop a bit too soon. This is OK. (If you wish to use float variables
to solve this problem, go ahead.)
4. The size of your animal should depend on the Y coordinate of its current location in the
canvas, not on the location of the last mouse click, or on the current position of the
mouse. Its size should change slowly and smoothly, just as its position does.

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codehelp

原文地址:https://www.cnblogs.com/python34/p/11622620.html

时间: 2024-08-30 17:16:35

COMP 1010的相关文章

LightOJ 1010 Knights in Chessboard (规律)

题意:给定一个m*n的棋盘,问最多放多少个马,使得他们不相互攻击. 析:很明显可以从上图看出来了马放在白格,或者黑格,不会攻击,不过行或者列为1,2时是特殊的,我们只要特殊判断一下就行了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cm

1010 求个最大值

1010: 求个最大值 时间限制: 1 Sec  内存限制: 128 MB提交: 231  解决: 39[提交][状态][讨论版] 题目描述 给出 n(1 <= n <= 200000)个数字 ai(1 <= ai <= 1000000),i 为数字的下标,按输入顺序从 1 开始编号一直到 n,求满足 ai >= aj 的最大的 ai % aj. 输入 第一行一个数字 n,第二行 n 个整数. 输出 题目要求的最大值. 样例输入 2 2 3 样例输出 1 提示

BZOJ - 1010【斜率优化DP】

1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9961  Solved: 4056[Submit][Status][Discuss] Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压 缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具,第i件玩具经过 压缩后变成一维长度为Ci.为了方便整理

BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][Status][Discuss] Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具,第i件玩具经过压缩后变成一维长度为Ci.为了方便整理,P

【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能讲讲其用法: 1.sort入门: 使用sort需要包含algorithm头文件,完整代码如下 #include<iostream> #include<vector> #include<algorithm>//貌似可以不用,但最好加上. using namespace std

NBUT 1010 魔法少女(DP)

[1010] 魔法少女 时间限制: 1000 ms 内存限制: 65535 K 问题描述 前些时间虚渊玄的巨献小圆着实火了一把. 在黑长直(小炎)往上爬楼去对抗魔女之夜时,她遇到了一个问题想请你帮忙. 因为魔女之夜是悬浮在半空的,所以她必须要爬楼,而那座废墟一共有n层,而且每层高度不同,这造成小炎爬每层的时间也不同.不过当然,小炎会时间魔法,可以瞬间飞过一层或者两层[即不耗时].但每次瞬移的时候她都必须要至少往上再爬一层(在这个当儿补充魔力)才能再次使用瞬移.爬每单位高度需要消耗小炎1秒时间.

Entity Framework 6 Recipes 2nd Edition(10-10)译 - &gt; 为TPH继承的插入、更新、删除操作映射到存储过程

10-10. 为TPH继承的插入.更新.删除操作映射到存储过程 问题 TPH继承模型,想把它的插入.修改.删除操作映射到存储过程 Solution 假设数据库有一个描述不同种类的产品表(Product )(见Figure 10-13). 而且为这个表的每种产品创建了创建了派生模型,这个模型如Figure 10-14. Figure 10-13. 一个含有鉴别列(ProductType)的产品表, 表的每行按该列的值划分不同的产品 Figure 10-14. TPH继承形式的模型 接下来把这个模型

BZOJ 1010 玩具装箱 斜率优化DP

详情见 http://www.cnblogs.com/proverbs/archive/2013/02/01/2713109.html(我觉得这里面讲得已经够详细了,我就不赘述了) 还是来回忆一下做这道题的历程吧!一开始的确有点想错了,但马上又反应过来,清楚了题意.写了个 n^2 的算法.很明显,对于n <=  50000 的数据,肯定是要TLE的.(援引我看博客过程中看到的一句话来形容就是“省选题的数据就是硬”.)没办法,只能上网找百度(太弱了).一开始的确有点茫然,但马上就决定要自己推导一下

理解JNDI中 java:comp/env/jdbc/datasource 与 jdbc/datasource 的不同之处(转)

在描述JNDI,例如获得数据源时,JNDI地址有两种写法,例如同是  jdbc/testDS 数据源: A:java:comp/env/jdbc/testDS B:jdbc/testDS   这两种写法,配置的方式也不尽相同,第一种方法应该算是一种利于程序移植或迁移的方法,它的实现与“映射”的概念相同,而B方法,则是一个硬引用. java:comp/env 是环境命名上下文(environment naming context(ENC)),是在EJB规范1.1以后引入的,引入这个是为了解决原来J