Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Exercises

 

Exercise 1

 

Assume that you are the mananger of a restaurant.

 

Establish a price for cokes, fries, and burgers and set a tax rate. Make these global variables - place before the main. Example of a global declaration follows:

 

In the main method

 

greet the customer (assume only 1 customer - do not use a loop)

state prices

take number of cokes and return this number to the main

take number of fries and return this number to the main

take number of burgers and return this number to the main

calculate and announce the total price.

 

 

Exercise 2

 

Ask the customer how much money he is providing in payment in terms of dollars, quarters, dimes, nickles, and pennies.

Calculate and tell the customer what the change is in terms of the above, as appropriate.

 

Exercise 3

 

Part a

 

(1) Define the following. Include an example in your definition.

     (a) Function Scope

     (b) File Scope

     (c) Block Scope

     (d) Function-Prototype Scope

 

Part b

 

Chapter 6 of the text, Exercises, Exercise 6.12, pages 316-317.

 

Exercise 3

 

An integer is said to be perfect if the sum of its factors, including 1 (but not the number itself) is equal to the number. For example, 6 is a perfect number, because 6 = 1 + 2 + 3.

 

Write a function named perfect that detetrmines whether the parameter passed to it, number, is a perfect number.

 

Use this function in a program that prints all the perfect numbers between 2 and 10,000. Print the first 5, one per line, along with the factors.