Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 01, 2015, 05:57:32 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
|-+  Recent Posts
Pages: 1 2 [3] 4 5 ... 10

 21 
 on: February 17, 2015, 01:25:31 AM 
Started by slackie - Last post by slackie
i heve been make program so the result like this

values[0] = 197
values[1] = 0
values[2] = -101
values[3] = 547
values[4] = 0
values[5] = 350
values[6] = 0
values[7] = 0
values[8] = 0
values[9] = 35

this is the program

// working with array

#include <stdio.h>

int main (void)
{

   int values[10];
   int index;
   int i;   

   for ( i =0; i<10; ++i)
   values = 0;

   values[0] = 197;
   values[2] = -100;
   values[5] = 350;
   values[3] = values[0] + values[5];
   values[9] = values[5] / 10;
   --values[2];
   
   
   
   for ( index =0; index <10; ++index)
   
   printf("values[%i] = %i\n", index, values[index]);
   

   return 0;



}


but i corious why program in post 1 have result like that
can you explain
thank you
Smiley

 22 
 on: February 16, 2015, 10:28:02 PM 
Started by slackie - Last post by slackie
hello everbody, i am newbie so please help me

i have a little problem about array in program 7.1 on book programming in c third edition

this is the program

// working with array

#include <stdio.h>

int main (void)
{

   int values[10];
   int index;

   values[0] = 197;
   values[2] = -100;
   values[5] = 350;
   values[3] = values[0] + values[5];
   values[9] = values[5] / 10;
   --values[2];

   
   for ( index =0; index <10; ++index)
   printf("values[%i] = %i\n", index, values[index]);
   
   return 0;

}


the result  should be like this

values[0] = 197
values[1] = 0
values[2] = -101
values[3] = 547
values[4] = 0
values[5] = 350
values[6] = 0
values[7] = 0
values[8] = 0
values[9] = 35


but my result is different

when is use mingw the result is

values[0] = 197
values[1] = 3
values[2] = -101
values[3] = 547
values[4] = 4218880
values[5] = 350
values[6] = 4202350
values[7] = 4202256
values[8] = 0
values[9] = 35

when i use cygwin the result is

values[0] = 197
values[1] = 1629192174
values[2] = -101
values[3] = 547
values[4] = 1629192174
values[5] = 350
values[6] = 1627419952
values[7] = 47
values[8] = 2280836
values[9] = 35

and  in cygwin when i ask program to give number again the result diffrent with before
why my result is different?
i have been  give value to index like this
for ( index =0; index <10; ++index)
index = 0; ( in for)
why the program like i don't use array
it is like i use ++index in values[index]
can you explain that sir
may be i  wrong about purpose the program

thank you Smiley

 23 
 on: February 16, 2015, 03:43:32 PM 
Started by barrettlikespizza - Last post by barrettlikespizza
Brian,

Thank you once again for your help!  I rewrote a few things per your suggestion and it's running great now!

#import <Foundation/Foundation.h>

Code: (Objective-C)
//Interface Section

@interface TreasureMap: NSObject

-(void) print;
-(void) setXcoord: (int) x;
-(void) setYcoord: (int) y;
-(int) getXcoord;
-(int) getYcoord;


//Implementation Section

@end



@implementation TreasureMap

{
    int xCoord;
    int yCoord;
}

    -(void) print;
    
{
        NSLog (@"The treasure is located at %i longitude, %i latitude", xCoord, yCoord);
}

-(void) setXcoord: (int) x

{
    xCoord = x;
}

-(void) setYcoord: (int) y

{
    yCoord = y;
}

-(int) getXcoord
{
    return xCoord;
}

-(int) getYcoord

{
    return yCoord;
}

@end

// Program section

int main(int argc, const char * argv[]) {
    @autoreleasepool {
  
        TreasureMap *myTreasuremap = [[TreasureMap alloc] init];
        
        [myTreasuremap setXcoord: 55];
        [myTreasuremap setYcoord: 88];
        
        NSLog(@"I found the treasure map! It says the treasure is located at %i latitude %i longitude!", [myTreasuremap getXcoord], [myTreasuremap getYcoord]);

    }
    return 0;  
 }

 24 
 on: February 14, 2015, 08:15:19 AM 
Started by barrettlikespizza - Last post by BrianLawson
The problems that I see are that your declarations for setXcoord and setYcoord are not correct. They both need to have the input parameter specified, i.e.,
Code: (Objective-C)
(void) setXcoord: (int) x;
(void) setYcoord: (int) y;
Also, there is an extraneous [ before your NSLog statement at the end of the program. Remove that character and fix the declarations for your coordinate setters and you'll be in business.

 25 
 on: February 11, 2015, 05:59:23 PM 
Started by barrettlikespizza - Last post by barrettlikespizza
Hello!

Posting my answers to Chapter 3 exercises.

Something is wrong with question 7.

If anyone could take a moment to review this, I'd appreciate it!
 
1.) The invalid names are:
 
 Int - Because int is a reserved term, and also starts with a capital letter
 A$ - Dollar signs aren't allowed
 ReInitialize - Can't start with Caps
 Xx - Can't start with Caps
 
2.) @interface Fridge: Appliance

insertFood;
extractFood;
openDoor;
closeDoor;
lightOn;
 
3.)
 [fridge insertFood];
 [fridge extractFood];
 [fridge openDoor];
 [fridge closeDoor];
 [fridge lightOn];
 
 4.)
 car
 - accelerate
 - decelerate
 - refuel
 - wash
 
 boat
 - accelerate
 - decelerate
 - refuel
 - wash
 - deploySail
 - collapseSail
 
 motorcycle
 - accelerate
 - decelerate
 - refuel
 - wash
 - popWheelie
 
 Yes, there is overlap with accelerate, decelerate, refuel and wash.
 
 5.) Yes, I do see an advantage to being able to apply an action to an object that could be from one of several classes.
 
Here is the advantage: Regardless of what you're calling the object (Boat, Motorcycle, Car, etc.) if they're all from the "Vehicle" class, you can use the same set of methods for all three objects.
 
    If there were multiple class types, we would need to write multiple class definitions and methods. (I'm assuming that by "action" the book also means "method") in this question.
 
 6.) It seems that Object Oriented Programming has an advantage over procedural language in this example.
    In Procedural language, you have to write a new wash method for each vehicle that comes along.
    In Object Oriented programming, you simply write one wash method and apply it to the various vehicles you create. Only write one method as opposed to 3 or 4.
    This seems like too easy of a question. Am I missing something more complicated?
 
 7.) X coord, Y coord question:

Code: (Objective-C)
#import <Foundation/Foundation.h>

//Interface Section

@interface TreasureMap: NSObject

-(void) print;
-(void) setXcoord;
-(void) setYcoord;
-(int) getXcoord;
-(int) getYcoord;


//Implementation Section

@end



@implementation TreasureMap

{
    int xCoord;
    int yCoord;
}

    -(void) print;
   
{
        NSLog (@"The treasure is located at %i longitude, %i latitude", xCoord, yCoord);
}

-(void) setXcoord: (int) x

{
    xCoord = x;
}

-(void) setYcoord: (int) y

{
    yCoord = y;
}

-(int) getXcoord
{
    return xCoord;
}

-(int) getYcoord

{
    return yCoord;
}

@end

// Program section

int main(int argc, const char * argv[]) {
    @autoreleasepool {
   
        TreasureMap *myTreasuremap = [TreasureMap new];
       
        [myTreasuremap setXcoord: 55];
        [myTreasuremap setYcoord: 88];
       
        [NSLog(@"The treasure can be found at %i longitude, %i lattitude", [myTreasuremap getXcoord],[myTreasuremap getYcoord]);
       

    }
    return 0; 
 }

 26 
 on: February 11, 2015, 04:46:13 AM 
Started by timBob - Last post by timBob
This is my take on it. I used just code that's been covered in the book so far, rather than adding stuff from other sources.  The only addition is the 'exit (0)' added to the E commend to end the program-  I found this on the StackOverFlow forum, not sure if it's been covered in the book up to chapter 6.

Division method:-

-(void) divide:(double)value

{
  if (value != 0)
    accumulator /= value;
 
  else
    NSLog(@ "division by zero");
}





Program section:-

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

{
  @autoreleasepool
 
  {
    double value;
    char operator;
   
   
    Calculator *SimpleCalc = [[Calculator alloc] init];
   
 
   
do
  {
    NSLog(@ "type in your expression");
    scanf(" %lf  %c", &value, &operator);
   

       
      if (operator == '+')
        {
          [SimpleCalc add: value];
            NSLog(@ "= %lf", [SimpleCalc accumulator]);
        }
   
        else if (operator == '-')
        {
          [SimpleCalc subtract: value];
            NSLog(@ "= %lf", [SimpleCalc accumulator]);
        }
   
        else if (operator == '*')
        {
          [SimpleCalc multiply: value];
            NSLog(@ "= %lf", [SimpleCalc accumulator]);
        }
   
 
        else if (operator == '/')
        {
          [SimpleCalc divide: value];
            NSLog(@ "= %lf", [SimpleCalc accumulator]);
        }
     
        else if (operator == 'S')
        {
          [SimpleCalc setAccumulator: value];
            NSLog(@ "= %lf", [SimpleCalc accumulator]);
        }
   
        else if (operator == 'E')
        {
          NSLog(@ "End of calculations");
          exit(0);
        }

   
      else
        NSLog(@ " illegal operator");

  }


    while (true);
 
 
  }
    return 0;
}

 27 
 on: February 10, 2015, 01:47:08 AM 
Started by timBob - Last post by Mgaikjo
I will try to follow the example that has told me.

 28 
 on: February 10, 2015, 01:42:44 AM 
Started by anhkiet_1992 - Last post by Mgaikjo
It is a wonderful thing to do next.

 29 
 on: February 05, 2015, 01:42:23 PM 
Started by barrettlikespizza - Last post by BrianLawson
If you are writing your own class definitions you can change them however you please, only proper programming practices is what keeps one writing proper code.

If you are working in a production shop, odds are that someone else may be writing the classes and you don't have access to the .m files, only the header files for implementing your code that makes use of those classes.

 30 
 on: February 05, 2015, 11:35:50 AM 
Started by barrettlikespizza - Last post by barrettlikespizza
BrianLawson, thank you for answering my question so quickly!

I feel like I've mostly got it now.

But one thing I'm wondering about is this:

The whole idea of data encapsulation is to hide things from programmers.

But what would stop a programmer from simply editing the @implementation section?

Or is the author talking more about something like main.h where we can't see what's inside main's implementation section?

Pages: 1 2 [3] 4 5 ... 10


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.