currency converter

14
Currency Converter Program Requirements Problem: Currency Conversion Description: The Currency Conversion application is a menu- driven program that allows users to select one of five international currency types, input the amount of a foreign currency, and then converts the foreign currency to dollars. The program displays the equivalent dollar amount and returns the user to the menu until he or she enters another conversion or quits the program. International currency type (menu selection) Canadian dollars (rate: 1 U.S. dollar = 1.4680 Canadian dollars) Mexican pesos (rate: 1 U.S. dollar = 9.5085 pesos) English pounds (rate: 1.6433 U.S. dollars = 1 pound) Japanese yen (rate: 1 U.S. dollar = 104.9200 yen) French francs (rate: 1 U.S. dollar = 6.2561 francs) Application-Level Requirements List 1. The program shall present a series of user screens that prompts the user for specified input. 2. The main user screen shall have an application title. 3. The main user screen shall have a short description telling the user how to use the program. 4. The calculation of the currency shall be executed only after all the valid input values are provided. 5. The program shall allow the user to clear all input fields and recompiles the calculation. 1

Upload: david-suresh

Post on 08-Apr-2015

618 views

Category:

Documents


21 download

TRANSCRIPT

Page 1: Currency Converter

Currency Converter Program

Requirements

Problem: Currency Conversion

Description: The Currency Conversion application is a menu-driven program that allows users to select one of five international currency types, input the amount of a foreign currency, and then converts the foreign currency to dollars. The program displays the equivalent dollar amount and returns the user to the menu until he or she enters another conversion or quits the program.

International currency type (menu selection)

Canadian dollars (rate: 1 U.S. dollar = 1.4680 Canadian dollars)

Mexican pesos (rate: 1 U.S. dollar = 9.5085 pesos)

English pounds (rate: 1.6433 U.S. dollars = 1 pound)

Japanese yen (rate: 1 U.S. dollar = 104.9200 yen)

French francs (rate: 1 U.S. dollar = 6.2561 francs)

Application-Level Requirements List

1. The program shall present a series of user screens that prompts the user for specified input.

2. The main user screen shall have an application title.3. The main user screen shall have a short description telling the user how to use the

program.4. The calculation of the currency shall be executed only after all the valid input values

are provided.5. The program shall allow the user to clear all input fields and recompiles the

calculation.

1

Page 2: Currency Converter

Currency Converter Program

Input-Process-Output Chart

Input Process OutputName:Type:

Range:

Display Menu Name:Type:

Range:

Currency TypeInteger1-6

Name:Type:

Range:

International ValueReal0-1,000,000

Get Foreign Value Name:Type:

Range:

International ValueReal0-1,000,000

Name:Type:

Range:

Name:Type:

Range:

International ValueReal0-1,000,000

Currency TypeInteger1-6

Convert Currency Name:Type:

Range:

US ValueReal> 0

Name:Type:

Range:

Name:Type:

Range:

Name:Type:

Range:

Currency TypeInteger1-6

International ValueReal0-1,000,000

US ValueReal> 0

Display Results Name:Type:

Range:

Name:Type:

Range:

Name:Type:

Range:

Currency TypeInteger1-6

International ValueReal0-1,000,000

US ValueReal> 0

2

Page 3: Currency Converter

Currency Converter Program

Design

Hierarchy Chart

Flowcharts

Control Flow Diagram—-Main Control

3

Page 4: Currency Converter

Currency Converter Program

Control Flow Diagram—Display Menu

4

No

Page 5: Currency Converter

Currency Converter Program

Control Flow Diagram—Get_Int_Value

5

Page 6: Currency Converter

Currency Converter Program

Control Flow Diagram—Convert Currency

6

Page 7: Currency Converter

Currency Converter Program

Control Flow Diagram—Display Results

7

Page 8: Currency Converter

Currency Converter Program

Psuedocode

Main Module

Declare selection as integerDeclare currency Type as IntegerDeclare international Value as realDeclare US Value as real

Do while user wants to continueDisplay MenuGet International ValueConvert CurrencyDisplay Results

End loopPrint exit message

End Main Module

Display Menu

Declare continue as BooleanSet continue = trueWhile continue = true

Display "Welcome to the international currency conversion program"Display "Please make a selection"Display "International Currency Types:" Display "1: Canadian Dollars" Display "2: Mexican Pesos" Display "3: English Pounds" Display "4: Japanese Yen" Display "5: French Francs" Display "6: Quit" Display "Enter a selection:";

Input currency Type

If currency Type >= 1 AND currency Type <= 5 thenSet continue = false

else if currency Type = 6Display “Quitting Currency Conversion”continue = false

else Display “"Error 1: Invalid menu selection."continue = true

end if

8

Page 9: Currency Converter

Currency Converter Program

end WhileEnd Display MenuGet International Value

Declare value as integerDeclare continue as BooleanSet continue = trueWhile continue = true

Display "Enter a currency value (positive number): "Input international Valueif international Value > 0 AND international Value <= 1000000 thencontinue = false

elseDisplay “"Error 2: Invalid input--Negative Number"continue = true

end if end while

End Get International Value

Convert Currency

Declare rate as realSelect Case of currency Type

case 1: Set rate = 1.4680 case 2: Set rate = 9.5085 case 3: Set rate = .6433 case 4: Set rate = 104.9200 case 5: Set rate = 6.2561 default: Set rate = 0.0End CaseUS Value = rate * international Value

End Convert Currency

Display Results

Declare nation as stringDeclare currency as stringSelect Case of currency Type case CANADIAN: nation = "Canadian";

9

Page 10: Currency Converter

Currency Converter Program

currency = "Dollars"; case MEXICAN:

nation = "Mexican"; currency = "Pesos";

case ENGLISH: nation = "English"; currency = "Pounds";

case JAPANESE: nation = "Japanese"; currency = "Yen";

case FRENCH: nation = "French"; currency = "Francs"; default: nation = "No country"; currency = "";End Caseif currency <> “” then

Display “The value of “, international Value, “ “ , nation, “ “, currency, “ is “, US Value, “ dollars”else

Display "Error3: Invalid currency type."end if

End Display Results Test Values

Input Expected Output CommentsInternational Value case 1 = 0.0

Error Message input out of valid range

International Value case 1 = 1000001

Error Message input out of valid range

International Value case 1 = 0.01

Canadian Dollars = 0.01US Dollars = 0.01468

lower limit of International Value case 1

International Value case 1 = 1000.00

Canadian Dollars = 1000.00US Dollars = 1468.00

middle of International Value case 1

International Value case 1= 7000.00

Canadian Dollars = 7000.00US Dollars = 10276.00

upper limit International Value case 1

International Value case 2= 0.0

Error Message input out of valid range case 2

International Value case 2 = 1000001

Error Message input out of valid range case 2

International Value case 2 = 0.01

Pesos = 0.01US Dollars = 09.5085

lower limit of International Value case 2

International Value case 2 = 1000.00

Pesos = 1000.00US Dollars = 9508.5

middle of International Value case 2

International Value case 2= Pesos = 7000.00 upper limit International

10

Page 11: Currency Converter

Currency Converter Program

7000.00 US Dollars = 66559.5 Value case 2International Value case 3 = 0.0

Error Message input out of valid range case 3

International Value case 3 = 1000001

Error Message input out of valid range case 3

International Value case 3 = 0.01

Pounds = 0.01US Dollars = 0.006433

lower limit of International Value case 3

International Value case 3 = 1000.00

Pounds = 1000.00US Dollars = 643.3

middle of International Value case 3

International Value case 3= 7000.00

Pounds = 7000.00US Dollars = 4503.1

upper limit International Value case 3

International Value case 4 = 0.0

Error Message input out of valid range case 4

International Value case 4 = 1000001

Error Message input out of valid range case 4

International Value case 4 = 0.01

Yen = 0.01US Dollars = 1.0492

lower limit of International Value case 4

International Value case 4 = 1000.00

Yen = 1000.00US Dollars = 104920.00

middle of International Value case 4

International Value case 4= 7000.00

Yen = 7000.00US Dollars = 734440.00

upper limit International Value case 4

International Value case 5 = 0.0

Error Message input out of valid range case 5

International Value case 5 = 1000001

Error Message input out of valid range case 5

International Value case 5 = 0.01

Francs = 0.01US Dollars = .062561

lower limit of International Value case 5

International Value case 5 = 1000.00

Francs = 1000.00US Dollars = 6256.1

middle of International Value case 5

International Value case 5= 7000.00

Francs = 7000.00US Dollars = 43792.7

upper limit International Value case 5

11

Page 12: Currency Converter

Currency Converter Program

References

Venit, S. (2004). Extended prelude to programming: Concepts and design (2nd ed.).

Boston: Scott/Jones.

12