Programming Problems

Submitted by: Submitted by

Views: 1469

Words: 1569

Pages: 7

Category: Science and Technology

Date Submitted: 08/13/2011 08:58 PM

Report This Essay

Chapter 2: Programming Problems, page 109-110

2. The manager of the Super Supermarket would like to be able to

compute the unit price for products sold there. To do this, the

program should input the name and price of an item and its weight

in pounds and ounces. Then it should determine and display the

unit price (the price per ounce) of that item and the total cost of the amount purchased.

Main Module

// Declare the variables

Declare ItemName as String

Declare ItemPrice, Unit Price, WeightOunces as Float

Declare ItemWeight, WeightPounds As Integer

// Get the name of the item

Write “What is the name of the item?”

Input ItemName

// Get the price of the item in dollars and cents

Write “What is the price of the item in dollars and cents?”

Input ItemPrice

// Get the weight of the item in pounds and ounces

Write “What is the weight of the item in pounds and ounces?”

Input WeightPounds, WeightOunces

// Calculate the unit price of the item

Set ItemWeight = (WeightPounds * 16) + WeightOunces

Set UnitPrice = ItemPrice / ItemWeight

// Output the result

Write “The price of the item per unit is “ + UnitPrice + “unit price”

4. Shannon and Jasmine bowl as a team. Each of them bowls three games in a tournament. They would like to know their individual averages for their three games and the team score (the total of the six games). Allow the user to input the scores for each player. Output Shannon’s average, Jasmine’s average, and the team score. You will need the following variables:

Score1 (a Float)

sumShannon (a Float)

avgJasmine (a Float)

Score2 (a Float)

sumJasmine (a Float)

total (a Float)

Score3 (a Float)

avgShannon (a Float)

Main module

Declare Score1, Score2, Score3, Total As Float

Declare SumShannon, SumJasmine, AvgShannon, AvgJasmine As Float

Write “Bowling Average Program”

Write “This program computes the average of three scores, the total team score ”

Write “and displays...