<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Sample Code on MSOE OpComp</title><link>https://msoeopcomp.org/samples/</link><description>Recent content in Sample Code on MSOE OpComp</description><generator>Hugo</generator><language>en-us</language><copyright>{year} MSOE</copyright><atom:link href="https://msoeopcomp.org/samples/index.xml" rel="self" type="application/rss+xml"/><item><title>Sample Code: C++</title><link>https://msoeopcomp.org/samples/cpp/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://msoeopcomp.org/samples/cpp/</guid><description>&lt;p&gt;Common input, output and arithmetic fragments for C++. See also the
&lt;a href="../python/"&gt;Python&lt;/a&gt; and &lt;a href="../java/"&gt;Java&lt;/a&gt; versions.&lt;/p&gt;
&lt;p&gt;The fragments assume &lt;code&gt;using namespace std;&lt;/code&gt; and are meant to go inside
&lt;code&gt;main&lt;/code&gt;. The headers each one needs are listed with it; &lt;code&gt;&amp;lt;iostream&amp;gt;&lt;/code&gt; and
&lt;code&gt;&amp;lt;string&amp;gt;&lt;/code&gt; are needed almost everywhere:&lt;/p&gt;</description></item><item><title>Sample Code: Java</title><link>https://msoeopcomp.org/samples/java/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://msoeopcomp.org/samples/java/</guid><description>&lt;p&gt;Common input, output and arithmetic fragments for Java. See also the
&lt;a href="../python/"&gt;Python&lt;/a&gt; and &lt;a href="../cpp/"&gt;C++&lt;/a&gt; versions.&lt;/p&gt;
&lt;p&gt;The fragments are meant to go inside &lt;code&gt;main&lt;/code&gt;. The &lt;code&gt;Scanner&lt;/code&gt; ones need&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; java.util.Scanner;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;at the top of the file, and create the scanner once:&lt;/p&gt;</description></item><item><title>Sample Code: Python</title><link>https://msoeopcomp.org/samples/python/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://msoeopcomp.org/samples/python/</guid><description>&lt;p&gt;Common input, output and arithmetic fragments for Python 3. See also the
&lt;a href="../java/"&gt;Java&lt;/a&gt; and &lt;a href="../cpp/"&gt;C++&lt;/a&gt; versions.&lt;/p&gt;
&lt;details class="toc" open&gt;
&lt;summary&gt;&lt;span class="title"&gt;Contents&lt;/span&gt;&lt;/summary&gt;
&lt;div class="inner"&gt;&lt;nav id="TableOfContents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#reading-input"&gt;Reading input&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#one-value-per-line"&gt;One value per line&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#several-values-on-one-line"&gt;Several values on one line&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#a-list-of-numbers-on-one-line"&gt;A list of numbers on one line&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#other-separators"&gt;Other separators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#a-count-followed-by-that-many-lines"&gt;A count followed by that many lines&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#every-line-until-the-end-of-the-input"&gt;Every line until the end of the input&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#reading-from-a-file"&gt;Reading from a file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#working-with-numbers"&gt;Working with numbers&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#converting-between-float-and-int"&gt;Converting between float and int&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#division"&gt;Division&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rounding-up-and-down"&gt;Rounding up and down&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#other-handy-operations"&gt;Other handy operations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#math-functions"&gt;Math functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#formatting-output"&gt;Formatting output&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#example-average-of-the-input"&gt;Example: average of the input&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#example-sorting-and-searching"&gt;Example: sorting and searching&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id="reading-input"&gt;Reading input&lt;/h2&gt;
&lt;h3 id="one-value-per-line"&gt;One value per line&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;input()&lt;/code&gt; returns the next line as a string (without the newline), so
convert it to the type you need:&lt;/p&gt;</description></item></channel></rss>