Exercises

Goat

Exercise

Cthulhu helps Kyrat

Kyrat's economy has been devastated by mismanagement and civil war. The Golden Path rebels have defeated King Pagan Min, and are seeking investment from the West.

Our pal Cthulhu steps (slithers?) forward. It opens a chain of stores selling goats and chickens.

Goat Chickens

Sold in Cthulhu's Kyrati stores

Two stores are in northern Kyrat, and three stores are in the south. The daily sales from the northern stores are in one CSV file. Sales from the southern stores are in another CSV file.

Write a program that reads both CSV files, and makes a combined report. The worksheet starts out like this:

Start

Cthulhu keeps changing the names of the stores, so they need to be read from the files each day. The file names can change, too, so they need to be read from the worksheet.

Here's a sample file for the south:

  • "Banapur Supplies",8,8
  • "Shanath Overstock",21,31
  • "Ajay's Animonculory",14,15

The first field is the store name. The second is the goat sales. The third is the chicken sales.

The file for the north is the same format, just fewer lines:

  • "Rohan Farm Friends",13,7
  • "Jalendu Joy Shop", 19, 23

You can copy-and-paste this data to make your own CSV files.

When the user clicks the Run button, the program reads the files, shows the data, and the totals. Like this:

Output

Upload your workbook. The usual coding standards apply.

Exercise

Stock price change

Write a program that computes changes in stock price. The worksheet starts like this:

Start

The user types the name of a CSV file into a cell, and clicks Run. The file must be in the same folder as the workbook.

Here's a sample CSV file:

  • "CMC", 400, 500

The first field is the company code, the second is the start price, the third is the end price.

The change is the end price minus the start price, divides by the start price. Note that the output must be a percentage.

Here's some output:

Output

Here's some more. The file has:

  • "GG", 30, 45

Output

Upload your solution. The usual coding standards apply.

Exercise

Goat tax returns

Goats can submit their tax returns electronically, with the data in a CSV file. Here's the file format:

  • "Name", income, Cthulhu-related expenses, tax already paid

For example, the file nellie.csv might have this:

  • "Nellie the Super Goat",291,39,42

Write a program to compute taxable income, tax, and amount due. You can download a workbook that's already been set up for you. You just have to add the code.

You can also download three CSV files to test your workbook:

The worksheet starts like this:

Start

The user fills in the file name, and clicks Run. As usual, the CSV file should be in the same folder as the workbook.

The output would be:

Output

Another example. This is in virrotio.csv:

  • "Vittorio",128,5,13

Output:

Output

Another example. maggie.csv has:

  • "Maggie",924,89,172

Output:

Output

As long as the numbers are within one decimal point, that's fine.

Read the tax rate from the worksheet. This lets Cthulhu arbitrarily change the tax rate for goats who say things it doesn't like. Yeah, it's a jerk.

Separate your code into input, processing, and output sections, with each line of code in the right section. Use comments to label the sections.

Upload your workbook. The usual coding standards apply.

Exercise

Sandwich winner

Cthulhu has a sandwich eating contest every week. Goats eat three sandwiches:

  • Vegemite
  • Peanut butter
  • Marmalade

Goat

​Vegemite! Yum!

Their eating time for each one is recorded. The goat with the lowest total time is the winner.

Cthulhu wants each week's winner to be on its website. Write a program to make that happen.

Cthulhu will send you a CSV file each week, called winner,csv, with data on the winner. For example:

  • "Hattie"
  • 2.6, 4.5, 3.8

The first line has the goat's name. The second line has the times in seconds. Vegemite time, then peanut butter time, then marmalade time.

Your worksheet should look like this to start:

Start

Press the button, and your code runs. It should fill in the worksheet, as well as make the webpage winner.html. The program should show a message when it's done writing the file.

Here's the worksheet with output:

Worksheet output

Here's what winner.html looks like in a web browser:

HTML output

Your program should write the HTML that makes the page. Here's the HTML for this case:

  • <h1>Sandwich Eating Winner</h1>
  • <p>This week's winner is Hattie, with an average time of 3.633333 seconds.</p>

Of course, if the data in the CSV file is different, the output will be different, too. Your program should run with any valid input data.

Upload your worksheet. Hint: test it with at least two different input data sets.

Exercise

Aussie rules webpage

Make a worksheet that starts like this:

Start

The user fills in the team names, goals, behinds, and file name.

Data entered

The user clicks Run. The program computes the scores (goals * 6 + behinds), and shows them in the worksheet:

Output

The program outputs HTML to the file name given. Here's what the file given in the screenshot would look like in a browser:

Webpage

Upload your workbook as usual.

Exercise

Cake production planning

The Goat Cakes Squishing Company (GCSC) makes and sells goat cakes, for birthdays, sillydays, osmondays... goats celebrate all kinds of things.

Goat cakes aren't baked. They're made by squishing stuff together in powerful presses. There are two kinds of cakes:

  • Corn cakes
  • Oat cakes

GCSC has two retail stores, called North and South, and a central factory. The cakes are pressed in the factory, and sent to the stores.

Sometimes, customers order cakes ahead of time at the stores. So a goat might order two oat cakes for next week, from South. Other cakes are sold over-the-counter (OTC), as goats wander in from the street.

Write a production planning program, to estimate the number of cakes GCSC will need for the coming week. Your program should produce different output, depending on the data in the CSV files.

Each store emails a CSV file to the factory, with the number of corn and oat cakes customers have ordered for the week. For example, North might send this file:

  • 13,8

That would mean North has orders for 13 corn, and 8 oat. The file is always called north.csv.

South sends a similar file, called south.csv.

Your worksheet should start like this:

Start

(You can download a starting worksheet.)

B7 and B8 show data read from north.csv. B11 and B12 show data read from south.csv.

B15 and B16 show estimates OTC for the week, for North and South added together.

  • For North, OTC is double the orders. So if corn orders for North are 10, estimated OTC will be 20. If oats orders are 8, estimated OTC will be 16.
  • For South, OTC is triple the orders (southern goats are more impulsive). So if corn orders for South are 10, estimated OTC will be 30. If oats orders are 8, estimated OTC will be 24.

The total for corn (B19) is North corn orders plus South corn orders plus OTC. Same for oats.

Here is some sample output:

Output

Here's some output for different CSV data:

More output

Upload your solution. The usual coding standards apply.

Exercise

Weekly goat count

You're the Chief Goat Counter for Atafu. You have three countorial assistants, each assigned to count the goats in one region of the island:

Atafu regions

Each week, the countorials deliver their goat counts to your PA, Deranged Dirk. Deranged puts them in a CSV file for you, always in the same format. For example:

  • 32, 18
  • 59, 31
  • 113, 75

The first line is number of big (32) and small (18) goats in the NW region. The second line is number of big (59) and small (31) goats in the NE region. The third line is number of big (113) and small (75) goats in the south region.

You can download this file.

Write a VBA program to make a webpage summarizing a week's goat data. To start, the worksheet looks like this:

Start

You don't have to make this yourself. You can download it, already set up for you. Hooray!

The user types in the names of the input and output files. The input file is the CSV data file. The output file is a webpage file.

The user clicks the button. The program:

  • Reads the input
  • Computes the results
  • Puts the results in the worksheet
  • Creates a webpage file with the results

So, the output shows up in two places:

  • The worksheet
  • The webpage

For the data above here is the output. First, the worksheet:

Output

Notice your program should show a message box to the user, after it does everything.

Here is the webpage for that data:

Webpage

You can download the webpage. Open it in Notepad, TextEdit, or another text editor, if you want to check out the HTML your program should create. (I prefer Notepad++. Free! Free is good.)

Here's another example. First, the input:

  • 41, 21
  • 69, 36
  • 141, 95

You can download the file if you want it.

Here is the output. The worksheet:

Output

Here's the webpage output:

Webpage

You can download the webpage. Open it with a text editor to see the HTML.

Submit your workbook. No need to submit data files, or webpages. The usual coding standards apply.

Remember, your goat loves you. Play with it.

Exercise

Game Space price estimate

Goats like to meet up for epic computer game events. Your company sells game space packages to event organizers. The packages include the tables and hardware needed to run events.

Write a program to estimate the price of a game space package for a customer. The program outputs a webpage. You can download a starting workbook.

Here's what the worksheet looks like to start.

Start

Users fill in the customer name, expected number of each goat breed, and the output file name.

Input

When they click Run, the program creates a webpage with a price estimate, and shows a message box when it's done:

MsgBox

Here's what the output would look like, for the input above:

Output

You can get the HTML for this case. (When it shows in a browser, right-click on the page, and view source, to see the HTML. Don't use Safari.)

You ask Jolene, a grizzled old goat who's been making estimates for years, how the estimates are computed. Here's what she says.

- - CUT SCREEN HERE - -

(Spits)

Howdy. So, you're the programmin' expert, huh? (Hrunk, burp) Shoot, I shouldna had that extry spicy cud. Well, shows ya, us old folk are stupid, too.

Anyways, we gets medium tables for Alpines and Toggenburgs. Plus four spares. Them Toggenburgs get kinda smashy when they lose. Them mediums cost $65 each.

We gets a small table for each Pygmy, and two spares. The smalls cost $48 each.

We gets a laptop for each goat, and two spares. They cost $1,700 each.

An' we gets a goat keyboard for each goat. With five spares. They's $46 apiece.

Oh, and the goat trackballs. One each goat, cost $52 each. Three spares.

I gotta go lie down.

- - CUT SCREEN HERE - -

Hint: check the sample output file, so you know what output your program should create.

Here's another example. Input:

Input

Output:

Output

Upload your workbook. The usual coding standards apply.