Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:47:52+00:00 2026-06-06T16:47:52+00:00

Why it says that numerator and denominator in the category MathOps is undeclared variable

  • 0

Why it says that numerator and denominator in the category MathOps is undeclared variable ?

It is in the Chapter 11 and the Program 11.1

Can’t understand why it doesn’t work, because it is the same code as in the book without any mistakes.

Please help

Code:

    #import <Foundation/Foundation.h>  
#import "complex.h"  
#import "Fraction.h"  
#import "XYPoint.h"  

@interface Fraction (MathOps)  
-(Fraction *)add:(Fraction *) f;  
-(Fraction *)mul:(Fraction *) f;  
-(Fraction *)sub:(Fraction *) f;  
-(Fraction *)div:(Fraction *) f;  

@end  

@implementation Fraction (MathOps)  
-(Fraction *)add:(Fraction *) f  
{  
    Fraction *result = [[Fraction alloc]init];  

    result.numerator = (numerator * f.denominator)+(denominator * f.numerator);   

// numerator and denominator: Using undeclared variables.  

    result.denominator = denominator * f.denominator;  
}  
-(Fraction *)mul:(Fraction *) f  
{  
    Fraction *result = [[Fraction alloc]init];  
    result.numerator = numerator * f.numerator;  
    result.denominator = denominator * f.denominator;  

    // numerator and denominator: Using undeclared variables.  
}  
-(Fraction *)sub:(Fraction *) f {}  
-(Fraction *)div:(Fraction *) f {}  
@end  

typedef Fraction *FractionObj;  
int main (int argc, const char * argv[])  
{  

    @autoreleasepool {  
        complex *imaginary= [[complex alloc]init];  
        complex *real = [[complex alloc]init];  
        complex *results;  

        [real setReal:1];  
        [real setImaginary:2];  
        [real print];  

        [imaginary setReal:2];  
        [imaginary setImaginary:1];  
        [imaginary print];  

        results = [real add: imaginary];  
        [results print];  
        NSLog(@"FRACTIONS!");  
        Fraction *a = [[Fraction alloc]init];  
        Fraction *b = [[Fraction alloc]init];  
        id resultFraction;  

        [a setTo:20 over:3];  
        [b setTo:1 over:3];  
        [b minusSign];  
        [a minusSign];  

        id ab = a;  
        id ba = b;  
        [ab print: 0];  
        NSLog(@"-");  
        [ba print: 0];  
        NSLog(@"=");  
        resultFraction = [ab multiplyN: ba];  
        [resultFraction print: 1];  

      XYPoint *xy = [[XYPoint alloc]init];  

        [xy setX:100 andY:110];  
        [xy print];  

        NSLog(@"VERIFYING \n \n \n");  
        Fraction *fraction = [[Fraction alloc]init];  
        complex *Complex = [[complex alloc]init];  
        id number = [[complex alloc]init];  

        if([fraction isMemberOfClass: [complex class]])  
            NSLog(@"Fraction is member of class complex");  
        if([Complex isMemberOfClass: [NSObject class]])  
            NSLog(@"complex is member of class NSObject");  
        if([Complex isKindOfClass: [NSObject class]])  
            NSLog(@"complex is kind of class NSObject");  
        if([fraction isKindOfClass: [Fraction class]])  
            NSLog(@"Fraction is kind of class Fraction");  
        if([fraction respondsToSelector: @selector(print)])  
           NSLog(@"Fraction respond to selector print");  
        if([Complex respondsToSelector: @selector(print)])  
           NSLog(@"Complex responds to print");  
        if([Fraction instancesRespondToSelector: @selector(print)])  
           NSLog(@"Fraction's instances respond to print");  
        if([number respondsToSelector: @selector (print)])  
           NSLog(@"number responds to print");  
        if([number isKindOfClass: [complex class]])  
           NSLog(@"number is kind of class complex");  
        if([[number class] respondsToSelector:@selector (alloc)])  
           NSLog(@"Number class responds to alloc");  

        if([a counter]!=1){ NSLog(@"%i times was invoked method multiplyN", a.counter); }  
        else { NSLog(@"Only %i time was invoked method multiplyN", a.counter);}  

        typedef enum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday} Day;  

    }  

    return 0;  
}  

Fraction.h:

    @interface Fraction : NSObject
@property int numerator, denominator, counter;

//methods
@end

Fraction.m

@implementation
@synthesize numerator, denominator, counter;

//methods

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:47:54+00:00Added an answer on June 6, 2026 at 4:47 pm

    Try adding a self. prefix to your code:

    result.numerator = (self.numerator * f.denominator)+(self.denominator * f.numerator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This article says that Emacs has redo because you can reverse direction while undoing,
Haskell 98 specification says that the entry point of a program, namely, function main
Here it says that I can get width (of columns I guess) but only
w3schools says that exceptions can be strings, integers, booleans, or objects, but the example
People says that libraries shouldn't have configuration files. I can't pass arguments to my
Wikipedia says that BlueGriffon can create and edit pages in accordance to HTML 4,
I understand that the standard says that the size of a long integer is
MSDN says that the function SetDllDirectory() can be used to insert a directory into
The documentation says that camel-spring-ws(v2.7.1) officially supports spring-ws 1.5.9, but doesn't mention spring-ws 2.0.2.RELEASE.
My buddy says that he tries to program with as little if/else statements as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.