Exercises

Goat

Many of these were exams (exam 1) in the past.

Exercise

Your simple program

Write a program like the tip calculator, length converter, and Aussie Rules scorer. When a button is pressed, it should take some input from the worksheet, do some calculation(s), and output to the worksheet, using the IPO pattern. Input and output can be numeric and/or string.

Add a comment for each part of your IPO code, like "Arr! Here be input, maties!" You don't have to do Pirate, though.

Use good variable names, Option Explicit, and other things you need.

Upload your worksheet.

Exercise

Questions

Write a program that asks the user about their name, their dog's name, and shows a message. All input and output is with dialogs. First, the program asks for the user's first name:

First name

Then the last name:

Last name

Then the dog's name:

Dog's name

That's all the input. After that, your program shows a message, that puts together the data:

Output

Format the message exactly, with the right spacing, and the line breaks.

Notice something else you need to do. The user might type extra spaces around their input, like they did with the dog name.

Dog's name

Make sure the extra spaces do not affect the output.

Another run sequence:

First name

Last name

Dog name

Output

Upload your worksheet. The usual coding standards apply. Good variable names, like that.

Exercise

Cylinder covering

Write a program to help users work out how much fabric they need to make a covering for their fave cylinder. The input should be from the worksheet, like this:

Input

I asked Google how to work out the surface area of a cylinder. It said:

Surface area formula

Here's the output for that data:

Output

Problem, though. The input is in centimeters. The output should be in square meters. I asked Google about that, too.

Square cm to square meters

Another example. The input:

Input

Output:

Output

Upload your workbook. The usual standards apply.

Exercise

XP

Write a program that computes how many experience points (XP) a player earns in a game. They earn XP from killing things like rats, and zombies. You can download this starting workbook.

Here's the start screen:

Start

The user enters numbers in the cells, and clicks the button. Here's some sample output:

Output

Here's what each critter is worth:

Critter XP each
Bat 5
Rat 7
Wolf 20
Zombie 25
Goblin 30
Hobgoblin 50

Upload your solution. The usual coding standards apply.

Exercise

Food order

Write a program to compute the price of a goaty food order. You can download a starting workbook. Here's what it looks like to start:

Start

Users type in the number of each item they want to order. Your program works out the total food cost, total drink cost, total service charge, and the overall total. Here some output:

Output

Write a program to do this.

Important! Your code should get all the prices from the worksheet. Your code should not have 14.95 anywhere in it. Nor 2.95. Nor 0.75. Etc.

You don't need to round the prices to the nearest cent. If you want to, this page explains how.

Include comments identifying each of the three parts of the program.

Upload your solution. The usual standards (variable name standards, indenting, maybe other stuff you've learned) apply.

Exercise

Goatercise

Write a program to work out how many calories a goaty workout will burn. You can download a start worksheet. It looks like this:

Start

Users fill in the green cells, and click the button. They see the calories their workout would burn. Here's how much toning exercises burn per rep:

Exercise Calories for one rep
Butt heads 20
Foreleg curl 14
Angst 27

Calories for a toning exercise are the number of sets, times the reps per set, times the value above, like 20.

Here's the burn for cardio:

Exercise Calories per minute
Treadmill 180
Unicycle 320
Worried pacing 90

Here's some output:

Output

Some more:

Output

Upload your solution to this site, not to Moodle. The usual coding standards apply.

Exercise

The Bonnie Burns Effect

Nobody Listens to Paula Poundstone is your comedy field guide to life. The podcast features Paula, her cohost Adam (who is on every show), Toni, and the redoubtable Bonnie Burns.

Paula's assistant Wendell noticed the more Bonnie is on the show, the more merch they sell, but the lower their sponsorship revenue is. Sponsors are nervous about Bonnie, who might, for example, use "alternative facts" about her age to get a better deal, or lure Toni into a life of breakfast crime.

Bonnie also drives some people to despair. The show has had to pay for psychiatric care for Adam and Vic, the show's sound editor.

Some of Bonnie's antics pose legal risks, such as a threatened lawsuit by the estate of Zero Mostel. The show seeks legal advice before releasing a Bonnie-ridden episode.

Write a VBA program to estimate the revenue effect of each minute Bonnie is talking on the show. You can download a start worksheet. It looks like this:

Start

The user fills in values in the input part, above the Run button. They click the button, and get the output.

  • Add in the effect of merch and sponsor changes.
  • Adam needs two hours of psychiatric care for each minute Bonnie talks.
  • Vic needs three hours per minute, since he has to listen to Bonnie speak more than once while he's editing the show.
  • The show needs one hour of legal advice for each minute Bonnie talks.

Here's some sample output:

Output

Use the IPO pattern. Add a comment identifying each of the three parts of the program.

Upload your workbook with the VBA code here. The usual standards (variable naming, indentation, secluded cells, explicit variables) apply.

Exercise

Frenchness concentration

About this exercise

This is another in a continuing series of exercises about my fave podcast, Nobody Listens To Paula Poundstone. It's dedicated to my fellow Nobodies.

Adam Felber is a writer, musician, and cohost of Nobody Listens To Paula Poundstone. He's on every show.

Recently, he fainted at a party full of French people. Medical tests found Adam is allergic to Frenchness. Any more than 2.85 Frenchness per cubic meter in the room, and Adam's in danger of fainting.

Write a VBA program to estimate the concentration of Frenchness in a room. Download this workbook as a starting point.

Here's how your worksheet should start:

Start

The user types values in the People cells, and clicks Run. Here's some output:

Output

Here's some more output:

More output

Frenchess per cubic meter is the number of people from Paris (2 in the example above) times Paris' concentration (0.11) plus the number of people from Nice (3 in the example) times Nice's concentration (0.18), etc.

Requirements:

  • Don't put the concentration values (like 0.11) directly in your code. They may change over time.
  • Follow the secluded Cells rule.
  • Use the IPO pattern. Add comments identifying each section, e.g., 'Input.
  • No lines of code should be more than 60 characters long. Check the dialogs lesson if you need a reminder.
  • The usual standards apply (like good variable names, and Option Explicit).

Upload your solution as usual.