A French solution for Challenge 18


#1

file ActionEtranger.h

[code]#import “Action.h”

@interface ActionEtranger : Action
{
float txConversion;
}

@property float txConversion;

@end[/code]

file ActionEtranger.m

[code]#import <Foundation/Foundation.h>
#import “ActionEtranger.h”

#import “Action.h”

@implementation ActionEtranger

@synthesize txConversion;

-(float) coutAchatEnEuros
{
float c = [super coutAchatEnEuros];
return c * [self txConversion];
}

  • (float) valeurActuelEnEuros
    {
    float v = [super valeurActuelEnEuros];
    return v * [self txConversion];

}
@end
[/code]

file main.m

#import <Foundation/Foundation.h>
#import "Action.h"
#import "ActionEtranger.h"

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

    @autoreleasepool {
        
        NSMutableArray *tableauDesActions = [[NSMutableArray alloc]init];
        Action *newAction1 = [[Action alloc] init];
        
        [newAction1 setPrixAchatAction:2.30];
        [newAction1 setPrixActuelAction:4.50];
        [newAction1 setNbActions:40];
        [tableauDesActions addObject:newAction1];

        Action *newAction2 = [[Action alloc] init];
        [newAction2 setPrixAchatAction:12.19];
        [newAction2 setPrixActuelAction:10.56];
        [newAction2 setNbActions:90];
        [tableauDesActions addObject:newAction2];
        
        Action *newAction3 = [[Action alloc] init];
        [newAction3 setPrixAchatAction:45.10];
        [newAction3 setPrixActuelAction:49.51];
        [newAction3 setNbActions:210];
        [tableauDesActions addObject:newAction3];

        ActionEtranger *newActionEtranger1 = [[ActionEtranger alloc] init];
        [newActionEtranger1 setPrixAchatAction:2.30];
        [newActionEtranger1 setPrixActuelAction:4.5];
        [newActionEtranger1 setNbActions:40];
        [newActionEtranger1 setTxConversion:2];
        [tableauDesActions addObject:newActionEtranger1];

        ActionEtranger *newActionEtranger2 = [[ActionEtranger alloc] init];
        [newActionEtranger2 setPrixAchatAction:10.00];
        [newActionEtranger2 setPrixActuelAction:20.00];
        [newActionEtranger2 setNbActions:100];
        [newActionEtranger2 setTxConversion:5.00];
        [tableauDesActions addObject:newActionEtranger2];
        
        for (Action *a in tableauDesActions) {
            NSLog(@"Prix d'Achat %.2f, Prix Actuel %.2f, Qté, %u, Cout d'Achat %.2f, Valeur actuelle %.2f",
                  [a prixAchatAction], [a prixActuelAction], [a nbActions], [a coutAchatEnEuros], [a valeurActuelEnEuros]);
        }
        
        
    }
    return 0;
}