Activecode Exercises

Answer the following Activecode questions to assess what you have learned in this chapter.

Construct a block of code that changes the first element of vec to a 6, multiplies the third element of vec by 2, and increments the last element of vec by 1 (in that order). This should work no matter what vec is.

Below is one way to construct the code.

Construct a block of code that creates a vector called digs whose elements are 7, 8, 7, 8. Then access elements to change the digs to contain the elements 7, 4, 7, 4. Important: Change the 8’s to 4’s in order of increasing index.

Below is one way to construct the code.

Construct a block of code that creates a vector called nums whose elements are five 1’s. Then make a copy of this vector called digits, and use vector operations to change digits to {1, 2, 3}.

Below is one way to construct the code.

Construct a block of code that loops over a vector called numbers and transforms the vector so each element is doubled.

Below is one way to construct the code.

Suppose you have the vector words. Construct a block of code that transforms the vector to: vector<string> words = {"cAr", "cAt", "switch", "mArio"}. Write the necessary code.

Below is one way to construct the code.

Suppose you run Club Keno, and you are in charge of picking the 20 random numbered balls between 1 and 80. Construct a block of code that chooses these random numbers, then saves them to a vector called keno.

Below is one way to construct the code

Suppose you have the defined vector album. Construct a block of code that counts how many songs in album start with b. Write the necessary code.

Below is one way to construct the code

Suppose you have the defined vectors, temps and precip. Your family will go to the beach if the temperature at least 75 degrees and the chance of precipitation is less than 50%. Construct a block of code that counts how many days your family can hit the beach on your vacation.

Below is one way to construct the code

Suppose you have the defined vector nouns. Construct a block of code that creates a vector of the proper nouns in nouns. Use the isupper function to check if a letter is uppercase.

Below is one way to construct the code. For this question, the isupper function is not defined but it returns a bool determined by an input of a string.

Suppose you have the already defined howMany function and excl vector. Construct a block of code that counts how many times “.”, “!”, and “?” occur in excl. Save the counts to a vector with “.” count as the first element, “!” count as the second, and “?” count as the third.

Below is one way to construct the code

You have attempted of activities on this page