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

List of all available Websheets


Viewing cpp/cs104/classes/this_scope 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
 
Examine the <tt>setValue()</tt> function below.  What is wrong with it?
<p>
Fix it by preceding the data member with <tt>this-></tt>
Engine
Template / Reference solution
 
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wself-assign"
#include <iostream>
using namespace std;
class Item {
public:
   void setValue(int value);
   int getValue() const { return value; }
private:
   int value;
};
void Item::setValue(int value)
{
\[
REDACTED
\show:
   value = value;
]\
}
int main()
{
   Item x;
   x.setValue(2);
   // Now print out the value...expecting 2
   cout << x.getValue() << endl;
   return 0;
}
#pragma clang diagnostic pop#include <iostream>
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 [{}]
 
[{}]
Is example?
i.e., just a demo
remove
Remove default compiler flag(s)
json list of flags
see default_cppflags
e.g. ["-Wno-write-strings"]
 
["-Wno-shadow", "-Wno-self-assign"]
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'.