first, design a candlestick class
1) Lowest price (can read and write (Get,set))
2) Maximum price (read/write (Get,set))
3) Average price (read-only (get))
1, KLine.h
#import <Foundation/Foundation.h>
@interface kline:nsobject{
@public
float _highprice;
float _lowprice;
float _avgprice;
}
-(void) Sethighprice: (float) heighprice;
-(float) gethighprice;
-(void) Setlowprice: (float) lowprice;
-(float) getlowprice;
-(float) getavgprice;
@end
2, KLINE.M
#import "KLine.h"
@implementation KLine
-(void) Sethighprice: (float) heighprice{
_highprice = Heighprice ;
_avgprice = (_lowprice + _highprice)/2;
}
-(float) gethighprice{
return _highprice;
}
-(void) Setlowprice: (float) lowprice{
_lowprice = lowprice;
_avgprice = (_lowprice + _highprice)/2;
}
-(float) getlowprice{
return _lowprice;
}
-(float) getavgprice{
//return (_lowprice + _highprice)/2;
return _avgprice;
}
@end
3, Main.h:
#import <Foundation/Foundation.h>
#import "KLine.h"
int main (int argc, const char * argv[])
{
@autoreleasepool {
KLine *kline = [KLine new];
[Kline sethighprice:30.0f];
[Kline setlowprice:20.0f];
float avg = [Kline Getavgprice];
NSLog (@ "avg =%.2f", avg);
}
return 0;
}