Write a statement  that assigns  x the value  k*(k-1)*(k-2)*…*3*2*1 by calling the fact function and multiplying its return value  by k.

C++

LANGUAGE: C++ CHALLENGE: Assume  the availability of a function called fact. The function receives an int argument  and returns an int value . If the argument  is one or smaller, it returns the integer  value  one. Otherwise it returns the product  of all the integers  from one to its argument . So the value  of fact(4) is 1*2*3*4 and…

Read More

The elements of an integer -valued array can be set to 0 (i.e., the array can be cleared) recursively as follows: An array of size 0 is already cleared; Otherwise, set the first element of the array to 0, and clear the rest of the array Write a void function named clear that accepts an integer array, and the number of elements in the array and sets the elements of the array to 0.

C++

LANGUAGE: C++ CHALLENGE: The elements  of an integer -valued  array  can be set to 0 (i.e., the array  can be cleared) recursively as follows: An array  of size 0 is already  cleared; Otherwise, set the first element  of the array  to 0, and clear the rest of the array  Write a void function named  clear that…

Read More

Write a recursive, string -valued  function, reverse, that accepts a string  and returns a new string  consisting of the original string  in reverse.

C++

LANGUAGE: C++ CHALLENGE: Write a recursive, string -valued  function, reverse, that accepts a string  and returns a new string  consisting of the original string  in reverse. For example, calling reverse with the string  goodbye returns the string  eybdoog. Reversing a string  involves: No action if the string  is empty or has only 1 character  (reversing a…

Read More

Declare  an array  named  winarr, consisting of 3 Window objects , where the first element  is an 80×20 window, the second a 10×10 window, and the third a 133×40 window.

C++

LANGUAGE: C++ CHALLENGE: Assume  a class  Window with a constructor  that accepts two integer  arguments : width and height (in that order). Declare  an array  named  winarr, consisting of 3 Window objects , where the first element  is an 80×20 window, the second a 10×10 window, and the third a 133×40 window.

Read More

Define a derived class  WindowWithBorder that contains a single additional integer  instance variable  named  borderWidth, and has a constructor  that accepts an integer  parameter  which is used to initialize  the instance variable.

C++

LANGUAGE: C++ CHALLENGE: Assume  the existence of a Window class  with a function getWidth that returns the width of the window. Define a derived class  WindowWithBorder that contains a single additional integer  instance variable  named  borderWidth, and has a constructor  that accepts an integer  parameter  which is used to initialize  the instance variable . There is…

Read More

Define a derived class , ApartmentBuilding that contains four (4) data members: an integer  named  numFloors, an integer  named  unitsPerFloor, a boolean  named  hasElevator, and a boolean  named  hasCentralAir. There is a constructor  containing parameters  for the initialization  of the above variables  (in the same order as they appear above).

C++

LANGUAGE: C++ CHALLENGE: Assume  the existence of a Building class . Define a derived class , ApartmentBuilding that contains four (4) data members: an integer  named  numFloors, an integer  named  unitsPerFloor, a boolean  named  hasElevator, and a boolean  named  hasCentralAir. There is a constructor  containing parameters  for the initialization  of the above variables  (in the same order…

Read More

Define a derived class , CameraPhone that contains two data members: an integer  named , imageSize, representing the size in megapixels of each picture, and an integer  named  memorySize, representing the number of gigabytes in the camera’s memory.

C++

LANGUAGE: C++ CHALLENGE: Assume  the existence of a Phone class . Define a derived class , CameraPhone that contains two data members: an integer  named , imageSize, representing the size in megapixels of each picture, and an integer  named  memorySize, representing the number of gigabytes in the camera’s memory. There is a constructor  that accepts two integer  parameters …

Read More