University of Florida

Institute of Food and Agricultural Sciences
   Home  |  Objectives  |  Agents  |  Parents  |  Youth  |  Contact Us  | 
 |  


Programming 102: Advanced Skills

Project Details

     Ask any programmer-the best part of computers is being able to tell them what to do. Every time you operate a computer or use a program to write a letter or play a game, you are telling the computer what to do. However, someone else before you has written all the rules, and you just get to use them to "drive". Imagine the thrill of being that someone else! Imagine having a powerful tool at your disposal that you can manipulate to do almost anything you want it to do. This is the ultimate thrill - at least for a certain kind of computer user.

     This activity isn't for the faint of heart or the beginner. It requires that you've done some programming (maybe in the prior activity in this manual, Programming 101), that you understand some or all of the following programming concepts: requesting input, assignment to variables, formatting and displaying output, iteration, conditional branching, procedure calls, and function calls. It assumes that you know a bit about at least one computer language and the tools to write programs in that language. If you dare, read on.


Materials Needed

     A compiler, or interpreter, or a "development environment" for the programming language you choose.

     Reference manuals on the programming language or environment.

     Books on sample programs for beginners with your programming language.

     Frequent access to the computer at which you will be doing your programming.

     A printer connected to this computer (directly or via network) is very helpful.


Do It

     Select one or more of the following problems and write a program to solve the problem. These problems are roughly listed in order of difficulty. While you may wish to use a development environment for windowing systems, these problems can be solved using just a typed-in interface that doesn't have all the fancy graphics. Your results may not look fancy, but real programmers don't care-it's the joy of the task not the look of the results that counts! Eventually, you'll be able to be more concerned about the looks, but for now, enjoy (and master) the process.

     These problems are just ideas. You may have a problem of your own that you would like the computer to solve for you. The sky's the limit.

  1. Write a program that writes your name in block letters vertically down the page. If you'd like to take this further, write a program that asks for any user's first name, and write the name in block letters. Let each block letter be made up of itself. For example:

    L would be:

    L
    L
    L
    LLLL
    C would be"

    CCC
    C
    C
    CCC

    Concepts used: assignment, conditional branching.

  2. Here's a little number-juggling program. Ask a user for the year of his or her birth and his or her age. Then double the birth year, add five, multiply by fifty, add the age, subtract 250, and divide by 100. Write the answer out with 2 digits of decimal accuracy. What is it? Be sure your program tells the user what it's doing with each step.

    Concepts used: requesting user input, assignment to variables, and formatting output.

  3. Write a program that asks for a person's age in years, months, and days, and tell that user how many seconds old they are. Write the answer with comma's in the appropriate places in the number, if you can. Continue to ask for another age to convert to seconds until the user enters a 0, which is the signal to end the program.
  4. Concepts used: assignment to variables, requesting user input, iteration, formatting output.

  5. Because a program user can't actually look inside the computer to see what a program does, it's possible to make a program seem more intelligent than it really is. Write a program that appears to engage in small talk (by asking the user questions), but which in reality ignores the answers (because everybody's answers will be more or less the same). You can create a more convincing sense of interaction by periodically prompting for and echoing integer or single character data, such as the user's street number, age, or number of brothers and sisters. A more sophisticated version of this program was used to completely fool people into thinking they were typing answers that were being read and responded to by a real psychiatrist. See if you can make yours that realistic and try it with your friends!

    Concepts used: processing user input, formatting output, assignment to variables.

  6. A palindrome is a number or a text phrase that reads the same backward and forward. For example, each of the following is a palindrome: 12321, WOW, 11611. Write a program that reads in a string of letters or numbers or a phrase and determines if it is a palindrome.

  7. Write a program that creates a schedule for a day by adding time. It should ask the user for the time to start the day and the time to end the day's activities. Each time should be entered with a colon between the hours and minutes (8:35). The program user should enter activities in the order they wish to do them and the time in minutes that it should take for each activity. The user should continue to enter activities and the time to accomplish each activity until the end of the day. The program should print to a file a schedule for the day's activities with the time each should start and stop.

    Concepts used: assignment to variables, writing output to a file, iteration, conditional branching.

  8. In the game of Hangman, a player tries to guess letters in a secret word. With each wrong guess, the stick figure of a hanging man is partially drawn. When six wrong guesses have been made, the figure is complete, and the player loses the game. Write a program to play the game with two players. The first player types in the word that the other tries to guess. The game displays the hanging man in one of the six stages of development each time the second player incorrectly guesses a letter. For example:

    Stage 1 Stage 2 Stage 3 Stage 4 Stage 5 Stage 6
     
    O O
    |
    O
    -|  
    O
    -|-
    O
    -|-
    /  
    O
    -|-
    / \

    It displays the status of the word being guessed with each successful guess of a letter. Letters that have not yet been guessed are displayed with an underscore (e.g., _ r e _ g h t)

  9. Write a program to convert an amount of money in numerical form to the same amount of money in text form. Use this program as a procedure in a larger program to write checks. Prompt the user for the payee and the amount with no dollar signs. The program will print on the appropriate place on a preprinted check today's date, the payee, the numerical amount, and the amount in words. (The checks will need to be purchased preprinted, either on tractor-fed paper for a dot-matrix printer or on single sheets for a laser or ink-jet printer. Your bank will order checks in this format for you.)

Review It

  • Look again at problem 1. Why were you asked to print the letters vertically down the page rather than horizontally? What is a non-proportional font and why is using one helpful for this exercise?


  • Look again at problem 6. What would you have to do differently to print the schedule to the screen after the user told you all the activities and the time for each? Would the program be more difficult that way?

Pursue It

  • Look again at problem 1. If you want to turn this into a more advanced exercise using arrays, try writing anyone's first name horizontally!


  • Write problem 6 so that the schedule is printed to the screen after the user has provided all the input. This will require you to store all of the information before finally printing it. Consider using a 2- dimensional array to accomplish this.


  • Write problem 7 so that it is a game for one rather than for two. Let the computer be the source of the words and have a random number generator select the words from a data bank of words that the program accesses.


  • Exhibit your program at the fair. Make sure you have written documentation so someone else can figure out what your program is supposed to do and can evaluate whether it does it. That documentation should include either a flowchart or pseudocode that is structured and readable.

Data Bank

     The best source of information on the language you are using to write your program is the manual that comes with the compiler or interpreter or environment.

     For more information see http://www.yahoo.com/Computers_and_Internet/Programming_Languages



Activity: Write a computer program
Skill level: Advanced
Project skill: Programming
Life skill: Marketable skills
Date completed:

Helper's initials:


Adapted from material developed by Illinois 4-H. Used by permission.

For IFAS-related questions or information, please contact IFAS External Relations.
Copyright © 1994-2000 | University of Florida | Institute of Food and Agricultural Sciences | Gainesville, FL 32611
For Web site problems or suggestions, contact the site Web Master.