• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

연습문제 답안 질문.

19.10.11 12:37 작성 조회수 238

2

강의 후 연습문제를 풀고 있는데, 맞게 코딩 하였는지 아닌지 확실하지 않습니다. 혹시 모범 답안이 있을까요? 아니면 여기에 작성한 코드를 적어도 될까요?

답변 3

·

답변을 작성해보세요.

1

강의를 만든지 일년이 넘었는데 이 문제 정답에 대한 질문이 처음 들어온 것 같습니다. 학생들이 정답을 먼저 보면 공부에 크게 방해가 된다고 생각을 해서 문제 정답을 공개하지 않는다는 방침을 가지고 있었는데 유료 강의를 구매해서 공부하시는 분들은 최대한 풀어보신 후에 답을 찾으실 것 같다는 생각이 들었습니다.

지금 작성하신 답안을 적어주시면 수정할 부분을 알려드리겠습니다. 아직 풀이가 끝나지 않으셨다면 최대한 노력해보신 후에 다시 질문으로 올려주셔도 됩니다.

0

여기 참고하세요. 

https://blog.naver.com/atelierjpro/221676103022

https://www.learncpp.com/cpp-tutorial/bit-manipulation-with-bitwise-operators-and-bit-masks/

0

최원철님의 프로필

최원철

질문자

2019.10.11

맞게 코딩했는지 궁금하여 올립니다.

#include <iostream>

#include <bitset>

using namespace std;

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;

if (my_article_flags & option_viewed)

{cout << " Read " << endl;}

else 

{cout << " Not read " << endl;}

if (my_article_flags | option_liked)

{cout << " Like " << endl;}

else

{cout << " fine " << endl;}

if (my_article_flags ^ option_liked)

{cout << "Dislike" << endl;}

else

{cout << " fine " << endl;}

if (my_article_flags & option_deleted)

{cout << " Deleted " << endl;}

else

{cout << " Still Saved " << endl;}

/*cout << bitset<8>(option_viewed) << "  " << int(option_viewed) << endl;

cout << bitset<8>(option_edited) << "  " << int(option_edited) << endl;

cout << bitset<8>(option_liked) << "  " << int(option_liked) << endl;

cout << bitset<8>(option_shared) << "  " << int(option_shared) << endl;

cout << bitset<8>(option_deleted) << "  " << int(option_deleted) << endl << endl;

cout << "No read = " << bitset<8>(my_article_flags) << endl;

my_article_flags |= option_viewed;

cout << "read = " << bitset<8>(my_article_flags) << endl;

my_article_flags |= option_liked;

cout << "click on like = " << bitset<8>(my_article_flags) << endl;

my_article_flags ^= option_liked;

cout << "Double click on like = " << bitset<8>(my_article_flags) << endl;

my_article_flags &= option_deleted;

cout << "Delete the article = " << bitset<8>(my_article_flags) << endl;*/

return 0;

}