subject

In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0. For example, in Matlab: begin code 1 V = [1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1); end code For each of the following tasks test your code for many different values and lengths of V. (a) Write code using a for loop that will flip every third entry of Vie make the entry 0 if it is 1 or make it 1 if it is 0). This loop should modify V directly. For example V - ti, 1, 0, 1, 0, 1, 1, 0, 1) would become V = [1, 1, 1, 1, 0, 0, 1, 0, 0).
(b) Write code using a for loop that will flip every third instance of the number 1 in V. This loop should modify V directly. For example V - (1, 1, 0, 1, 0, 1, 1, 0, 1) would become V - 11, 1, 0, 0, 0, 1, 1, 0, 0).
(c) Write code using a for loop that will assign to the variable numChanges the number of times that successive elements of V change from 0 to 1 or from 1 to 0. For example if V - 10, 0, 1, 1] then numChanges would equal 1 and if V - (0, 1, 0, 1) then numChanges would equal 3
(d) Write code using a for loop that assigns to a variable nunOccurs the number of times a certain pattern, specified by the variable pattern occurs in V. For this problem, overlap is allowed, i. e. if pattern - [0, 1, 0) then the last 0 of an occurrence of [0, 1, o can be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then two instances of [0, 1, 0 should be counted and numOccurs should equal 2.
(e) Write code using a while loop that will assign to the variable numDccuraSep the number of times a certain pattern of O's and 1's occurs separately in V. The variable pattern gives 3 of 4 the certain pattern to look for. For this problem overlap is not allowed, ie if pattern - [0, 1, 0] then the last 0 of an occurrence of 10, 1. O cannot be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then only one instance of [0, 1, 0 should be counted and numOccursSep should equal 1.
(f) Write code using a while loop that will replace a sequence, specified by the variable seqremove, with a sequencespecified by the variable seqNew seqRemove and seqNew are the same size. For this problem once a sequence is replaced, only elements following the replaced sequence should be considered. For example if seqRemove - [0, 0], seqNew - [1, 0] and V - (1, 0, 0, 0, 1), then V should become [1, 1.0, 0, 1) and not [1, 1, 1,0, 11

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:30, paolaviviana
Experimental data that is expressed using numbers is said to be
Answers: 1
image
Computers and Technology, 23.06.2019 11:50, itaheart101
While preforming before operation pmcs, you notice the front right tire appears slightly under-inflated. what is the proper action?
Answers: 3
image
Computers and Technology, 24.06.2019 03:00, greenhappypiggies
Using a conditional expression, write a statement that increments numusers if updatedirection is 1, otherwise decrements numusers. ex: if numusers is 8 and updatedirection is 1, numusers becomes 9; if updatedirection is 0, numusers becomes 7.
Answers: 1
image
Computers and Technology, 24.06.2019 11:20, brittanybyers122
Print "censored" if userinput contains the word "darn", else print userinput. end with newline. ex: if userinput is "that darn cat.", then output is: censoredex: if userinput is "dang, that was scary! ", then output is: dang, that was scary! note: if the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "program end never reached." the system doesn't print the test case that caused the reported message.#include #include using namespace std; int main() {string userinput; getline(cin, userinput); int ispresent = userinput. find("darn"); if (ispresent > 0){cout < < "censored" < < endl; /* your solution goes here */return 0; }
Answers: 3
You know the right answer?
In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0...

Questions in other subjects:

Konu
Mathematics, 15.01.2020 05:31
Konu
English, 15.01.2020 05:31
Konu
Mathematics, 15.01.2020 05:31