食譜

Examplets.org

Objective-C Daily (May 29, 2017)

 

Date 2011/4/9
Name Add Two Numbers
Description Add Two Numbers using Objective-C
Filename AddTwoNumObjC.c
Content
  1. Using the Standard input stream to enter different numbers or text
  2. Find two integers each time and,
  3. Display output the sum to the standard output stream.
  4. Repeat the all the steps until an EOF (End of File) signal received
Sample Input: 123 3.5 dsfasd 4 fdsafds 6
Sample Output: 126 0
Expected Test Command:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSMutableData* data=[NSMutableData dataWithLength:sizeof(char) * 256];
	NSInteger total=0;
	NSInteger nCount=0;
	char* temp=[data mutableBytes];
	do{
		temp[0]=0;
		scanf("%255s",temp);
		if (temp[0]!=0) {
			NSInteger val;
			NSString *data=[[NSString alloc] initWithCString:temp];
			NSScanner *scan=[NSScanner scannerWithString:data];
			if([scan scanInteger:&val]){
				if (nCount++ % 2==0) {
					total=val;
				}else {
					total+=val;
					printf("%d ",(int)total);
				}
			}

		}
	}while(temp[0]!=0);
    [pool drain];
    return 0;
}


Date 2011/4/8
Name Hello Friend
Description Ask user's name and echo greeting message to user using Objective C
Filename HelloFriendObjC.c
Content
  1. Using the Standard output stream to prompt your:"Your name?"
  2. Then use the input stream to receive input from user.
  3. Display the greeting message "Hello, [user name]!" using standard output stream.
  4. Repeat all the steps until users press CTRL-Z (MS windows) or CTRL-D (Mac) or receive the EOF signal.
Sample Input: Peter Pan
Sample Output: Hello, Peter Pan!
Expected Test Command:  

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSMutableData* data=[NSMutableData dataWithLength:sizeof(char) * 256];
	char* name=[data mutableBytes];
	printf("Your name?");
	do{
		name[0]=0;
		scanf("%[^\n]+",name);
		if (name[0]!=0) {
			printf("Hello, %s!\n",name);
			printf("Your name?");
			scanf("%c",name);
		}
	}while(name[0]!=0);
	[pool drain];
	return 0;
}


Date 2011/4/7
Name Hello World
Description Display greeting message to user using Objective C
Filename HelloWorldObjC.c
Content
  1. Display the greeting message "Hello, World!" using standard output stream by Windows Scripting File using JScript
Sample Input:  
Sample Output: Hello, World!
Expected Test Command:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	printf("Hello, World!\ns");
    [pool drain];
    return 0;
}

6502 MPU and assembly


Latest Blog Articles from CloudGen wordpress blog!


Copyright 2008-2017

Cloud-Gen