Name______JNumber______Section______

CIS 115 Introduction to Problem Solving and Programming

Instructor: Overstreet

Homework 5 (VB – Procedures and Functions)

Due: Week 9 - Friday, March 13

Write a VB application to compute the number of calories in a particular food item, given the amount (in grams) of carbohydrates, protein, and fat. Have the user input the name of the food item, grams of carbohydrates, grams of protein, and grams of fat, then click a button to calculate the total number of calories. Use the following info to compute the calories:

Carbohydrates – 4 calories per gram

Fat – 9 calories per gram

Protein – 4 calories per gram

Build a formatted output string to indicate the name of the item and the number of calories. Display this string to the user using a message box. Format the output string as follows:

Food item name contains number calories.

Use variables to hold the name, grams of carbohydrates, grams of protein, grams of fat, and calories. Your event procedure should call a separate function to compute the calories, and a separate sub procedure to build and display the output string.

For this exercise, you will submit your completed solution design sheet (inputs, outputs, processes, TOE Chart, algorithm, and data dictionary), evaluation sheet (test design), a printed copy of your Visual Basic Application (a screen shot of your running program, including InputBox screens), and a printed copy of your code. If you do not include the completed solution sheet, evaluation sheet, and both the screen shot and the code, your assignment will be counted as incomplete.

Staple your grade sheet (on top), the evaluation sheet, the solution design sheet, the screen shots, and the code together and make sure to write your name, jnumber and section number at the top of your grade sheet. No envelope necessary.


CIS 115 Introduction to Problem Solving and Programming

Instructor: Overstreet

Homework 5 (VB – Procedures and Functions)

Solution Design Sheet

Inputs:

Outputs:

Processes:

Solution (TOE Chart/Algorithm):

Tasks / Objects / Events
Input Food Name / Text Box, Label / None
Input Carbs / Text Box, Label / None
Input Fat / Text Box, Label / None
Input Protein / Text Box, Label / None
Store Inputs, Call Function to Compute Calories, Call Sub to Build and Display Output String / Button (btnComputeCalories) / Click
Exit Program / Button (btnExit) / Click

Event Event Procedure Code Algorithm

btnComputeCalories_Cick 1. Input and store Food Name

2. Input and store Carbs (grams)

3. Input and store Fat (grams)

4. Input and store Protein (grams)

5. Call function to return number of calories

Arguments:

6. Call sub to build and display formatted output string

Arguments:

btnExit_Click 1. End the application


CIS 115 Introduction to Problem Solving and Programming

Instructor: Overstreet

Homework 5 (VB – Procedures and Functions)

Sub/Function Sub/Function Code Algorithm

Funtion ComputeCal(Single,Single,Single) As Single

Sub OutputResults(String,Single)

Data Dictionary:

Variable Name / Type / Usage / Initial

Evaluation Sheet

Test Design:

Test Case / Inputs / Expected Outputs / Observed Outputs
Carbs (grams) / Fat (grams) / Protein (grams) / Calories / Calories
1
2
3
4
5


CIS 115 Introduction to Problem Solving and Programming

Instructor: Overstreet

Homework 5 (VB – Procedures and Functions)

Due: Week 9 - Friday, March 13

Grade Sheet

_____(20pts) Completed solution design sheet (understand/design)

_____(10pts) Completed evaluation sheet (evaluation)

_____(30pts) Screen shots (interface implementation)

_____(40pts) Code listing (algorithm implementation)

_____(100pts) Total Score