Object-c 学习之路一(Hello world)
来源:互联网 发布:3d美工面试题 编辑:程序博客网 时间:2024/05/16 19:03
本人从今天开始学习oc 了心里灰常高兴,写了个hello world 留作纪念。
#import <Foundation/Foundation.h>@interface Rectangle : NSObject{ int width; int height;}-(void) setWidth:(int) w setGeight:(int) h;-(int) gePerimeter;-(int) getArea;@end
#import "Rectangle.h"@implementation Rectangle-(void) setWidth:(int) w setGeight:(int) h{ width=w; height=h;}-(int) gePerimeter{ return (width+height)*2;}-(int) getArea{ return width*height;}@end
Square 类继承Rectangle类
#import "Rectangle.h"@interface Square : Rectangle-(void) setSide:(int) w;-(int) side;@end
#import "Square.h"@implementation Square:Rectangle-(void) setSide:(int)w{ [self setWidth:w setGeight:w];}-(int) side{ return width;}-(int) getArea{ return [self side]*[self side];}@end主文件:
//// main.m// OcStart//// Created by WildCat on 13-3-25.// Copyright (c) 2013年 wildcat. All rights reserved.//#import <Foundation/Foundation.h>#import "Person.h"#import "Rectangle.h"#import "Square.h"int main(int argc, const char * argv[]){ @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); NSLog(@"李兴乐你好!!"); //定义一个Person类 Person * p=[[Person alloc] init]; [p setStr:@"李兴乐"]; [p myPrint]; //定义一个Rectangle类对象 Rectangle *r=[[Rectangle alloc] init]; [r setWidth:3 setGeight:4]; int area=[r getArea]; int perimeter=[r gePerimeter]; NSLog(@"The Area is:%d ,the parimeter is %d",area,perimeter); //定义一个Square实例对象 Square *s=[[Square alloc] init]; //键盘输入正方型的边长 NSLog(@"请输入正方形的边长"); int number; scanf("%i",&number); //设置边长 [s setSide:number]; int side=[s side]; int areas=[s getArea]; int perimeters=[s gePerimeter]; NSLog(@"The square's side is :%d ,the area is : %d ,the primeter is : %d",side,areas,perimeters); NSString *hello=@"sdfgdsf"; //转换为大写 hello=[hello uppercaseString]; NSLog(hello); //调用字符串的求长度方法 NSLog(@"The String length is : %ld",[hello length]); } return 0;}
- Object-c 学习之路一(Hello world)
- Object-C 之 Hello World
- object-c之从"Hello World"开始(object-c)
- object—c学习笔记(一)-----创建hello world
- Objective-C学习笔记(一):OC之Hello World!
- Objective-C 学习笔记(一)hello world和基础
- 快速学习C语言一: Hello World
- C语言学习一hello world程序
- linux下C编程(一)之 hello world
- qt学习笔记(一)之Hello world
- qt学习笔记(一)之Hello world
- Spring Boot学习之旅:(一)HELLO WORLD
- 【转】Object-C之Windows版Hello, World!
- 我的c学习之路二------hello world
- Objective C 学习之路1(Hello world)
- C/C++ 学习之路 -- 第0001课 -- Hello World
- C/C++ 学习之路 -- 第0001课 -- Hello World
- Python学习笔记(一)Hello World
- C++中TRACE宏及assert()函数的使用
- に的用法
- QT国际化支持
- struts2的常量配置default.properties
- 递归函数中静态变量的疑惑
- Object-c 学习之路一(Hello world)
- .net 快捷键
- 在C/C++代码中使用SSE等指令集的指令(1)介绍
- js获取高度
- 糊涂窗口综合症及其解决方法
- Android网络编程之Http通信
- 如何进行选择
- java23种设计模式分类
- pyOpenssl简介