-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.m
More file actions
194 lines (134 loc) · 4.45 KB
/
Copy pathlab1.m
File metadata and controls
194 lines (134 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// 1)
#import <Fundamental/Fundamental.h>
int main()
{
printf("This is my 1st C statement.");
printf("This is my 2nd C statement.");
printf("This is my 3rd C statement.");
printf("This is my 4th C statement.");
printf("This is my 5th C statement.");
NSLog(@"This is my 1st objective-C statement.");
NSLog(@"This is my 2nd objective-C statement.");
NSLog(@"This is my 3rd objective-C statement.");
NSLog(@"This is my 4th objective-C statement.");
NSLog(@"This is my 5th objective-C statement.");
sleep(1);
return(0);
}
/*
Take a screen shots of the C statements, objective C statements separately and
together and the role of the sleep(1) statement. The sleep(1); statement allows
the string buffer to be flushed before the program completes execution.
*/
// 2)
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
double odometer = 9200.8;
int odometerAsInteger = (int)odometer;
NSLog(@"You've driven %.1f miles", odometer); // 9200.8
NSLog(@"You've driven %d miles", odometerAsInteger); // 9200
}
return 0;
}
// 3)
int a;
int b;
int c;
a = 1;
b = 2;
c = a + b;
NSLog(@"Hello World!");
NSLog(@" a + b = %i", c);
NSLog(@" a + b = %i", a + b);
NSLog(@" a = %i", a);
NSLog(@" b = %i", b);
// 4) Create a New Xcode Project called Lab 1 Exercise 2
@autoreleasepool {
NSLog(@"Hello, World!");
NSString * firstString = @"This holds my string";
NSString *thisHoldsANumberString = [NSString stringWithFormat:@"my number = %d and %d",4,5];
NSString *numberString = @"3456";
int myIntNumber = [numberString intValue];
float myFloatNumber = [numberString floatValue];
NSString *floattring = [NSString stringWithFormat:@"My number = %f", myFloatNumber];
NSNumber *myNSNumber = [[NSNumber alloc] initWithInt:myIntNumber];
NSLog(@"firstString =%@", firstString);
NSLog(@"thisHoldsANumberString = %@", thisHoldsAnumberString);
NSLog(@"numberString = %@", numberString);
NSLog(@"myFloatNumber = %f", myFloatNumber);
NSLog(@"myIntNumber = %d", myIntNumber);
NSLog(@"floatString = %@", floatString);
NSLog(@"myNSNumber = %@", [myNSNumber stringvalue]);
}
// 5)
it jj;
for (jj=0; jj < 4; jj++) {
NSLog(@"%d, ",jj);
}
// 6)
double x=24.0;
NSNumber *result = @(x * .15);
NSLog(@"%.2f",[result doubleVelue]);
// 7)
int len = [@"Hello" length];
NSLog(@"Length of string = %i", len);
// 8)
NSString *ns = [NSString stringWithFormat:@"My Number=%d and %d", 4, 5];
NSLog(@" %@", ns);
// 9)
NSString *string1=@"This is a string";
NSMutableString *string2;
string2 = [NSMutableString stringWithString:string1];
NSLog(@" string1 = %@, string2 = %@", string1, string2);
// 10)
NSMutableString *string3=[NSMutableString stringWithString:@"The quick brown fox jumped."];
[string3 insertString:@"agile, " atIndex : 4];
NSLog(@" string3 = %@", string3);
// 11)
NSString *string4=@"The quick brown fox jumped";
NSString *string5;
string5 = [string4 capitalizedString];
NSLog(@" string4 = %@, string5 = %@", string4, string5);
also can try: lowerCaseString, upperCaseString
// 12)
NSLog (@"Current date: %@", [NSDate date]);
// 13)
Comment out the #import <UIKit/UIKit.h> statements
Add the #import <Foundation/Foundation.h> statement instead
// 14) add 5 lines of the following C code:
printf("This is a line of C code. \n");
// 13)
NSMutableString *string3=[NSMutableString stringWithString:@"The quick brown for jumped."];
[string3 insertString:@"agile, " atIndex : 4];
NSLog(@"..%@ .. %@", string1, string2);
NSLog(@"...%@ ", string3);
NSString *string4=@"The quick brown fox jumped";
NSString *string5;
NSString *string6;
NSString *string7;
string5 = [string4 capitalizedString];
string6 = [string4 lowercaseString];
string7 = [string4 uppercaseString];
NSLog(@"...%@ ... %@", string4, string5);
NSLog(@"...%@ ... %@", string4, string6);
NSLog(@"...%@ ... %@", string4, string7);
NSLog(@"Current date: %@", [NSDate date]);
@autoreleasepool {
NSMutableArray *items = [ [NSMutableArray alloc] init];
[items addObject:@"One"];
[items addObject:@"Two"];
[items addObject:@"Three"];
[items insertObject:@"zero" atIndex:0];
NSLog(@"Object at 0 is %@", [items objectAtIndex:0]);
NSLog(@"Object at 1 is %@", [items objectAtIndex:1]);
NSLog(@"Object at 2 is %@", [items objectAtIndex:2]);
NSLog(@"Object at 3 is %@", [items objectAtIndex:3]);
for (int i = 0; i < [items count]; i++) {
NSLog(@"%@", [items objectAtIndex:i]);
}
items = nil;
}
sleep(1);
return 0;
}