码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-C 程序设计(第六版)第四章习题答案

时间:2014-09-17 23:04:32      阅读:410      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   2014   div   sp   问题   

1.   非法常量

      0x10.5    0X0G1    98.7U    17777s    0996    1.2Fe-7    15,000    .

2.

     //只需要列出表达式就可以
        
        int F = 27;       //设置F为华氏温度,赋值 27
        float C ;           //设置C为摄氏温度,类型为浮点类型
        
        C = (F-32)/1.8;
        NSLog(@"%.1f",C);     // %.1f 保留一位小数就可以

     //输出结果
       2014-09-17 14:58:48.259 prog1[6058:303] -2.8
       Program ended with exit code: 0

3.    输出结果为 d .

4.    

        float x = 2.55 ,  result ;
        
        result = 3 * (x * x * x) - 5 * (x * x) + 6 ;
        
        NSLog(@"result is %f",result);

       //结果如下
      2014-09-17 15:11:11.064 prog1[6196:303] result is 23.231621

5.

        //不知道这道题考的是什么 列出表达式过了得了

        double result;
        
        result = (3.31e-8 + 2.01e-7) / (7.16e-6 + 2.01e-8);
        
        NSLog(@"result is %e",result);
        
        //输出结果
        2014-09-17 15:29:31.547 prog1[6274:303] result is 3.260400e-02
        Program ended with exit code: 0

6.

//-------------interface部分-----------

@interface Complex : NSObject

- (void) setReal: (double) a;            //设置实数
- (void) setImaginary: (double) b;    //设置虚数
- (void) print;                                 //打印结果
- (double) real;
- (double) imaginary;

@end

//--------------implementation部分----------------

@implementation Complex
{
    double real;
    double imaginary;
}

- (void) setReal: (double) a
{
    real = a;
}

- (void) setImaginary: (double) b
{
    imaginary = b;
}

- (void) print
{
    NSLog(@"The complex is %.f + %.fi", real, imaginary);
}

- (double) real
{
    return real;
}

- (double) imaginary
{
    return imaginary;
}


@end


//----------------program部分-------------

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

    @autoreleasepool {

        Complex * newComplex = [[Complex alloc]init];
        
        [newComplex setReal:11];
        [newComplex setImaginary:22];

//下面两个方法都可以 ,分别测试 print方法和 real,imaginary方法;(应题目要求) [newComplex print];

  //      NSLog(@"The complex is %.f + %.fi",[newComplex real],[newComplex imaginary]);

       
    }
    return 0;
}

//结果如下
   2014-09-17 17:27:59.830 prog1[6678:303] The complex is 11 + 22i
   Program ended with exit code: 0

7.

手机出问题了  弄手机先

 

Objective-C 程序设计(第六版)第四章习题答案

标签:style   blog   color   io   ar   2014   div   sp   问题   

原文地址:http://www.cnblogs.com/MingMing-King/p/3978113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!