C++ 2020. 4. 15. 09:11

<stdio.h>#include <Windows.h>#include <conio.h> //로컬디스크 D 에 ID 라는 파일을 생성해주세요 (대문자)#include <string.h> //프로젝트 - 속성 - c/c++ - 전처리기 ;_CRT_SECURE_NO_WARNINGS 를 추가#include <stdlib.h>#include <ctype.h>

void menu(int*); //로그인프로그램메뉴void login(char*, char*); //로그인void singup(char*, char*); //회원가입

int main(void){ int cho; //선택화면에서 선택값을 저장하는곳 char loginid[15]; //로그인에서 아이디를 저장하는곳 char loginpassword[15]; //로그인에서 비밀번호를 저장하는곳 char singupid[15]; //회원가입에서 아이디를 저장하는곳 char singuppassword[15]; //회원가입에서 비밀번호를 저장하는곳

menu(&cho);

switch (cho) { case 1: login(loginid, loginpassword); break; case 2: singup(singupid, singuppassword); break; default: printf("잘못입력하셨습니다."); main(); break; }}

void menu(int *cho) //메인화면{ printf_s("제작자 : staff2303@gmail.com \n"); printf_s("==============================================. \n"); printf_s("1.login \n"); printf_s("2.sing up \n"); printf_s("주의! 문자입력시오류! (수정중)\n"); scanf_s("%d", cho); system("cls");

}

void login(char *loginid, char *loginpassword) //로그인화면

{ FILE *rfp; char file[50]; char loginpassword2[15]; int amo; printf_s("login. \n"); printf_s("==========================================. \n"); printf_s("  I  D   : "); scanf_s("%s", loginid, 15); sprintf_s(file, "D:\\ID\\%s.txt", loginid); // 아이디와 똑같은 파일을 오픈 fopen_s(&rfp, file, "r"); // 파일이없어서열수없을경우 rfp에는 NULL이들어온다. 

if (rfp == NULL) { system("cls"); printf_s("아이디가없습니다. \n"); printf_s("==========================================. \n"); system("Pause"); system("cls"); main(); }

printf_s("PASSWORD : "); scanf_s("%s", loginpassword, 15); printf("암 호 키 : "); scanf_s("%d", &amo); FILE* fp = fopen(file, "r");   //파일오픈 fgets(loginpassword2, 15, fp); //메모장에서 password를  password2로 저장 fclose(fp); for (int i = 0; loginpassword2[i] != '\0'; i++) //password 복호화 { if (isalpha(loginpassword[i])) { if (loginpassword2[i] - amo < 'a') { int plus = 'a' + amo - 1 - loginpassword2[i]; loginpassword2[i] = 'z'; loginpassword2[i] -= plus; } else loginpassword2[i] -= amo; } else { if (loginpassword2[i] - amo < '0') { int plus = '0' + amo - 1 - loginpassword2[i]; loginpassword2[i] = '9'; loginpassword2[i] -= plus; } else loginpassword2[i] -= amo; } }

if (strcmp(loginpassword, loginpassword2) == 0) // 입력한 password와 복호화된 password를 비교 { printf_s("\n로그인완료\n"); system("Pause"); system("cls"); exit(1); } else { system("cls"); printf_s("비밀번호 혹은 암호키가 틀립니다.\n"); system("Pause"); system("cls"); main(); }}

void singup(char *singupid, char *singuppassword)

{ FILE *fp; char file[50]; int amo; printf_s("sing up. \n"); printf_s("==========================================. \n"); printf_s("아이디를입력하시오(15자이내). \n"); scanf_s("%s", singupid, 15); sprintf(file, "D:\\ID\\%s.txt", singupid); // 폴더의 이름과 경로를 file 에 저장 (아이디 = 폴더의 이름) fp = fopen(file, "w+"); fclose(fp); Sleep(1000); system("cls");

printf_s("sing up. \n"); printf_s("==========================================. \n"); printf_s("비밀번호를입력하세요(영문, 숫자 15자이내).\n"); scanf_s("%s", singuppassword, 15); printf_s("암호키를 입력하세요(1~5) \n"); scanf_s("%d", &amo);

for (int i = 0; singuppassword[i] != '\0'; i++) //password 암호화 { if (isalpha(singuppassword[i])) { if (singuppassword[i] + amo > 'z')

{ int less = singuppassword[i] - 'z';

singuppassword[i] = 'a' + amo - 1; singuppassword[i] += less; } else singuppassword[i] += amo; } else { if (singuppassword[i] + amo > '9')

{ int less = singuppassword[i] - '9';

singuppassword[i] = '0' + amo - 1; singuppassword[i] += less; } else singuppassword[i] += amo; } } fp = fopen(file, "w+"); fprintf(fp, "%s", singuppassword); fclose(fp); Sleep(1000); system("cls"); //완료창  printf_s("회원가입완료. \n"); printf_s("==========================================. \n"); Sleep(1000); system("cls"); main();}

'C++' 카테고리의 다른 글

[C++] 네이버 RSA 로그인 소스  (0) 2020.04.14
posted by 핵커 커뮤니티
:
VB 2020. 4. 15. 09:08

먼저 폼에 커맨드버튼 1개, 텍스트 박스 1개를 준비한후,

프로젝트▶구성 요소로 들어간다음 잘 찾아보시면

Microsoft Internet controls 가 있습니다. 그것을 체크하신후,

확인을 누르면 도구 탭에 지구(?)가 등록되는 대요,

그걸 클릭하고 폼에 추가 해 줍니다.

커맨드버튼에 무엇을 입력하냐면

Private sub CommandButton1_click()

WebBrowser1.Navigate (Text1)

End sub 가 되겠죠.

그리고 Text1에 주소를 입력하고 커맨드 버튼을 누르면 웹 브라우저에 인터넷이 표시됩니다.

만약 뒤로, 앞으로, 홈으로, 새로고침 을 추가 하고 싶다면,

뒤로는

Private sub CommandButton1_click()

WebBrowser1.GoBack

End sub 이고

앞으로는

Private sub CommandButton1_click()

WebBrowser1.GoForward

End sub 이고

홈으로는

Private sub CommandButton1_click()

WebBrowser1.GoHome

End sub 이고

새로고침은

Private sub CommandButton1_click()

WebBrowser1.Refresh 가 되겠죠.

만약 웹브라우저에서 새로운 창을 추가하면,

Internet Explorer 로 새 창이 나옵니다.

만약 만든 브라우저로 새 창을 열고 싶을때는,

이 코드를 폼에 추가 하면 됩니다.

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)

Dim frm As Form1

Set frm = New Form1

Set ppDisp = frm.WebBrowser1.Object

frm.Show

End Sud

'VB' 카테고리의 다른 글

[VB] 랜덤숫자을 출력해보자  (0) 2020.04.15
[VB] 다음 로그인 소스  (0) 2020.04.15
[VB] 스마일파일 로그인 소스  (0) 2020.04.15
[VB] 한글판 패치하기  (0) 2020.04.15
posted by 핵커 커뮤니티
:
SQL 2020. 4. 14. 19:28

JOIN 의 개념

서로 다른 테이블을 공통 컬럼을 기준으로 합치는(결합하는) 테이블 단위 연산

조인의 결과 테이블은 이전 테이블의 컬럼 수의 합과 같다.

SELECT * FROM 테이블 1 JOIN 테이블 2 ON 테이블1.컬럼명 = 테이블2.컬럼명 ...

조인 시 서로 다른 테이블에 같은 컬럼명이 존재하면 구분을 위해 테이블명.컬럼명으로 사용해서 표시

 

예제

- city 테이블과 country 테이블을 조인하시오. (city.CountryCode = country.Code)

- 국가코드와 해당 나라의 GNP 를 표시하시오

 

결과 확인

- SELECT * FROM city JOIN country ON city.CountryCode = country.Code;

- SELECT city.CountryCode, country.GNP FROM city join country ON

city.CountryCode = country.Code;

 

 

 

 

 

 

JOIN 의 종류

조인 시 NULL 값을 허용하는 내부 조인(불가)과 외부조인(허용)으로 구분

INNER JOIN / LEFT JOIN / RIGHT JOIN / FULL JOIN

 

INNER JOIN

조인 시 NULL 값을 허용하지 않음

(NULL 값을 가진 레코드는 조인결과에 빠짐)

LEFT JOIN

조인 시 JOIN 의 왼쪽 테이블의 NULL 값을 포함해서 표시

RIGHT JOIN

조인 시 JOIN 의 오른쪽 테이블의 NULL 값을 포함해서 표시

FULL JOIN

MySQL 은 지원하지 않음

 

 

예제

- city 테이블에 국가코드가 없는 도시가 있는지 확인

- country 테이블에는 존재하지만 도시가 하나도 없는 나라가 있는지 확인

- 이 때 INNER JOIN / LEFT JOIN / RIGHT JOIN 의 차이점으로 확인

 

결과 확인

- SELECT COUNT(*) FROM city WHERE CountryCode is NULL;

- SELECT COUNT(*) FROM city LEFT JOIN country ON city.CountryCode = country.Code;

(country 값이 존재하지 않는 city 는 포함)

- SELECT COUNT(*) FROM city RIGHT JOIN country ON city.CountryCode = country.Code;

(country 중 도시 수가 하나도 없는 country 는 포함)

 

 

 

 

 

 

별명(ALIAS)

SQL 쿼리 결과 생성 시 컬럼명에 대한 별명을 사용해 표시하는 기능

SELECT 테이블명1.컬럼명1 AS 별명1, 테이블명2.컬럼명2 AS 별명2 FROM ....

조인할 때 많이 사용된다

 

예제

- city 테이블과 country 테이블을 조인해서 국가코드 'KOR' 인 나라의 축약표시명(Abbr) 과 정식명(Full Name)을 표시하시오

 

결과 확인

- SELECT city.CoutryCode AS Abbr, country.Name AS FullName FROM city JOIN country on city.CountryCode = country.Code WHERE city.CountryCode = 'KOR';

 

 

 

 

뷰 (VIEW)

SQL 쿼리의 결과값을 임시 테이블로 저장해서 사용할 수 있음

사용 용도가 끝나면 명시적으로 삭제해야 함 (DROP VIEW ....)

CREATE VIEW 뷰명 AS SELECT ...

 

예제

CREATE VIEW sampleView AS SELECT city.CountryCode AS Abbr, country.Name AS FullName FROM city JOIN country ON city.CountryCode = country.Code WHERE city.CountryCode = 'KOR';

SELECT * FROM sampleView;

posted by 핵커 커뮤니티
:
SQL 2020. 4. 14. 19:18

DISTINCT 연산자

SELECT 문의 결과 값에서 특정 컬럼만 출력할 경우 중복된 값들이 나오는 경우에 이를 제거해서 표시하는 기능

SELECT DISTINCT 컬럼명 1, 컬럼명 2, ... FROM 테이블명

 

예제

- 국가코드가 'KOR' 인 도시들의 국가코드를 표시하시오.

- 국가코드가 'KOR' 인 도시들의 국가코드를 중복제거해서 표시하시오.

 

결과 확인

- SELECT CountryCode FROM city WHERE CountryCode = 'KOR';

- SELECT DISTINCT CountryCode FROM city WHERE CountryCode = 'KOR';

 

 

 

 

논리연산자 (AND, OR, NOT)

SELECT 문의 조건절에 논리 조건 적용해서 적용할 수 있는 연산자

SELECT * FROM 테이블명 WHERE (NOT) 조건 1 AND/OR (NOT) 조건 2 ..... 

 

예제

- 국가코드가 'KOR' 이면서 인구가 100만 이상인 도시를 찾으시오

- 국가코드가 'KOR', 'CNN', 'JPN' 인 도시를 찾으시오

- 국가코드가 'KOR' 이 아니면서 인구가 100만 이상인 도시를 찾으시오.

 

 

 

결과 확인

- SELECT * FROM city WHERE CountryCode = 'KOR' AND Population > 1000000

- SELECT * FROM city WHERE CountryCode = 'KOR' OR CountryCode = 'CNN' OR CountryCode = 'JPN'

- (위와 같은 코드) SELECT * FROM city WHERE CountryCode in ('KOR', 'CNN', 'JPN')

 

- SELECT * FROM city WHERE CountryCOde != 'KOR' AND Population > 1000000

posted by 핵커 커뮤니티
:
PHP 2020. 4. 14. 19:07

[PHP]함수의 인수

함수 안에서 사용하는 값을 함수 밖에서 전달할 수 있는데 이 값을 인수라고 한다.

-예

<?php

function check($age) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check(19);

?>

-결과

​프로그래밍

 

인수가 지정되지 않은 경우(에러가 발생한다.)

- 예

<?php

function check($age) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check();

?>

- 결과(에러 발생)

Fatal error: Uncaught ArgumentCountError: Too fewargumenC:/ xampp/hydocs/for:php:

2 Stack trace: #0 C:xampp/hidocs/for

인수에 값이 없는 경우 에러가 발생하므로 인수의 기본값을 사용한다.

-예

<?php

function check($age=19) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check();

?>

 

- 결과(에러가 발생하지 않았다.)

프로그래밍

 

<?php

function test($x1, $x2)(

echo '*'.$x1.$x2.'*';

)

test('핵','커');

?>

결과는 *핵커*

'PHP' 카테고리의 다른 글

[PHP] PHP 문자 N 문자를 연결해보자!  (0) 2020.04.14
[PHP] PHP 함수 생성 및 호출  (0) 2020.04.14
[PHP] PHP 다운로드  (0) 2020.04.14
[PHP] 시작,종류,태그,변수,저장확정자  (0) 2020.04.11
posted by 핵커 커뮤니티
:
Objective_C 2020. 4. 14. 18:52

9.파운데이션 프레임워크

9-1.루트 클래스

NSObject는 Objective-C의 클래스가 가져야 할 가장 기본적인 기능(메모리 관리, 객체 식별 등)을 제공하며,모든 클래스는 NSObject를 직접 혹은 간접적으로 상속함으로써 그 기능들을 사용할 수 있게된다. 사용자가 직접 구현하는 클래스도 이를 위해 NSObject를 상속하는 것을 절대 잊지말아야한다.

 

9-2.문자열 관련 클래스

9-2-1.NSString

유니코드 방식으로 문자열을 다루는 기능을 제공하는 클래스,. 파운데이션 프레임워크에서 가장 많이 사용되는 클래스

-기본사용방법 : 문자열 앞에 항상 '@'를 붙여주어야한다. NSString *string = @"string test";

-포맷표현 방식 : 다른언어의 %s가 아니라 %@사용한다. 나머지 타입은 같다(%d,%f,%u)

NSString *string1 = [[NSString alloc]initWithFormat:@"%@",@"string"];

NSStirng *string2 =[NSString stringWithString:@"string"];

-생성 메소드 : 클래스 메소드는 alloc 또는 copy로 시작하는 이름을 갖지 않으므로 사용이 끝난 후 release할 필요없다.

인스턴스 메소드들은 alloc 메소드를 이용하여 생성되므로, 사용이 끝난 후에는 반드시 release를 호출해야한다.

//빈 문자열을 가지는 객체를 생성하여 반환

+(id)string

//주어진 문자열을 가지는 객체를 생성하여 반환

+(id)stringWithFormat:(NSString *)format, …

+(id)stringWithString:(NSString *)aString;

//위 메소드들의 인스턴스 메소드 형태, 기능은 동일

-(id)initWithFormat:(NSString *)format …

-(id)initWithString:(NSString *)aString

//사용예

NSString *string1 = [NSString string];

NSString *string2 = [NSString stringWithFormat:@"String: %@", @"Test"];

NSString *string3 = [NSString stringWithString:@"String"];

NSString *string4 = [[NSString alloc] initWithFormat:@"String : %@",@"Test"];

NSString *string5 = [[NSString alloc] initWithString:@"String"];

-결합메소드

//현재 문자열과 주어진 문자열을 결합하여 반환

-(NSString *)stringByAppendingFormat:(NSSting *)format …

-(NSString *)stringByAppendingString:(NSString *)aString

//사용예

NSString *string1 = @"Hello"

NSString *string2 = [stirng1 stringByAppendingFormat:@"%@",@"World"];

NSString *string3 = [stirng1 stringByAppendingString:@" World"];

-분리 메소드

//현재 문자열을 검사하여 주어진 문자열이 나타낼 때마다 문자열 분리

-(NSArray *)componentsSeparatedByString:(NSString *)separator

//현재 문자열의 주어진 위치 이후 문자열 반환

-(NSString *)substringFromIndex:(NSUInteger)anIndex

//현재 문자열의 주어진 위치까지의 문자열 반환

-(NSString *)substringToIndex:(NSUInteger)anIndex

 

//사용예

NSString *string1 = @"String1, String2, String3";

NSArray *iterms =[string1 componentsSeparatedByString:@". "];

//ite는 :{@"String1", @"String2", @"String2"}

NSString *string2 =@"String";

NSString *string3 =[string2 substringFromIndex:3];

NSString *string4 =[string2 substringToIndex:3];

//string 2: @"ing" string 4:@"str"

-값 변환 메소드

//현재 문자열에 해당하는 정수값 반환

-(int)intValue

//현재 문자열에 해당하는 실수값 반환

-(float)floatValue

-(double)doubleValue

//사용예

NSString *string1 =@"5";

int intValue =[string1 intValue]; //intValue : 5

NSString *string2 =@"2.34";

float floatValue = [string2 floatValue]; //2.34

double double Value = [string2 doubleValue]; //2.34

-비교 메소드

//현재 문자열이 주어진 문자열로 시작하는지 검사

-(BOOL)hasPrefix:(NSString *)aString

//현재 문자열이 주어진 문자열로 끝나는지 검사

-(BOOL)hasSuffix:(NSString *)aString

//현재의 문자열이 주어진 문자열과 동일하지 검사

-(BOOL)isEqualToString:(NSString *)aString

//사용예

NSString *string1 = @"Hello World!";

BOOL value1 = [string1 hasPrefix:@"Hel"];

BOOL value2 = [string1 hasSuffix:@"orld"]; //value1,value2 :YES

BOOL value3 = [string1 isEaualToString:@"Hello World!"]; //value3 :YES

-기타 메소드

//문자열의 길이를 반환

-(NSUInteger)length

//문자열읮 ㅜ어진 위치에 해당하는 문자를 반환

-(unichar)characterAtIndexLNSUInteger)index

//사용예

NSString *string = @"String";

int length = [string length]; //length :6

unichar value = [string characterAtIndex:3]; //value : i

9-2-2.NSMutableString

NSString 클래스를 상속하는 자식 클래스, 문자열을 한번 할당하면 변경할 수 없는 NSString과는 달리 수정할 수 있다는 것이 장점, 참고로 파운데이션 프레임워크 클래스 중에서 이름에 Nutable이 포함된 클래스 (NSMutableArray, NSMutableDictionary 등)는 값을 수정할 수 있는 클래스다,.

 

//주어진 문자열을 현재의 문자열과 결합

-(void)appendFormat:(NSString *)format ..

-(void)appendFormat:(NSString *)aString

//주어진 문자열을 현재 문자열의 주어진 위치에 사입

-(void)insertString:(NSString *)aString atIndex:(NSUInteger)anIndex;

//현재의 문자열을 주어진 문자열로 대체

-(void)setString:(NSString *)aString

//사용예

NSMutableString *string. = [NSmutableString stringWithString:@"Hello"]; //String :@"Hello"

[string appendFormat:@"%@",@"Wor"]; //String :@"Hellowor"

[string appendString:@"ld!"] //string: @"Helloworld!"

[string insertString:@" " atIndex:5]; //string: @"Hello world!"

[string setString:@"Bye World!"]; //string: @"Bye World!"

 

9-3.객체 집합 관련 클래스

NSArray : 순서가 있는 객체 리스트를 관리

NSDictionary : 키 – 값 형태의 객체 리스트를 관리

NSSet : 순서가 없는 객체 리스트를 관리

위는 할당된 내용을 수정할 수 없는 클래스지만. 이들 클래스 이름에 Mutable이 들어간 MSMutableArray, NSMutableDictionary, NSMutableSet는 수정할수 있는 클래스이다.

 

9-3-1.NSArray

-생성메소드

//사용예

NSDate     *aDate = [NSDate distantFuture];

NSValue     *aValue = [NSNumber numberWithInt:5];

NSString     *aString = @"a string";

// +(id)arrayWithObjects : 주어진 객체들을 포함하는 객체를 생성하여 반환

NSArray *array1 = [NSArray arrayWithObjects:aData, avalue, aString, nil]; //마지막은 반드시 nil을 전달

// -(id)initWithObjects : arrayWithObjects의 인스턴스 메소드 형태, 기능은 동일

NSArray *array2 = [[NSArray alloc]initWithObjects:aData, aValue, aString, nil]; //마지막은 반드시 nil을 전달

//+(id)arrayWithArray: 주어진 배열 내의 인자들을 포함하는 객체를 생성하여 반환

NSArray *array3 = [NSArray arrayWithArray: array1];

//-(id) initWithArray : +arrayWithArray의 인스턴스 메소드 형태 기능은 동일

NSArray *array4 = [[NSArray alloc] initWithArray: array1];

주요메소드

NSString *item1 = @"1", *item2 = @"2", *item3=@"3";

NSArray *array = [NSArray arrayWithObjects: item1, item2, item3, nil]; //array :{item1, item2, item3}

//주어진 배열 내의 인자의 수를 반환

int cout : [array count]; //count :3

//주어진 인덱스의 객체를 반환

NSString *string = [array objectAtIndex:1]; //string :@"2"

//주어진 객체의 배열 내의 인덱스를 반환

NSUInteger index = [array indexOfbject :item3]; //index:2

 

9-3-2.NSMutabelArray

NSString *item1 = @"1", *item2 = @"2", *item3=@"3", *item4=@"4";

NSMutableArray *array =[NSMutableArray arrayWithObjects: item1, item2, item3, nil]; //array :{item1, item2, item3}

//주어진 인자를 지정된 위치에 삽입한다.

[array insertObject:item4 atIndex:2]; ////array :{item1, item2,item4, item3}

//지정된 위치의 인자를 삭제한다.

[array removeObjectAtIndex:3]; ////array :{item1, item2,item4}

//주어진 인자를 배열 끝에 추가한다.

[array addObject:item3]; // array :{item1, item2,item4,item3}

//마지막 인자를 삭제한다.

[array removeLastObject]; // array :{item1, item2,item4}

//현재 배열의 지정된 위치의 객체를 주어진 객체로 대체한다.

[array replaceObjectAtIndex:2, withObject:item3]; // array :{item1, item2,item3}

 

9-3-3.NSDictionary –stl의 map

-생성메소드

//+(id) dictionaryWithObjectsAndKeys: 주어진 객체, 키 값으로부터 객체를 생성반환

NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2",nil];

//-(id) initWithdictionaryWithObjectsAndKeys:+(id) dictionaryWithObjectsAndKeys의 인스턴스 메소드 형태

NSDictionary *dict2 = [[NSDictionary alloc] initWithdictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2",nil];

-주요메소드

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Chris", @"name", @"programmer", @"job",nil]; //dirct :{@"job" : @"programmer", @"name :@"Chris"}

//dictionary에 있는 객체의 수를 반환

NSUInteger count = [dict count]; //count :2;

//dictionary에 있는 모든 키 값들을 반환

NSArray *keys= [dict allKeys]; //Keys:{@"job",@"name"};

//dictionary에 있는 모든 객체들을 반환

NSArray *values = [dict allValues]; values :{@"programmer",@"Chris"}

//주어진 키 값을 갖는 객체를 반환

NSString *string = [dict objectForKey:@"name"]; //string : @"Chris"

9-3-4.NSMutableDictionary

NSMutableDictionary *dict =[NSMutableDictionary dictionary]; //Dict: { }

//주어진 객체와 키 조합을 추가한다.

[dict setObject:@"Chris" forKey:@"name"]; //dict:{@name: @"chris"}

[dict setObject:@"programmer" forKey:@"job"]; //dict: {@"job": @"programmer", @"name" : @"Chris"}

//주어진 객체와 키 조합을 삭제

[dict removeObjectForKey:@"name"]; //dict : {@"job" : "programmer"};

//모든 객체-키 조합 삭제

[dict removeAllObjects];//dict:{ }

9-3-5.NSSet –NSArray와 달리 순서가 없다.

-생성메소드

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *aString = @"a string";

//주어진 객체들을 포함하는 객체를 생성하여 반환

NSSet "mySet =[NSSet setWithObjects:aDate, aValue, aString, nil];

// NSSet "mySet =[[NSSet alloc]initWithObjects:aDate, aValue, aString, nil];

-주요메소드

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *name = @"Chris";

NSSet *mySet =[NSSet setWithObjects: date, value, name, nil]; //mySet :{value, name, date}

//NSSet 에 들어있는 오브젝트 객체 개수

NSUInteger count =[mySet count]; //count :3

//NSSet에 들어있는 모든 오브젝트 객체 반환

NSArray *array1 = [mySet allObjects]; // array1 : {value, name, date;

//NSSet 내에 주어진 객체가 존재하는지 검사하여 결과 반환

BOOL result = [mySet containsObject:@"Chris"]; //result :YES

9-3-6 NSMutableSet

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *name = @"Chris", *job = @"programmer";

NSMutableSet *mySet =[NSMutableSet setWithObjects: date, value, name, nil]; //mySet :{value, name, date}

//set에 주어진 객체를 추가

[mySet addObject:job]; //mySet :{job, value, name, date}

//set에 주어진 객체 삭제

[mySet removeObject:@"Chris"]; //mySet :{job, date,value}

//set의 모든 객체 삭제

[mySet removeAllObjects]; //mySet: {}

9-3-7 객체 탐색

-객체를 탐색하는 예

NSArray *array = [NSArray arrayWithObjects:@"One",@"Two", @"Three", @"Four", nil];

NSString *item = nil;

for( item in array){

if([item isEqualToString:@"Three"]){

break;

}

}

-NSEnumerator를 사용하는 방법

NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", @Three", @"Four", @nil];

NSString *item = nil;

NSEnumerator *enumerator = [array objectEnumerator];

 

while(item = [enumerator nextObject]){

if( [item isEqualToString:@"Three"]){

break;

}

}

NSEnumerator 사용하면 좋은예

NSArray의 경우 reverseEnumerator 메소드를 이용하여 객체를 역순으로 탐색 할수 있다.

objectEnumerator 대신에 reverseEnumerator 메소드를 호출하면 된다.

NSDictionary의 경우 NSEnumerator를 이용하면 키 값뿐 아니라 객체도 탐색할 수 있다. 키 값을 탐색할때는 KeyEnumerator 메소드, 객체 값을 탐색할때는 objectEnumerator를 이용하면 된다

 

9-4. 값(정수 및 실수)표현 관련 클래스

9-4-1.NSNumber

NSValue 클래스를 상속하는 자식 클래스, BOOL, char, int, float와 double 등 각종 값을 설정하고 반환하는 기능을 수행한다.

NSNumber *boolNumber = [NSNumber numberWithBool:YES];

NSNumber *intNumber = [NSNumber numberWithInt:23];

NSNumber *doubleNumber = [NSNumber numberWithDouble:23.46];

BOOL     value1 = [boolNumber boolValue];

int     value2 = [intNumber intValue];

double     value3 = [doubleNumber doubleValue];

//값비교

NSNumber *intNumber = [NSNumber numberWithInt:23];

NSNumber *floatNumber = [NSNumber numberWithFloat:3.45];

NSString *string1 = [intNumber stringValue]; //string1 : 23

if(NSOrderedAscending == [intNumber compare:floatNumber]{

}

BOOL equality = [intNumber isEqualToNumber:floatNumber];

 

//compare:메소드는 kemdarhk 같은 반환값을 가지게된다.

NSOrderedAscending    :현재 값보다 주어진 값이 클경우

NSOrderedDescending    :현재 값보다 주어진 값이 작은경우

NSOrderedSame        :현재 값과 주어진 값이 같은 

'Objective_C' 카테고리의 다른 글

[Objective-C] 기초배우기 (3)  (0) 2020.04.14
[Objective-C] 기초배우기 (2)  (0) 2020.04.14
[Obejective-C] 기초배우기 (1)  (0) 2020.04.13
posted by 핵커 커뮤니티
:
PHP 2020. 4. 11. 13:16

[PHP]_php 시작_종료 태그,변수, 저장 확장자

작성한 파일의 확장자를 html로 지정하면 php의 시작, 종료 태그 사이의 내용을 해석하지 않는다.

따라서 php의 내용을 표현하려면 확장자를 php로 저장하여야 한다.

<시작,종료> 태그는

<?php

-

-

-

?>

이런식으로 된 형식이다.

만약 다음과 같은 형식을 사용하려면

php.ini에서 설정해 주어야 한다.

<?

?>

short_open_tag=on

변수명 앞에서 $를 붙여야함

$x1 = 1;

$x2 = 2;

주의점! > 저장할 때 확장자는 php로 한다. <

내용 출력 명령은

echo​ "원하는 내용";

echo 1;

 

'PHP' 카테고리의 다른 글

[PHP] PHP 함수의 인수 배우보자!!!  (0) 2020.04.14
[PHP] PHP 문자 N 문자를 연결해보자!  (0) 2020.04.14
[PHP] PHP 함수 생성 및 호출  (0) 2020.04.14
[PHP] PHP 다운로드  (0) 2020.04.14
posted by 핵커 커뮤니티
: