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

List of all available Websheets


Viewing cpp/functions/draw_square 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 a function <tt>drawSquare</tt> that takes an integer and char parameter
and prints a square:
the integer indicates the side length of the square to draw, and
the character indicates what character to use to draw the square.
See the example below.
Public permissions remove
Remarks
Comments, history, license, etc.
 
Originally by Mark Redekopp (redekopp@usc.edu) and Dave Pritchard (daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
// prints an ASCII square to stdout (monitor) 
// of side length, s, using character, c
//  e.g. calling drawSquare(4, '*') should yield
//  ****
//  *  *
//  *  *
//  ****
 \[ void ]\ drawSquare (\[ int s, char c ]\) {
\[
  for(int i=0; i < s; i++){
    for(int j=0; j < s; j++){
      if(i==0 || i == s-1 || j==0 || j==s-1){
        cout << c;
      }
      else {
        cout << " ";
      }
    }
    cout << endl;
  }
]\
}
C++ test suite
See manual
 
[
   ["check-function", "drawSquare", "void", ["int", "char"]],
   ["call-function", "drawSquare", ["3", "'*'"]],
   ["call-function", "drawSquare", ["10", "'+'"]],
   ["call-function", "drawSquare", ["30", "'-'"]]
]
Solution visibility 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'.