Amazon.com Widgets FracCalc: Fraction Calculator in the App Store
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2014, 08:11:29 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Fraction Calculator Available from the App Store
| | |-+ FracCalc: Fraction Calculator in the App Store
Pages: [1] Go Down
Print
Author Topic: FracCalc: Fraction Calculator in the App Store (Read 26722 times)
skochan
Administrator
Hero Member
*****
Posts: 3114







on: July 30, 2009, 01:34:10 PM

I decided to make the Fraction Calculator developed in Chapter 21 of the text available from the App Store.  It is available at no charge.   There are several enhancements, including a better UI design (see attached pic).  The complete XCode project is available for download from this URL.

Note that the zip contains the app with the bug fix (as noted later in this thread).

To get the app from the App Store: FracCalc


Cheers,

Steve Kochan

Last Edit: June 06, 2010, 10:12:27 PM by skochan Logged
anmldr
Jr. Member
**
Posts: 53






Reply #1 on: September 15, 2009, 07:49:13 PM

Just out of curiosity, do you have any more apps on the AppStore?

Linda
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #2 on: September 16, 2009, 10:02:22 AM

None right now!   Cool

Cheers,

Steve
Logged
cameronsloan
Newbie
*
Posts: 1


Email




Reply #3 on: December 06, 2009, 03:02:20 PM

EDIT *******
You may disregard the request below.  The next book I am reading (Cocoa Programming for Mac OS X - Hillegass) looks like it might teach me what I need to know.

Thanks again for a great book and a very helpfull web site.
********************************************

Hey Stephen,
These forums have been very helpful to me as I've been working my way through your book.

I just completed the calculator project and think it's very cool.  In fact, I'd like to make the same calculator for use on the Mac.

I've tried to do this on my own, but I've run into some issues.  When choosing the template for the project, I selected Application on the left and Cocoa Aplication on the right.  The problem I'm having is that I didn't have a xxxxViewContrller.h file and don't know what would take it's place in this application.

Could you please provide a rough outline of the steps that would be required?

Thanks.
Last Edit: December 06, 2009, 04:32:09 PM by cameronsloan Logged
Wrensation
Newbie
*
Posts: 1






Reply #4 on: December 10, 2009, 06:05:46 PM

I downloaded the source of the Fraction Calculator and compiled it on the iPhone Simulator and came across a problem. Whenever you type in 3/2 3/2 and then click plus, it says the answer is 3 when the answer is 1. I searched back through it and found out what the problem is. The processOp method looks like this:

 
Code: (Objective-C)
-(void) processOp: (char) theOp {
  NSString *opStr;
    op = theOp;

    switch (theOp) {
        case '+':  opStr = @" + "; break;
        case '-':  opStr = @" − "; break;
        case '*':  opStr = @" ";  break;
        case '/':  opStr = @" ";  break;
    }
 
    [self storeFracPart];
   
    // If it's a chain operation, e.g., 1/2 + 3/5 + 2/3
    // do the first operation and store that as the first operand
   
    if (firstOperand == NO) {
        [myCalculator performOperation: op];
        [displayString setString: 
            [myCalculator.accumulator convertToString]];
       
        myCalculator.operand1.numerator = myCalculator.accumulator.numerator;
        myCalculator.operand1.denominator = myCalculator.accumulator.denominator;
    }  // 1/2 + 3/4 = + 5/6 = ...
    else if ([displayString isEqualToString: @""]  == YES) {
        [displayString setString: 
                 [myCalculator.accumulator convertToString]];
        myCalculator.operand1.numerator = myCalculator.accumulator.numerator;
        myCalculator.operand1.denominator = myCalculator.accumulator.denominator;

    }
   
    firstOperand = NO;
    isNumerator = YES;
    [displayString appendString: opStr];
    [display setText: displayString];
}

Where it should look like this:
Code: (Objective-C)
-(void) processOp: (char) theOp {
NSString *opStr;
char oldOp = op;
[self storeFracPart];
op = theOp;
    switch (theOp) {
        case '+':  opStr = @" + "; break;
        case '-':  opStr = @" − "; break;
        case '*':  opStr = @" ";  break;
        case '/':  opStr = @" ";  break;
    }
    // If it's a chain operation, e.g., 1/2 + 3/5 + 2/3
    // do the first operation and store that as the first operand
if (firstOperand == NO) {
        [myCalculator performOperation: oldOp];
        [displayString setString: 
[myCalculator.accumulator convertToString]];
       
        myCalculator.operand1.numerator = myCalculator.accumulator.numerator;
        myCalculator.operand1.denominator = myCalculator.accumulator.denominator;
    }  // 1/2 + 3/4 = + 5/6 = ...
    else if ([displayString isEqualToString: @""]  == YES) {
        [displayString setString: 
[myCalculator.accumulator convertToString]];
        myCalculator.operand1.numerator = myCalculator.accumulator.numerator;
        myCalculator.operand1.denominator = myCalculator.accumulator.denominator;
    }
    firstOperand = NO;
    isNumerator = YES;
    [displayString appendString: opStr];
    [display setText: displayString];
}

If you can't see what I changed, I rearranged the top part of the method to include a "char oldOp" and set that to "op" before where you set "op to equal theOp", and the down below where the "if (firstOperand == NO)" statement, I changed the op to perform "oldOp" instead of "op" because the problem was that it was adding instead of dividing. You need to change that and then resubmit it to the app store.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #5 on: December 11, 2009, 10:40:10 AM

It's funny, because I stumbled across that same bug a couple of days ago and fixed it but never posted.

Thanks!    Grin

Cheers,

Steve Kochan
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.