Você está na página 1de 21

Chapter 2

Programmng Chaenges

1. Name and Intas

Name of a person usuay conssts of rst


name, mdde name, and ast name.
Deveop a program that has the foowng
methods

Return the fu name of that person. For


exampe, "Hoang The Nguyen"

Return the author name for ctng a


reference. For exampe, "Nguyen H.T."

2. Name, Age, and Annua
Income

Deveop an empoyee report that has the


foowng nformaton

Name

Age

Annua pay

For exampe, Mr. |oe Mahoney s 26 years


od. He earns $100,000.0 per year

3. Persona Informaton

Deveop a program to represent


nformaton of a person. The nformaton
shoud ncude

Name

Address (number and street) wth cty, state,


and ZIP

Teephone number

Coege ma|or

http://www.nm.nh.gov/servces/faqmages/nst
_address.|pg

4. Sum of Two Numbers

Deveop a program to cacuate the sum


of two ntegers

5. Saes Tax

Deveop a program to cacuate the sae


tota by usng the foowng formua
sae tota = purchase amount + state
saes tax (4%) + county saes tax (2%)

6. Star Pattern

Deveop a program that dspays the


foowng pattern
*
***
*****
*******
*****
***
*

7. Land Cacuaton

One acre of and s equvaent to 43,560


square feet. Deveop a program that
cacuates the number of acres n a tract
of and wth a gven vaue n square feet,
for exampe, 389,767 square feet

8. Saes Predcton

The East Coast saes dvson of a


company generates 62 percent of tota
saes. Based on that percentage, deveop
a program that w predct how much
East Coast dvson w generate f the
company has $4.6 mon n saes ths
year

9. Mes-per-Gaon

A car's mes-per-gaon (MPG) can be


cacuated wth the foowng formua
MPG = Mes drven / Gaons of gas used
Deveop a program to cacuate the car's
MPG

10. Crcut Board Prot

An eectroncs company ses crcut


boards at a 40 percent prot. If you know
the reta prce of a crcut board, you can
cacuate ts prot wth the foowng
formua
Prot = Reta prce 0.4

Deveop a program to cacuate the


amount of prot earned for that product

11. Test Average

Deveop a program to cacuate the


average of three test scores

12. Restaurant B

Deveop a program that computes the


tax, tp and tota on a restaurant b. The
tax shoud be 6.75 percent of the mea
charge. The tp shoud be 15 percent of
the tota after addng the tax

13. Stock Commsson

Kathryn bought 600 shares of stock at a


prce of $21.77 per share. She must pay
her stock-broker a 2 percent commsson
for the transacton. Deveop a program
that cacuates the foowng

The amount pad for the stock aone (wthout


the commsson)

The amount of the commsson

The tota amount pad (for the stock pus the


commsson)

14. Strng Manpuator

Gven the name of a cty, deveop a


program that provdes the foowng

The number of characters n the cty name

The name of the cty n a uppercase etters

The name of the cty n a owercase etters

The rst character n the name of the cty



15. Energy Drnk Consumpton

A soft drnk company recenty surveyed


12,467 of ts customers and found that
approxmatey 14 percent of those
surveyed purchase one or more energy
drnks per week. Of those customers who
purchase energy drnks, approxmatey 64
percent of them prefer ctrus-avored
energy drnks. Deveop a program that
cacuates the foowng

The approxmate number of customers n the


survey who purchase one or more energy
drnks per week

The approxmate number of customers n the


survey who prefer ctrus-avored energy
drnks

16. Stock Transacton Program

Last month |oe purchased some stock n


Acme Software, Inc. Here are the detas
of the purchase:

The number of shares that |oe purchased was


1,000

When |oe purchased the stock, he pad


$32.87 per share

|oe pad hs stock broker a commsson that


amounted to 2% of the amount he pad

Two weeks ater |oe sod the stock. Here


are the detas of the sae:

The number of shares that |oe sod was 1,000

He sod the stock for $33.92 per share

|oe pad hs stock broker another commsson


that amounted to 2% of the amount he
receved for the stock

Deveop a program that cacuates the


amount of prot that |oe made after
seng hs stock and payng the two
commssons to hs broker. (If the amount
of prot that your program devers s a
negatve number, then |oe ost money on
the transacton)

17. Word Game

A story conssts of the foowng unque


parts

Name of a person

Age

Name of a cty

Name of a coege

A professon

A type of an anma

A pet's name

Deveop a program that produces the


foowng story

There once was a person named NAME
who ved n CITY. At the age of AGE,
NAME went to coege at COLLEGE.
NAME graduated and went to work as a
PROFESSION. Then, NAME adopted a(n)
ANIMAL named PETNAME. They both
ved happy ever after!

Você também pode gostar