{"action":"created","issue":{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/255","labels_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/255/comments","events_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/255/events","html_url":"https://github.com/Mooophy/Cpp-Primer/pull/255","id":80851926,"number":255,"title":"Update Ex17_11_12_13 (p728)","user":{"login":"gaufung","id":11272110,"avatar_url":"https://avatars.githubusercontent.com/u/11272110?v=3","gravatar_id":"","url":"https://api.github.com/users/gaufung","html_url":"https://github.com/gaufung","followers_url":"https://api.github.com/users/gaufung/followers","following_url":"https://api.github.com/users/gaufung/following{/other_user}","gists_url":"https://api.github.com/users/gaufung/gists{/gist_id}","starred_url":"https://api.github.com/users/gaufung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaufung/subscriptions","organizations_url":"https://api.github.com/users/gaufung/orgs","repos_url":"https://api.github.com/users/gaufung/repos","events_url":"https://api.github.com/users/gaufung/events{/privacy}","received_events_url":"https://api.github.com/users/gaufung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-26T08:13:56Z","updated_at":"2015-05-26T22:10:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/pulls/255","html_url":"https://github.com/Mooophy/Cpp-Primer/pull/255","diff_url":"https://github.com/Mooophy/Cpp-Primer/pull/255.diff","patch_url":"https://github.com/Mooophy/Cpp-Primer/pull/255.patch"},"body":"Create a Data Strucure for Quiz"},"comment":{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/comments/105683282","html_url":"https://github.com/Mooophy/Cpp-Primer/pull/255#issuecomment-105683282","issue_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/255","id":105683282,"user":{"login":"Mooophy","id":5942966,"avatar_url":"https://avatars.githubusercontent.com/u/5942966?v=3","gravatar_id":"","url":"https://api.github.com/users/Mooophy","html_url":"https://github.com/Mooophy","followers_url":"https://api.github.com/users/Mooophy/followers","following_url":"https://api.github.com/users/Mooophy/following{/other_user}","gists_url":"https://api.github.com/users/Mooophy/gists{/gist_id}","starred_url":"https://api.github.com/users/Mooophy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mooophy/subscriptions","organizations_url":"https://api.github.com/users/Mooophy/orgs","repos_url":"https://api.github.com/users/Mooophy/repos","events_url":"https://api.github.com/users/Mooophy/events{/privacy}","received_events_url":"https://api.github.com/users/Mooophy/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T22:10:14Z","updated_at":"2015-05-26T22:10:14Z","body":"@gaufung \r\nNot bad.\r\n\r\nI fixed the indentations and polished the coding and commenting style like below. Is it ok:\r\n```cpp\r\n/***************************************************************************\r\n*  @file       main.cpp\r\n*  @author     gau fung\r\n*  @date       25  May 2015\r\n*  @remark     This code is for the exercises from C++ Primer 5th Edition\r\n*  @note\r\n***************************************************************************/\r\n//!\r\n//! Exercise 17.11:\r\n//! Define a data structure that contains an integral object to track responses\r\n//! to a true/false quiz containing 10 questions. What changes, if any, would\r\n//! you need to make in your data structure if the quiz had 100 questions?\r\n//!\r\n//      std::bitset<10> reponses;\r\n//      std::bitset<100> reponses2;\r\n//!\r\n//! Exercise 17.12:\r\n//! Using the data structure from the previous question, write a function that\r\n//! takes a question number and a value to indicate a true/false answer and\r\n//! updates the quiz results accordingly.\r\n//!\r\n//! Exercise 17.13:\r\n//! Write an integral object that contains the correct answers for the\r\n//! true/false quiz. Use it to generate grades on the quiz for the data\r\n//! structure from the previous two exercises.\r\n//!\r\n\r\n#ifndef QUIZ\r\n#define QUIZ\r\n#include <iostream>\r\n#include <bitset>\r\n#include <utility>\r\n#include <string>\r\n#include <iostream>\r\n\r\n//class Quiz\r\ntemplate<std::size_t N>\r\nclass Quiz\r\n{\r\npublic:\r\n    //constructors\r\n    Quiz() = default;\r\n    Quiz(std::string& s) :bitquiz(s){}\r\n\r\n    //generate grade\r\n    template<std::size_t M>\r\n    friend std::size_t grade(Quiz<M> const&, Quiz<M> const&);\r\n\r\n    //print\r\n    template<std::size_t M>\r\n    friend std::ostream& operator<<(std::ostream&, Quiz<M> const&);\r\n\r\n    //update bitset\r\n    void update(std::pair<std::size_t, bool>);\r\nprivate:\r\n    std::bitset<N> bitquiz;\r\n};\r\n#endif\r\n\r\ntemplate<std::size_t N>\r\nvoid Quiz<N>::update(std::pair<std::size_t, bool> pair)\r\n{\r\n    bitquiz.set(pair.first, pair.second);\r\n}\r\n\r\ntemplate<std::size_t M>\r\nstd::ostream& operator<<(std::ostream& os, Quiz<M> const& quiz)\r\n{\r\n    os << quiz.bitquiz;\r\n    return os;\r\n}\r\n\r\ntemplate<std::size_t M>\r\nstd::size_t grade(Quiz<M> const& corAns, Quiz<M> const& stuAns)\r\n{\r\n    auto result = stuAns.bitquiz ^ corAns.bitquiz;\r\n    result.flip();\r\n    return result.count();\r\n}\r\n\r\n\r\nint main()\r\n{\r\n    //Ex17_11\r\n    std::string s = \"1010101\";\r\n    Quiz<10> quiz(s);\r\n    std::cout << quiz << std::endl;\r\n\r\n    //EX17_12\r\n    quiz.update(std::make_pair(1, true));\r\n    std::cout << quiz << std::endl;\r\n\r\n    //Ex17_13\r\n    std::string answer = \"10011\";\r\n    std::string stu_answer = \"11001\";\r\n    Quiz<5> ans(answer), stu_ans(stu_answer);\r\n    std::cout << grade(ans, stu_ans) << std::endl;\r\n\r\n    system(\"pause\");\r\n    return 0;\r\n}\r\n```"}}