Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/functions/overload by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Define two functions named <tt>rangesize</tt>.
<ol>
<li>
<tt>int rangesize(int start, int end)</tt> <br> This function should return the number of integers in the "inclusive" set 
$\{\textrm{start}, \textrm{start}+1, \dotsc, \textrm{end}\}$, which is <tt>end - start + 1</tt>. (e.g. there are
   3 integers in the inclusive set of integers from 4 to 6)
<li>
<tt>double rangesize(double start, double end)</tt> <br> This function should return the <strong>length</strong> of the 
interval $[\textrm{start},\textrm{end}]$ of real numbers, which is <tt>end - start</tt>.
</ol>
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
\[
int rangesize(int start, int end);
double rangesize(double start, double end);
   
int rangesize(int start, int end) {
   return end-start+1;
}
double rangesize(double start, double end) {
   return end-start;
}
\show:
int rangesize(int start, int end);
double rangesize(double start, double end);
int rangesize(int start, int end) {
   return end-start+1;
}
double rangesize(double start, double end) {
   return end-start;
}
]\
int main() {
   cout << showpoint;
   cout << rangesize(10, 20) << endl; // 11
   cout << rangesize(3.4, 6.2) << endl; // 2.8
   cout << rangesize(8, 30) << endl; // 23
   cout << rangesize(8.0, 30.0) << endl; // 22.0
   return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[
   {}
]
Solution visibility remove
Is example?
i.e., just a demo
remove


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.