Given an array a and a variable n that contains the number of elements in a, write an expression for the corresponding element of a[i].

C++

LANGUAGE: C++ CHALLENGE: We informally define the term “corresponding element” as follows: The first element in an array and the last element of the array are corresponding elements. Similarly, the second element and the element just before the last element are corresponding elements. The third element and the element just before the element just before the…

Read More

Write the definition of a function named averager that receives a double parameter and returns– as a double — the average value that it has been passed so far.

C++

LANGUAGE: C++ CHALLENGE: Write the definition of a function named averager that receives a double parameter and returns– as a double — the average value that it has been passed so far. So, if you make these calls to average, averager(5.0), averager(15.0), averager(4,3), the values returned will be (respectively): 5.0, 10.0, 8.1.

Read More

Rewrite the function body of this function so that instead of using iterating through the elements of the parallel arrays

C++

LANGUAGE: C++ CHALLENGE: consider the testPIN function used in Program 7-21. For convenience, we have reproduced the code for you below. Rewrite the function body of this function so that instead of using iterating through the elements of the parallel arrays, it returns true or false by calling countMatches the function defined in the previous…

Read More

Write the interface (.h file) of a class GasTank containing:

C++

LANGUAGE: C++ CHALLENGE: Write the interface (.h file) of a class GasTank containing: A data member named  amount of type double. A data member named  capacity of type double. A constructor that accepts a parameter of type double. A function named  addGas that accepts a parameter of type double and returns no value. A function named …

Read More

Write the implementation (.cpp file) of the  Averager class of the previous exercise. The full specification of the class is: An data member named  sum of type integer.

C++

LANGUAGE: C++ CHALLENGE: Write the implementation (.cpp file) of the Averager class of the previous exercise. The full specification of the class is: An data member named  sum of type integer. An data member named  count of type integer. A constructor with no parameters. The constructor initializes the data members sum and the data member  count…

Read More

Write the implementation (.cpp file) of the  Accumulator class of the previous exercise. The full specification of the class is

C++

LANGUAGE: C++ CHALLENGE: Write the implementation (.cpp file) of the  Accumulator class of the previous exercise. The full specification of the class is: An data member named  sum of type integer. A constructor that accepts no parameters. The constructor initializes the data member sum to 0. A function named getSum that accepts no parameters and returns an…

Read More

Write the implementation (.cpp file) of the Counter class of the previous exercise.

C++

LANGUAGE: C++ CHALLENGE: Write the implementation (.cpp file) of the Counter class of the previous exercise. The full specification of the class is: A data member  counter of type int. An data member named limit of type int. A static  int data member named  nCounters which is initialized to 0. A constructor that takes two  int arguments and assigns the…

Read More

Creating objects of the Currency class require a name (string), a currency symbol (string) and the number of decimal places (integer) usually associated with the currency (in that order).

C++

LANGUAGE: C++ CHALLENGE: Creating objects of the Currency class require a name (string), a currency symbol (string) and the number of decimal places (integer) usually associated with the currency (in that order). Creating objects of the Money class require a Currency object, and the actual amount (integer) (in that order). Define an object of type…

Read More

Given three variables, k, m, n, of type int that have already been declared and initialized, write some code that prints each of them left-justified in a 9-position field on the same line.

C++

LANGUAGE: C++ CHALLENGE: Given three variables, k, m, n, of type int that have already been declared and initialized, write some code that prints each of them left-justified in a 9-position field on the same line. For example, if their values were 27, 987654321, -4321, the output would be: |27xxxxxxx987654321-4321xxxx NOTE: The vertical bar,  |…

Read More