Commits

Roma Sokolov  committed 10660d0

discover id type

  • Participants
  • Parent commits dd91772

Comments (0)

Files changed (6)

File frac/Complex.h

+/* -*- mode: objc -*- */
+
+#import <Foundation/NSObject.h>
+
+@interface Complex: NSObject {
+  double real;
+  double imaginary;
+}
+
+-(Complex*) initWithReal: (double) r andImaginary: (double) i;
+-(void) print;
+-(void) setReal: (double) r;
+-(void) setReal: (double) r andImaginary: (double) i;
+-(void) setImaginary: (double) i;
+-(double) real;
+-(double) imaginary;
+
+@end

File frac/Complex.m

+#include <stdio.h>
+
+#import "Complex.h"
+
+@implementation Complex
+
+-(Complex*) initWithReal: (double) r andImaginary: (double) i {
+  self = [super init];
+
+  if (self) {
+    [self setReal: r andImaginary: i];
+  }
+
+  return self;
+}
+
+-(void) print {
+  printf("%f + %fi", real, imaginary);
+}
+
+-(void) setReal: (double) r {
+  real = r;
+}
+
+-(void) setReal: (double) r andImaginary: (double) i {
+  real = r;
+  imaginary = i;
+}
+
+-(void) setImaginary: (double) i {
+  imaginary = i;
+}
+
+-(double) real {
+  return real;
+}
+
+-(double) imaginary {
+  return imaginary;
+}
+
+@end

File frac/Fraction.h

+/* -*- mode: objc -*- */
+
 #import <Foundation/NSObject.h>
 
 @interface Fraction: NSObject {

File frac/Fraction.m

 
 @end
 
+

File frac/Makefile

 
 COMPILER := gcc
 
-SOURCES := Fraction.m $(PROJECT).m
+SOURCES := Fraction.m Complex.m $(PROJECT).m
 ALL_M :=$(filter %.m,$(SOURCES))
 
 ALL_D:=$(foreach s,$(ALL_M), $(basename $(notdir $(s))).d)
 #import <stdio.h>
 
 #import "Fraction.h"
+#import "Complex.h"
 
 
 int main() {
   Fraction *frac = [[Fraction alloc] init];
   Fraction *frac2 = [[Fraction alloc] init];
   Fraction *frac3 = [[Fraction alloc] initWithNumerator: 1 andDenominator: 6];
+  Complex *comp = [[Complex alloc] initWithReal: 10 andImaginary: 15];
+  id number;
 
   [frac setNumerator: 1];
   [frac setDenominator: 3];
-
   [frac2 setNumerator: 1 andDenominator: 5];
 
   printf("The fraction is: ");
   [frac3 print];
   printf("\n");
 
+  number = frac3;
+  printf("number as fraction is: ");
+  [number print];
+  printf("\n");
+
+  number = comp;
+  printf("number as complex is: ");
+  [number print];
+  printf("\n");
+
 
   [frac release];
   [frac2 release];
   [frac3 release];
+  [comp release];
 
   return 0;
 }