SlideShare uma empresa Scribd logo
1 de 16
Object-Oriented Programming Language
                           Chapter 4 : Data Types and Expressions


                                          Atit Patumvan
                          Faculty of Management and Information Sciences
                                        Naresuna University




Monday, February 20, 12
2



                                                                                     Contents


             •        Data Types and Constants

             •        Arithmetic Expressions

             •        Assignment Operators




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University              Object-Oriented Programming Language
Monday, February 20, 12
3



                                                              Data Type and Constant


            data_type identifier = value;
                  identifier

                                                                                     value

                                                                                      data_type
              int number = 25;                                                                 copy   25
                     number
                                                                                      25
                                                                                             int
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                     Object-Oriented Programming Language
Monday, February 20, 12
4



                                                           Data Types in Objective-C



                Type                                                                  Descriptions                Size

                 char                                            A character of the local character set       1 bytes

                   int                                                     An integer (whole numbers)         4 bytes

                 float                                                            Floating point number        4 bytes

                short                                                                A short integer          2 bytes

                 long                                                                A double short           4 bytes

            long long                                                                A double long            8 bytes

              double                                                             Double precision float        8 bytes

              BOOL

                   id                                                                  An object              4 bytes

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                        Object-Oriented Programming Language
Monday, February 20, 12
5



                                     Uses the basic Objective-C data types

Program 4.1
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, char *argv[]) {
04:! @autoreleasepool {
05:! ! int integerVar = 100;
06:! ! float floatingVar = 331.79;
07:! ! double doubleVar = 8.44e-11;
08:! ! char charVar = 'w';
09:! !
10:! ! NSLog(@"integerVar = %i", integerVar);
11:! ! NSLog(@"floatVar = %f", floatingVar);
12:! ! NSLog(@"doubleVar = %e", doubleVar);
13:! ! NSLog(@"doubleVar = %g", doubleVar);
14:! ! NSLog(@"charVar = %c", charVar);
15: 	 }




    integerVar = 100
    floatVar = 331.790009
    doubleVar = 8.440000e-11
    doubleVar = 8.44e-11
    charVar = w


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University   Object-Oriented Programming Language
Monday, February 20, 12
6



                                                                           Basic Data Types


                              Type                                                     Constant Example        NSLog chars
                              char                                                         a’, ‘n’                   %c
                      short int                                                                -              %hi, %hx, %ho
        unsigned short int                                                                     -              %hu, %hx, %ho
                                int                                                  12, -97, 0xFFE0, 0177      %i, %x, %o
                  unsigned int                                                         12u, 100U, 0xFFu         %u, %x, %o
                        long int                                                     12L, -2001l, 0xffffL     %li, %lx, %lo
          unsigned long int                                                          12UL, 100ul, 0xffeeUL    %lu, %lx, %lo
                long long int                                                         0xe5e5e5e5LL, 500ll    %lli, %llx, %llo
        unsigned long long                                                             12ull, 0xffeeULL        %llu, % llx,
                int
              float                                                       12.43f, 3.1e-5f, 0x1.5p10,               %llo
                                                                                                              %f, %e, %g, %a
                           double                                                   0x1p-1
                                                                            12.34, 3.1e-5, 0x.1p3             %f, %e, %g, %a
                   long double                                                          12.34L, 3.1e-5l       %Lf, %Le, %Lg
                                 id                                                           nil                     %p
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                Object-Oriented Programming Language
Monday, February 20, 12
7



                                                                 Arithmetic Expression

Program 4.3
05:
06:             int      a = 2;                                                      a   -   b   =   98
07:!      !     int      b = 2;                                                      b   *   c   =   50
08:!      !     int      c = 25;                                                     a   /   c   =   4
09:!      !     int      d = 4;                                                      a   +   b   *   c = 150
10:!      !     int      result;                                                     a   *   b   +   c * d = 300
11:!      !
12:!      ! result = a - b;!// subtraction
13:!      ! NSLog(@"a - b = %i", result);
14:
15:!      !     result = b * c;!// multiplication
16:!      !     NSLog(@"b * c = %i", result);
17:!      !
18:!      !     result = a / c;!// division
19:!      !     NSLog(@"a / c = %i", result);
20:
21:!      ! result = a + b * c;! // precedence
22:!      ! NSLog(@"a + b * c = %i", result);
23:!      !
24:!      ! NSLog(@"a * b + c * d = %i", a * b + c * d);
25:!




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                 Object-Oriented Programming Language
Monday, February 20, 12
8



                        Integer Arithmetic and Unary Minus Operator

Program 4.3
05:
06:!        int a = 25;
07:!      ! int b = 2;
08:!      ! float c = 25.0;
09:!      ! float d = 2.0;
10:!      !
11:!      ! NSLog(@"6 + a / 5                             * b = %i", 6 + a / 5 * b);
12:!      ! NSLog(@"a / b * b                             = %i", a / b * b);
13:!      ! NSLog(@"c / d * d                             = %f", c / d * d);
14:!      ! NSLog(@"-a = %i",                             -a);
15:!




    6 + a / 5 * b = 16
    a / b * b = 24
    c / d * d = 25.000000
    -a = -25




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University     Object-Oriented Programming Language
Monday, February 20, 12
9



                                                                 The Modulus Operator

Program 4.4
05:
06:!         int a = 25, b = 5, c = 10, d =7;
07:!
08:!         NSLog(@"a             %% b = %i",                 a % b);
09:!         NSLog(@"a             %% c = %i",                 a % c);
10:!         NSLog(@"a             %% d = %i",                 a % d);
11:!         NSLog(@"a             / d * d + a                 %% d = %i", a / d * d + a % d);
12:!


    a    %   b    =    0
    a    %   c    =    5
    a    %   d    =    4
    a    /   d    *    d + a % d = 25




                                                                a /d * d+ a % d = ((a / d) * d)+(a % d)


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University               Object-Oriented Programming Language
Monday, February 20, 12
10



                                    Integer and Floating-Point Conversion

Program 4.5
05:
06:!      float f1 = 123.125, f2;
07:!      int i1, i2 = -150;
08:!
09:!      i1 = f1; // floating to integer convision
10:!      NSLog(@"%f assigned to an int produces %i", f1, i1);
11:!
12:!      f1 = i2; // integer to floating convision
13:!      NSLog(@"%i assigned to a float produces %f", i2, f1);
14:!
15:!      f1 = i2 / 100; // integer divided by integer
16:!      NSLog(@"%i divided by 100 produces %f", i2, f1);
17:!
18:!      f2 = i2 /100.0; // integer divided by float
19:!      NSLog(@"%i divided by 100.0 produce %f", i2, f2);
20:!
21:!      f2 = (float) i2 / 100; // type cast operator
22:!      NSLog(@"(float) %i divided by 100 produces %f", i2, f2);

                                                                                     123.125000 assigned to an int produces 123
                                                                                     -150 assigned to a float produces -150.000000
                                                                                     -150 divided by 100 produces -1.000000
                                                                                     -150 divided by 100.0 produce -1.500000
                                                                                     (float) -150 divided by 100 produces -1.500000
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                   Object-Oriented Programming Language
Monday, February 20, 12
11



                                                              The Type Case Operator


                 int i2 = 25;
                 float f2 = (float) i2 / 5; // type cast operator
                 int s1 = (int) 29.55 + (int) 21.99;
                 int s2 = 29 + 21;
                 float f3 = (float) 6 / (float) 4
                 float f4 = (float) 6 / 4
                 id myNumber;
                 Fraction * myFraction;
                 myFraction = (Fraction *) myNumber;
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University     Object-Oriented Programming Language
Monday, February 20, 12
12



                                                                   Assignment Operator




                 count += 10;
                 count = count +10;

                 counter -= 5;
                 counter = counter - 5;

                 a /= b + c;
                 a = a / (b + c);

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University       Object-Oriented Programming Language
Monday, February 20, 12
13



                                          Increment and Decrement Operator




                 count++;
                 count = count + 1;

                 counter--;
                 counter = counter - 1;

                 a /= b + c;
                 a = a / (b + c);

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University   Object-Oriented Programming Language
Monday, February 20, 12
14



                                                                             Desk Calculator

Program 4.6
48:
49:!      int main(int argc, char *argv[]) {
50:!      ! @autoreleasepool {
51:!      ! ! Calculator * deskCalc = [[Calculator alloc] init];
52:!      ! ! [deskCalc setAccumulator: 100.0];
53:!      ! !
54:!      ! ! [deskCalc add: 200.];
55:!      ! ! [deskCalc divide: 15.0];
56:!      ! ! [deskCalc subtract: 10.0];
57:!      ! ! [deskCalc multiply: 5];                                                                  Calculator
58:!      ! !
59:!      ! ! NSLog(@"The result is % g", [deskCalc accumulator]);
60:!      ! !                                                                                  accumulator:double
61:!      ! ! [deskCalc release];
62:!      ! }
63:!      }                                                                                    setAccumulator(double):void
64:!                                                                                           clear:void
                                                                                               accumulator:double
                                                                                               add(double):void
  The result is                     50                                                         subtract(double):void
                                                                                               multiply(double):void
                                                                                               divide(double):void

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                        Object-Oriented Programming Language
Monday, February 20, 12
15



                                           Calculator Class: Interface Section

Program 4.6
02:
03:      @interface Calculator: NSObject
04:      {
05:!       double accumulator;
06:      }
07:
08:      // accumulator methods
09:      -(void) setAccumulator: (double) value;
10:      -(void) clear;
11:      -(double) accumulator;                                                              Calculator
12:
13:      // arithmetic methods
14:      -(void) add: (double) value;                                                accumulator:double
15:      -(void) subtract: (double) value;
16:      -(void) multiply: (double) value;
17:      -(void) divide: (double) value;                                             setAccumulator(double):void
18:      @end!                                                                       clear:void
                                                                                     accumulator:double
                                                                                     add(double):void
                                                                                     subtract(double):void
                                                                                     multiply(double):void
                                                                                     divide(double):void

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University              Object-Oriented Programming Language
Monday, February 20, 12
16



                              Calculator Class: Implementation Section

Program 4.6
 20:      @implementation Calculator
 21:
 22:      -(void) setAccumulator: (double) value{
 23:      ! accumulator = value;
 24:      }
 25:      -(void) clear{
 26:      ! accumulator = 0;
 27:      }
 28:      -(double) accumulator{
 29:      ! return accumulator;                                                              Calculator
 30:      }
 31:
 32:      -(void) add: (double) value{                                               accumulator:double
 33:      ! accumulator += value;
 34:      }
 35:      -(void) subtract: (double) value{                                          setAccumulator(double):void
 36:      ! accumulator -= value;                                                    clear:void
 37:      }
 38:      -(void) multiply: (double) value{                                          accumulator:double
 39:      ! accumulator *= value;                                                    add(double):void
 40:      }                                                                          subtract(double):void
 41:      -(void) divide: (double) value{
 42:      ! accumulator /= value;
                                                                                     multiply(double):void
 43:      }                                                                          divide(double):void
 44:      @end!
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University               Object-Oriented Programming Language
Monday, February 20, 12

Mais conteúdo relacionado

Mais procurados

On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesJose E. Rivera
 
Producing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkProducing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkDaniele Gianni
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureHoneyChintal
 
Extractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language ModelExtractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language Modelgerogepatton
 
Event-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesEvent-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesIstvan Rath
 
turecko-150426_pse_01
turecko-150426_pse_01turecko-150426_pse_01
turecko-150426_pse_01Peter Fabo
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and AlgorithmsPierre Vigneras
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODEL
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODELEXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODEL
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODELijaia
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handlingRai University
 
IRJET - Speech to Speech Translation using Encoder Decoder Architecture
IRJET -  	  Speech to Speech Translation using Encoder Decoder ArchitectureIRJET -  	  Speech to Speech Translation using Encoder Decoder Architecture
IRJET - Speech to Speech Translation using Encoder Decoder ArchitectureIRJET Journal
 
ENSEMBLE MODEL FOR CHUNKING
ENSEMBLE MODEL FOR CHUNKINGENSEMBLE MODEL FOR CHUNKING
ENSEMBLE MODEL FOR CHUNKINGijasuc
 
IRJET - Analysis of Paraphrase Detection using NLP Techniques
IRJET - Analysis of Paraphrase Detection using NLP TechniquesIRJET - Analysis of Paraphrase Detection using NLP Techniques
IRJET - Analysis of Paraphrase Detection using NLP TechniquesIRJET Journal
 
Dynamic framed slotted aloha algorithms using fast tag estimation
Dynamic framed slotted aloha algorithms using fast tag estimationDynamic framed slotted aloha algorithms using fast tag estimation
Dynamic framed slotted aloha algorithms using fast tag estimationambitlick
 

Mais procurados (20)

Review_Cibe Sridharan
Review_Cibe SridharanReview_Cibe Sridharan
Review_Cibe Sridharan
 
On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling Languages
 
Producing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkProducing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based Framework
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structure
 
Extractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language ModelExtractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language Model
 
Event-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesEvent-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling Languages
 
turecko-150426_pse_01
turecko-150426_pse_01turecko-150426_pse_01
turecko-150426_pse_01
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Unit 8
Unit 8Unit 8
Unit 8
 
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODEL
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODELEXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODEL
EXTRACTIVE SUMMARIZATION WITH VERY DEEP PRETRAINED LANGUAGE MODEL
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
 
IRJET - Speech to Speech Translation using Encoder Decoder Architecture
IRJET -  	  Speech to Speech Translation using Encoder Decoder ArchitectureIRJET -  	  Speech to Speech Translation using Encoder Decoder Architecture
IRJET - Speech to Speech Translation using Encoder Decoder Architecture
 
ENSEMBLE MODEL FOR CHUNKING
ENSEMBLE MODEL FOR CHUNKINGENSEMBLE MODEL FOR CHUNKING
ENSEMBLE MODEL FOR CHUNKING
 
IRJET - Analysis of Paraphrase Detection using NLP Techniques
IRJET - Analysis of Paraphrase Detection using NLP TechniquesIRJET - Analysis of Paraphrase Detection using NLP Techniques
IRJET - Analysis of Paraphrase Detection using NLP Techniques
 
Dynamic framed slotted aloha algorithms using fast tag estimation
Dynamic framed slotted aloha algorithms using fast tag estimationDynamic framed slotted aloha algorithms using fast tag estimation
Dynamic framed slotted aloha algorithms using fast tag estimation
 
313 318
313 318313 318
313 318
 

Semelhante a OOP Chapter 4: Data Type and Expressions

Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESRushikesh Kolhe
 
trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptxTapaswini14
 
Python for data science
Python for data sciencePython for data science
Python for data sciencebotsplash.com
 
Computer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListComputer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListAtit Patumvan
 
Data Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxData Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxtheodorelove43763
 
employee turnover prediction document.docx
employee turnover prediction document.docxemployee turnover prediction document.docx
employee turnover prediction document.docxrohithprabhas1
 
Array programming with Numpy
Array programming with NumpyArray programming with Numpy
Array programming with Numpymustafa sarac
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & StringsAbhinav Porwal
 
OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping Atit Patumvan
 
Introduction of data science
Introduction of data scienceIntroduction of data science
Introduction of data scienceTanujaSomvanshi1
 
Introduction to Python Objects and Strings
Introduction to Python Objects and StringsIntroduction to Python Objects and Strings
Introduction to Python Objects and StringsSangeetha S
 

Semelhante a OOP Chapter 4: Data Type and Expressions (17)

Data Science Using Python.pptx
Data Science Using Python.pptxData Science Using Python.pptx
Data Science Using Python.pptx
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTES
 
trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptx
 
fds u1.docx
fds u1.docxfds u1.docx
fds u1.docx
 
Python for data science
Python for data sciencePython for data science
Python for data science
 
Computer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListComputer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayList
 
Data Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxData Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docx
 
employee turnover prediction document.docx
employee turnover prediction document.docxemployee turnover prediction document.docx
employee turnover prediction document.docx
 
D04422730
D04422730D04422730
D04422730
 
DataScience_RoadMap_2023.pdf
DataScience_RoadMap_2023.pdfDataScience_RoadMap_2023.pdf
DataScience_RoadMap_2023.pdf
 
Array programming with Numpy
Array programming with NumpyArray programming with Numpy
Array programming with Numpy
 
Data types.pdf
Data types.pdfData types.pdf
Data types.pdf
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & Strings
 
OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping
 
Introduction of data science
Introduction of data scienceIntroduction of data science
Introduction of data science
 
Introduction to Python Objects and Strings
Introduction to Python Objects and StringsIntroduction to Python Objects and Strings
Introduction to Python Objects and Strings
 
APS PGT Computer Science SylIabus
APS PGT Computer Science SylIabusAPS PGT Computer Science SylIabus
APS PGT Computer Science SylIabus
 

Mais de Atit Patumvan

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agricultureAtit Patumvan
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)Atit Patumvan
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556Atit Patumvan
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationAtit Patumvan
 
Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6Atit Patumvan
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsAtit Patumvan
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Atit Patumvan
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2Atit Patumvan
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1Atit Patumvan
 

Mais de Atit Patumvan (20)

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agriculture
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computation
 
Media literacy
Media literacyMedia literacy
Media literacy
 
Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : Methods
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1
 

Último

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 

Último (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 

OOP Chapter 4: Data Type and Expressions

  • 1. Object-Oriented Programming Language Chapter 4 : Data Types and Expressions Atit Patumvan Faculty of Management and Information Sciences Naresuna University Monday, February 20, 12
  • 2. 2 Contents • Data Types and Constants • Arithmetic Expressions • Assignment Operators Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 3. 3 Data Type and Constant data_type identifier = value; identifier value data_type int number = 25; copy 25 number 25 int Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 4. 4 Data Types in Objective-C Type Descriptions Size char A character of the local character set 1 bytes int An integer (whole numbers) 4 bytes float Floating point number 4 bytes short A short integer 2 bytes long A double short 4 bytes long long A double long 8 bytes double Double precision float 8 bytes BOOL id An object 4 bytes Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 5. 5 Uses the basic Objective-C data types Program 4.1 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, char *argv[]) { 04:! @autoreleasepool { 05:! ! int integerVar = 100; 06:! ! float floatingVar = 331.79; 07:! ! double doubleVar = 8.44e-11; 08:! ! char charVar = 'w'; 09:! ! 10:! ! NSLog(@"integerVar = %i", integerVar); 11:! ! NSLog(@"floatVar = %f", floatingVar); 12:! ! NSLog(@"doubleVar = %e", doubleVar); 13:! ! NSLog(@"doubleVar = %g", doubleVar); 14:! ! NSLog(@"charVar = %c", charVar); 15: } integerVar = 100 floatVar = 331.790009 doubleVar = 8.440000e-11 doubleVar = 8.44e-11 charVar = w Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 6. 6 Basic Data Types Type Constant Example NSLog chars char a’, ‘n’ %c short int - %hi, %hx, %ho unsigned short int - %hu, %hx, %ho int 12, -97, 0xFFE0, 0177 %i, %x, %o unsigned int 12u, 100U, 0xFFu %u, %x, %o long int 12L, -2001l, 0xffffL %li, %lx, %lo unsigned long int 12UL, 100ul, 0xffeeUL %lu, %lx, %lo long long int 0xe5e5e5e5LL, 500ll %lli, %llx, %llo unsigned long long 12ull, 0xffeeULL %llu, % llx, int float 12.43f, 3.1e-5f, 0x1.5p10, %llo %f, %e, %g, %a double 0x1p-1 12.34, 3.1e-5, 0x.1p3 %f, %e, %g, %a long double 12.34L, 3.1e-5l %Lf, %Le, %Lg id nil %p Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 7. 7 Arithmetic Expression Program 4.3 05: 06: int a = 2; a - b = 98 07:! ! int b = 2; b * c = 50 08:! ! int c = 25; a / c = 4 09:! ! int d = 4; a + b * c = 150 10:! ! int result; a * b + c * d = 300 11:! ! 12:! ! result = a - b;!// subtraction 13:! ! NSLog(@"a - b = %i", result); 14: 15:! ! result = b * c;!// multiplication 16:! ! NSLog(@"b * c = %i", result); 17:! ! 18:! ! result = a / c;!// division 19:! ! NSLog(@"a / c = %i", result); 20: 21:! ! result = a + b * c;! // precedence 22:! ! NSLog(@"a + b * c = %i", result); 23:! ! 24:! ! NSLog(@"a * b + c * d = %i", a * b + c * d); 25:! Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 8. 8 Integer Arithmetic and Unary Minus Operator Program 4.3 05: 06:! int a = 25; 07:! ! int b = 2; 08:! ! float c = 25.0; 09:! ! float d = 2.0; 10:! ! 11:! ! NSLog(@"6 + a / 5 * b = %i", 6 + a / 5 * b); 12:! ! NSLog(@"a / b * b = %i", a / b * b); 13:! ! NSLog(@"c / d * d = %f", c / d * d); 14:! ! NSLog(@"-a = %i", -a); 15:! 6 + a / 5 * b = 16 a / b * b = 24 c / d * d = 25.000000 -a = -25 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 9. 9 The Modulus Operator Program 4.4 05: 06:! int a = 25, b = 5, c = 10, d =7; 07:! 08:! NSLog(@"a %% b = %i", a % b); 09:! NSLog(@"a %% c = %i", a % c); 10:! NSLog(@"a %% d = %i", a % d); 11:! NSLog(@"a / d * d + a %% d = %i", a / d * d + a % d); 12:! a % b = 0 a % c = 5 a % d = 4 a / d * d + a % d = 25 a /d * d+ a % d = ((a / d) * d)+(a % d) Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 10. 10 Integer and Floating-Point Conversion Program 4.5 05: 06:! float f1 = 123.125, f2; 07:! int i1, i2 = -150; 08:! 09:! i1 = f1; // floating to integer convision 10:! NSLog(@"%f assigned to an int produces %i", f1, i1); 11:! 12:! f1 = i2; // integer to floating convision 13:! NSLog(@"%i assigned to a float produces %f", i2, f1); 14:! 15:! f1 = i2 / 100; // integer divided by integer 16:! NSLog(@"%i divided by 100 produces %f", i2, f1); 17:! 18:! f2 = i2 /100.0; // integer divided by float 19:! NSLog(@"%i divided by 100.0 produce %f", i2, f2); 20:! 21:! f2 = (float) i2 / 100; // type cast operator 22:! NSLog(@"(float) %i divided by 100 produces %f", i2, f2); 123.125000 assigned to an int produces 123 -150 assigned to a float produces -150.000000 -150 divided by 100 produces -1.000000 -150 divided by 100.0 produce -1.500000 (float) -150 divided by 100 produces -1.500000 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 11. 11 The Type Case Operator int i2 = 25; float f2 = (float) i2 / 5; // type cast operator int s1 = (int) 29.55 + (int) 21.99; int s2 = 29 + 21; float f3 = (float) 6 / (float) 4 float f4 = (float) 6 / 4 id myNumber; Fraction * myFraction; myFraction = (Fraction *) myNumber; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 12. 12 Assignment Operator count += 10; count = count +10; counter -= 5; counter = counter - 5; a /= b + c; a = a / (b + c); Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 13. 13 Increment and Decrement Operator count++; count = count + 1; counter--; counter = counter - 1; a /= b + c; a = a / (b + c); Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 14. 14 Desk Calculator Program 4.6 48: 49:! int main(int argc, char *argv[]) { 50:! ! @autoreleasepool { 51:! ! ! Calculator * deskCalc = [[Calculator alloc] init]; 52:! ! ! [deskCalc setAccumulator: 100.0]; 53:! ! ! 54:! ! ! [deskCalc add: 200.]; 55:! ! ! [deskCalc divide: 15.0]; 56:! ! ! [deskCalc subtract: 10.0]; 57:! ! ! [deskCalc multiply: 5]; Calculator 58:! ! ! 59:! ! ! NSLog(@"The result is % g", [deskCalc accumulator]); 60:! ! ! accumulator:double 61:! ! ! [deskCalc release]; 62:! ! } 63:! } setAccumulator(double):void 64:! clear:void accumulator:double add(double):void The result is 50 subtract(double):void multiply(double):void divide(double):void Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 15. 15 Calculator Class: Interface Section Program 4.6 02: 03: @interface Calculator: NSObject 04: { 05:! double accumulator; 06: } 07: 08: // accumulator methods 09: -(void) setAccumulator: (double) value; 10: -(void) clear; 11: -(double) accumulator; Calculator 12: 13: // arithmetic methods 14: -(void) add: (double) value; accumulator:double 15: -(void) subtract: (double) value; 16: -(void) multiply: (double) value; 17: -(void) divide: (double) value; setAccumulator(double):void 18: @end! clear:void accumulator:double add(double):void subtract(double):void multiply(double):void divide(double):void Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12
  • 16. 16 Calculator Class: Implementation Section Program 4.6 20: @implementation Calculator 21: 22: -(void) setAccumulator: (double) value{ 23: ! accumulator = value; 24: } 25: -(void) clear{ 26: ! accumulator = 0; 27: } 28: -(double) accumulator{ 29: ! return accumulator; Calculator 30: } 31: 32: -(void) add: (double) value{ accumulator:double 33: ! accumulator += value; 34: } 35: -(void) subtract: (double) value{ setAccumulator(double):void 36: ! accumulator -= value; clear:void 37: } 38: -(void) multiply: (double) value{ accumulator:double 39: ! accumulator *= value; add(double):void 40: } subtract(double):void 41: -(void) divide: (double) value{ 42: ! accumulator /= value; multiply(double):void 43: } divide(double):void 44: @end! Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, February 20, 12