Tag Info

Hot answers tagged exercises

7

Whether this is a good plan or not depends on some things, most especially the nature of your students. However, it seems a bit too unstructured. If you have a general mix of student ability it could cause problems unless you incorporate the questions from the site(s) more formally into your teaching. There are a lot of questions available, I would guess ...

7

I saw the light at the end of the fiber optic cable as soon as you said that these are students of electronics. There is nothing more modular and encapsulated than that! Software is simply electronics without the hardware part. If you said to them, "What are the building blocks of a simple AM radio receiver?" they would (hopefully) reply something like: ...

6

Instead of an example, use a metaphor. Get yourself a frisbee - ultimate disk and two packs of sticky notes. You are the caller of a function. Another person is the function itself. Write a value on the sticky note and stick it to the frisbee. The pass it to the function (person). The person catches the disk, and replaces the stick note with a new one with a ...

6

If he wants to have a blast biting into some very fun and challenging problems, Project Euler is fantastic, and entirely language neutral. He may find that certain problems are out of his grasp until he learns a bit more programming, but there will be many that will be possible even with what he has. (Arrays, structs, and pointers should make all of the ...

6

Although the question is asking for a book, looking a "Project Euler" mentioned in another answer, I would like to suggest Codewars might be what you are looking for. On codewars you choose your programming language and then you get different levels of problems to solve step by step. You not only test your answer with their built-in testing tool ...

5

I post solutions after the due date of an assignment. And usually, I'll go over them in class as well. Two birds... Students get to see at least one working solution, although I try to come up with several. Posting the solution serves as a good block to students asking to turn in assignments late. They'll understand pretty well that they can't turn it in ...

5

One of the interesting things added to java in v8 is functional interfaces. Previously java only matched things up and verified correctness by type (type names). With functional interfaces, java now looks at the structure of code in certain situations. I can add examples to this answer to clarify if anyone asks. One interesting feature you can add is a ...

5

I have used a similar idea - writing an SHA-1 hash cracker - as a mini-project for students learning Java. These students had previously learned to program in other languages, so they had experience with variables, if/else, loops and functions; the main goal was to get them used to Java's syntax, but some of the specific things they had to do were: Import ...

5

The International Olympiad in Informatics is an international competition for gifted young amateur programmers. The tasks from past editions are available online, including detailed problem descriptions, test cases, and test harnesses. While these tasks are described in a way that should be understandable to novice programmers, they are quite challenging and ...

4

Create an object that creates a new file and writes in to it over several method invocations (not just one). Assure that the object has been deleted before continuing (Make the object go out of scope on the stack or delete a reference and let the reference go out of scope.) You need to assure that he file was closed. The destructor is the proper place to ...

4

To give or not to give, that is the question There are actually several possibilities that reflect how you want the provided solution to be used. For context, I am an instructor at Colorado State University and I am discussing assignments that students might encounter in the first two to three years (not CS1). Don't ever give the students solutions The ...

4

Don't provide code dumps. Provide guides that outline the process of solving the problem. Create a function that squares a number passed to it Don't just give out a fully-coded solution. The answer to this question is not as simple as regurgitating the syntax. It's a process of breaking the question down into smaller steps and taking those steps on one ...

3

Reading an answer is not the same thing as solving a problem. I think different areas of the brain are engaged. Solving the problem yourself is a stronger reinforcement of the ideas certainly. Frustration is a mind killer. Students shouldn't be frustrated when they are trying to learn and as novices they have few tools for problem solving. So, to resolve ...

3

There are 2 good examples of patterns where the destuctor is a key. This way you can teach a couple of useful patterns on the way. RAII - Resource Acquisition Is Initiation Rule of 3/5/0 It's easy to give a RAII assignment, just any C style handle that can be released in the end (Like a File handle, windows handle, etc). If they are more advanced, you ...

3

Classification problems are reasonable candidates. For instance, I wrote a GA that looked at the mushroom dataset taken from the UCI Machine Learning Repository with the goal of classifying an unknown mushroom as safe or poisonous based on its traits. Each candidate solution encoded a series of rules (Red cap means poisonous, blue spores are safe). During ...

3

I think you have left out two essential elements here. Your first two points leave the students passive consumers. The last is about testing. But there is no guarantee of any learning in between. In some ways, the two most important pedagogical ideas are Active Student Constant Feedback You need to ask your students to create things and you need to give ...

3

You could have a hierarchy based on an abstract class or interface Car, with implementations/subclasses for ElectricCar, HybridCar, GasBurningCar, etc. This illustrates that there can be very different implementations for an interface. Each class would have different additional members. For example, a GasBurningCar could have a maximum amount of gas (in ...

3

Can I craft an exercise ... that would give a dramatically wrong output, e.g. cause the screen to "blow" up if the function print-ed instead of return-ed... [my emphasis] Early in my Python classes I do (something like) this: >>> def foo(x): ... print(2*x + 3) ... >>> def bar(x): ... return (2*x + 3) ... >>> foo(4) ...

3

A famous example is Strassen's matrix multiplication algorithm, whose running time satisfies the recurrence $T(n) = 7T(n/2) + O(n^2)$. A similar example is Karatsuba's algorithm for fast integer multiplication, whose running time satisfies the recurrence $T(n) = 3T(n/2) + O(n)$. Other algorithms for multiplying matrices or integers supply even more examples ...

3

Disclaimer 1: I haven't seen the book, and I have no idea what exercises it offers. Disclaimer 2: I haven't seen your brother's code. The goal of an easy exercise is to learn how to write the perfect code. OTOH, the beginner's code tends to be sloppy. For starters, point your brother to the Code Review exchange. When the community is comfortable, let him go ...

3

There are literally zillions of scenarios. Even before the loops are introduced. For example, Min, max, and clipping a value into an interval. Figure out whether a year is a leap one. Determine if a Queen attacks a given square. Solve the quadratic equation in reals (if det < 0:). Calculate the value of a blackjack hand (an ace could be 1 or 11, your ...

2

I have used an example of a machine which has a serial number and a state. It can be turned on and off, it can be told to give out its serial number. A bMachine can be powercycled (inheritance from machine). There is a machinedesk which contains machines. They can self check. I worked through a whole range of 'things' that the objects could do to ...

2

One example that isn't necessarily exciting but would allow for a lot of class design is a Shape interface. From there let's say you have Quadrilateral, Ellipse, and Triangle as classes which implement Shape. You could do some really cool things by including as methods formulas for area and perimeter. Additionally, within Quadrilateral, you could further ...

2

One extremely handy macro is creating names ranges. Start recording Select the range you want to name Press the "create named range" in the "formulas" tab give name stop recording. Voila. This has many uses in real life Another one might be creating a table with headers. Record Select the table detect the headers with "format as table" and check "my ...

2

I'll start by adding the exercises I'm currently using, but please don't let this stop you from posting more! Create a macro that inserts a header row. (Story: "Every day I download a csv file. Always the same structure, but it is missing the header row. I want a macro that inserts a formatted header above my data.") Number formatting macro (Story: "I ...

2

I think the most critical thing about lambda functions is that they enable the convenient use of map and filter functions on collections and streams. Exercises in using these (and their equivalents in Optional, which is perhaps just as important, allowing us to get rid of null as it does) are probably the best way of showing what you can achieve with lambda ...

2

One idea might be to borrow SQL-related exercises -- find problems asking the reader to come up with some sort of SQL query to find information, and rephrase the problem and ask students to come up with an equivalent query using only Java's functional interface and lambda expressions. (I wouldn't bother telling students these questions were originally about ...

2

Design patterns covers a broad area. I'm going to assume that your students are beginners, more or less. Elementary Patterns A few people have developed some interesting elementary patterns for things as simple as loops and selection: http://www.cs.uni.edu/~wallingf/patterns/elementary/ These patterns help students program at the lowest level and, after ...

2

As well as what you have already mentioned: Provide working code, and have them modify it (top down as opposed to bottom up). I also see an opportunity to reduce time between students actions and receiving feedback. Automated feedback (this is not a substitute for teacher or peer feedback) Use a visual language, such as scratch or snap. This reduces ...

2

I have done something similar to this. I've found codingbat to be a great resource. The exercises there are not complex and are structured in a way that later exercises build on previous ones. There are more exercises there for Java than Python but at worst it may be useful for prompting ideas. Now, I have set classroom exercises using some of the ones ...

Only top voted, non community-wiki answers of a minimum length are eligible