C++
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].
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 MoreAssume a class Window with accessor method getWidth that accepts no parameters and returns an integer.
LANGUAGE: C++ CHALLENGE: Assume a class Window with accessor method getWidth that accepts no parameters and returns an integer. Assume further an array of 3 Window elements named winarr, has been declared and initialized. Write a sequence of statements that prints out the width of the widest window in the array.
Read MoreWrite 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.
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 MoreRewrite the function body of this function so that instead of using iterating through the elements of the parallel arrays
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 MoreWrite the interface (.h file) of a class GasTank containing:
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 MoreWrite 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.
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 MoreWrite the implementation (.cpp file) of the Accumulator class of the previous exercise. The full specification of the class is
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 MoreWrite the implementation (.cpp file) of the Counter class of the previous exercise.
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 MoreCreating 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).
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 MoreGiven 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.
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 MoreGiven an ifstream object named input, associate it with a file named hostdata by opening the file for input.
LANGUAGE: C++ CHALLENGE: Given an ifstream object named input, associate it with a file named hostdata by opening the file for input.
Read MoreAssume you are given a variable, payRate of type Money (a structured type with two int fields, dollars and cents).
LANGUAGE: C++ CHALLENGE: Assume you are given a variable, payRate of type Money (a structured type with two int fields, dollars and cents). Write the necessary code to increase the effective value of payRate by $1.50. To do this you need to add 50 to cents and 1 to dollars but you ALSO must make…
Read More