# Category: C++

## Assume that name is a variable of type string that has been assigned a value. Write an expression whose value is the last character of the value of name. So if the value of name were “Blair” the expression’s value would be ‘r’.

LANGUAGE: C++ CHALLENGE: Assume that name is a variable of type string that has been assigned a value. Write an expression whose value is the last character of the value of name. So if the value of name were “Blair” the expression’s value would be ‘r’.

## In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + … + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333… and so on.

LANGUAGE: C++ CHALLENGE: In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + … + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333… and so on. Assume that n is an integer variable whose value is some integer N greater […]

## The dimensions (width and length) of room1 have been read into two variables: width1 and length1. The dimensions of room2 have been read into two other variables: width2 and length2. Write a single expression whose value is the total area of the two rooms.

LANGUAGE: C++ CHALLENGE: The dimensions (width and length) of room1 have been read into two variables: width1 and length1. The dimensions of room2 have been read into two other variables: width2 and length2. Write a single expression whose value is the total area of the two rooms.

## Diamond Pattern Write a program that displays the following pattern

1

LANGUAGE: C++ CHALLENGE: Diamond Pattern Write a program that displays the following pattern: * *** ***** ******* ***** *** * Output description: Seven lines of output as follows: The first consists of 3 spaces followed by a star. The second line consists of 2 spaces followed by a 3 stars. The third consists of one space followed […]

## Land Calculation One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with 389,767 square feet.

LANGUAGE: C++ CHALLENGE: Land Calculation One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with 389,767 square feet.

## Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive.

LANGUAGE: C++ CHALLENGE: Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates , it prints out the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even […]

## You are given a 6×8 (6 rows, 8 columns) array of integers , x, already initialized and three integer variables : max, i and j.

LANGUAGE: C++ CHALLENGE: You are given a 6×8 (6 rows, 8 columns) array of integers , x, already initialized and three integer variables : max, i and j. Write the necessary code so that max will have the largest value in the array x.

## Given an array arr of type int , along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

LANGUAGE: C++ CHALLENGE: Given an array arr of type int , along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

## Write a single statement that assigns a new value to the element of the array indexed by j. This new value should be equal to twice the value stored in the next element of the array (i.e. the element after the element indexed by j).

LANGUAGE: C++ CHALLENGE: An array of int named a that contains exactly five elements has already been declared and initialized . In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3. Write a single statement that assigns a new value to the element of the array […]

## 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 […]