연습문제 코드 첨부
393
작성한 질문수 10
안녕하세요
좋은 강의 잘 듣고 있습니다.
연습문제를 풀어 보았는데 맞게 한건지 궁금하여 첨부합니다.
int main() //연습문제
{
unsigned char option_viewed = 0x01;
unsigned char option_edited = 0x02;
unsigned char option_liked = 0x04;
unsigned char option_shared = 0x08;
unsigned char option_deleted = 0x80;
unsigned char my_article_flags = 0;
/*cout << bitset<8>(option_viewed) << endl;
cout << bitset<8>(option_edited) << endl;
cout << bitset<8>(option_liked) << endl;
cout << bitset<8>(option_shared) << endl;
cout << bitset<8>(option_deleted) << endl;*/
//viewed article
my_article_flags |= option_viewed;
cout << bitset<8>(my_article_flags) << endl;
//clicked like
my_article_flags |= option_liked;
cout << bitset<8>(my_article_flags) << endl;
//clicked like again
my_article_flags &= ~option_liked;
cout << bitset<8>(my_article_flags) << endl;
//deleted this article
my_article_flags |= option_deleted;
cout << bitset<8>(my_article_flags) << endl;
return 0;
}
답변 2
1
문제 없이 잘 하신 것 같습니다.
뭔가 하나 알려드리면 Exclusive or 이라는 게 있는데, ^ 입니다.
https://en.wikipedia.org/wiki/Exclusive_or에서 truth table 만 보고 오셔도 충분합니다.
이걸 사용하시면 option_liked에 대한 동작을 하나로 만드실 수 있습니다. (다른 것도 마찬가지입니다.)
0
항상 좋은 가르침 감사합니다.
my_article_flags |= option_liked; 와 my_article_flags &= ~option_liked; 를
XOR을 사용하여 한줄의 코드로 만들 수 있다는 말씀이신가요?
XOR을 사용하여 이것저것 시도는 해 보았으나 같은 동작을 할 수 있는 코드는 아직 만들어내지 못했습니다.
저의 실력 부족인것 같습니다..
변수가 메모리에 저장되는 것을 알려주는 강의가 어떤강의였죠
1
466
1
메모리 주소 10진수로 출력
1
653
1
클래스 템플릿 특수화에서 boolalpha로 표현된 리턴값에 대해 질문이 있습니다.
1
499
1
여러가지 리턴 타입에 관한 강의가 어떤 걸까요?
1
534
1
메모리 주소에 관한 질분
0
679
1
인터페이스 클래스에서 reportError의 매개변수에 대해 궁금한 것이 있습니다.
0
549
1
형변환 오버로딩에서 const 관련 질문이 있습니다.
0
443
1
Digit 뒤에 reference를 사용하는 이유
0
510
1
4.2 전역 변수, 정적 변수, 내부 연결, 외부 연결
0
323
1
dat파일이...
0
539
1
TODO:대입 연산자 오버로딩에 대한 소스코드입니다.
0
644
1
복사 생성자 관련 질문이 있습니다.
0
454
1
수업 중 궁금한점이 있습니다.
1
390
1
라이브러리자체가 이해가 되지 않습니다.
0
561
1
마지막 예제 질문
0
302
1
증감연산자 위치에 따른 수행 순서 질문입니다.
0
375
1
단항 연산자 오버로딩에서 return 부분에 질문이 있습니다.
1
411
1
friend함수 관련 질문이 있습니다.
0
312
1
operator+ 정의부분에서 궁금한 것이 있습니다.
0
447
1
3분 17초 질문
0
350
1
함수에 값을 대입한다는 개념이 이해가 되지 않습니다.
0
448
1
int getvalue() const에서 const는 왜 뒤에 붙는건가요?
0
445
2
const Something &st에서 const를 빼면 안되나요?
0
300
1
friend함수는 다른 클래스의 멤버함수로 쓸 수 없나요??
1
493
1





