Listing 7-1: main in main.m

mewlingtincupΛογισμικό & κατασκευή λογ/κού

9 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

59 εμφανίσεις

1

Replace the text on page 181 of
Objective
-
C Programming For Dummies

with the following text.

Modifying main

To implement the new
spendDollars:

method, you need to make some changes
to
main
. You start by deleting the variable
s

numberDollarsInEuroland


and
n
umberDollarsInPoundland
you were using to represent the dollar
transactions. You replace
them each
with an
NSNumber

object, initialized
with the same amounts that you used to initialize the variables you just
deleted
.
This is shown in the code snippet belo
w @@md remove the code in
bold, italic, underline and add the code in bold
:

//double numberDollarsInEuroland = 100;

NSNumber *europeDollarTransaction = @100.00;

//double numberDollarsInPoundland = 100;

NSNumber *englandDollarTransaction = @100.00;

You then

delete the old
spendDollars:

message
s

and replace
them
with new
one
s

that uses the
NSNumber

argument:

//[europeBudget spendDollars:numberDollarsInEuroland];

[europeBudget spendDollars:europeDollarTransaction];

//[englandBudget spendDollars:numberDollarsIn
Poundland];

[englandBudget spendDollars:englandDollarTransaction];



Replace the text on page 187 of
Objective
-
C Programming For Dummies

with the following text.

Listing 7
-
1: main in main.m

#import <Foundation/Foundation.h>

#import "Budget.h"


int main (in
t argc, const char * argv[]) {



//double numberDollarsInEuroland = 100;


double numberEuros = 100;

// double numberDollarsInPoundland = 100;


double numberPounds = 100;





NSNumber *europeDollarTransaction = @100.00;


NSNumber *europeDollarTransac
tion2 = @200.00;


NSNumber *englandDollarTransaction = @100.00;


2


NSMutableArray *europeTransactions = [


[NSMutableArray alloc] initWithCapacity:1];


[europeTransactions addObject:europeDollarTransaction];


[europeTransactions addObject:e
uropeDollarTransaction2];




Budget *europeBudget = [Budget new];


[europeBudget createBudget:1000.00
withExchangeRate:1.2500];


//[europeBudget spendDollars:numberDollarsInEuroland];


for (NSNumber *aTransaction in europeTransactions) {


[
europeBudget spendDollars: aTransaction];


}


[europeBudget chargeForeignCurrency:numberEuros];




Budget *englandBudget = [Budget new];


[englandBudget createBudget:2000.00
withExchangeRate:1.5000];

// [englandBudget spendDollars:numberDollarsInPoun
dland];


[englandBudget spendDollars:englandDollarTransaction];


[englandBudget chargeForeignCurrency:numberPounds];




return 0;

}