View Single Post
Old 07-22-2025, 04:06 PM   #9
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,139
Karma: 60406498
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by kust View Post
I think this is what you meant by CSS

PHP Code:
class="heading4CodeSnippetTitle" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:002" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:002"><strong data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:003" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:003">Fig6.7</strong> | Die-rolling program using an <code data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:004" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:004">array</codeinstead of <code data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:005" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:005">switch</code>.</h4><div class="pearson-component codeSnippet" data-programlanguage="C++" data-startnumber="1" data-type="codeSnippet" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:006" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:006"><pre style="display: block; overflow-x: auto; padding: 0.5em; color: rgb(51, 51, 51); background: rgb(248, 248, 248);"><code><span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:007" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:007">//*fig06_07.cpp</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:008" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:008">//*Die-rolling*program*using*an*array*instead*of*switch.</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:009" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:009">#include*&lt;format&gt;</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:010" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:010">#include*&lt;iostream&gt;</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:011" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:011">#include*&lt;array&gt;</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:012" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:012">#include*&lt;random&gt;</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:013" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:013">***</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:014" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:014">int*main()*{</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:015" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:015">***//*set*up*random-number*generation</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:016" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:016">***std::random_device*rd;*//*used*to*seed*the*default_random_engine</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:017" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:017">***std::default_random_engine*engine{rd()};*//*rd()*produces*a*seed</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:018" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:018">***std::uniform_int_distribution*randomDie{1,*6};</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:019" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:019">***</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:020" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:020">***constexpr*size_t*arraySize{7};*//*ignore*element*zero</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:021" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:021">***std::array&lt;int,*arraySize&gt;*frequency{};*//*initialize*to*0s</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:022" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:022">***</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:023" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:023">***//*roll*die*60,000,000*times;*use*die*value*as*frequency*index</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:024" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:024">***for*(int*roll{1};*roll*&lt;=*60'000'000;*++roll)*{</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:025" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:025">******++frequency.at(randomDie(engine));</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:026" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:026">***}</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:027" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:027">***</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:028" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:028">***std::cout*&lt;&lt;*std::format("{}{:&gt;13}\n",*"Face",*"Frequency");</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:029" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:029">***</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:030" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:030">***//*output*each*array*element</span>
<span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:031" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:031">***for*(size_t*face{1};*face*&lt;*frequency.size();*++face)*{</span>
<
span class="computerLine" data-versionurn="urn:pearson:work:d076a113-cc38-4299-93e0-22cb1af1e5a0:032" id="urn:pearson:entity:4808e22d-eaaf-4982-a5ef-41537c3a1eae:032">******std::cout*&lt;&lt;*std::format("{:&gt;4}{:&gt;13}\n",*face,*frequency.at(face));</span
That is NOT a CSS
theducks is offline   Reply With Quote