|Question||Plz me find solutiona for this cs 115 question .
[5 marks] Suppose was applied tosearch for 24 in the shown below.Explain step by step what the method will do. Will the method find24?
2. [4 marks] Trace the operation of the algorithm on the following array (show the result ofevery iteration, even if there is no change):
3. [3 marks]
Programmer X declared a global variable in a file namedCounter.cpp:
unsigned int counter_value;
Programmer Y wrote main.cpp to attempt to change counter_valuein Counter.cpp:
unsigned int counter_value;
counter_value = 1909;
(a) Write on the above code to show achange that programmer Y can make to gain access to counter_value(the one in Counter.cpp) and mark your change with Y.
(b) Write on the above code to show a changethat programmer X can make to prevent Y from accessingcounter_value (the one in Counter.cpp) and mark your change withX.
(c) If the changes from (a) and (b) areboth made, which programmer succeeds, X or Y? ___
Suppose a C++ is needed to represent amammal in a computer program. The class should have three fieldsfor a (represented by a positiveinteger), a , and (a real value representing the number ofkilograms), all inaccessible outside the class.
(a) [6 marks] Write a for thisclass using the most suitable data types, including a and an . The constructors shouldbe accessible outside the class.
(b) [4 marks] Write the of afunction that sets a mammal’s weight to a suitable value passed asa parameter. Assume that the prototype for this function has beenadded to the class described in part (a). Make the functionconstant if appropriate.
(c) [1 marks] Show how the coulddeclare a variable of the Mammal type using the initializingconstructor for a dog weighing 18.09 kg born in 2013.
(d)[1 marks] Show how the coulddeclare an array called myZoo to contain 125 mammals.
(e) [2 marks] Write the for a function named searchMammalsthat searches an array of mammals for a mammal with a particularspecies name and returns the index of the first instance of thatspecies it finds (and -1 if it is not found). For efficiency, usepass-by-reference for the array, but guarantee that the array isnot changed. Pass the number of mammals in the array as aparameter. You do not have to write the function.
(a) [3 marks] Write a declaration for a C++ structured-recordtype named Counter that includes two integer fields namedcounter_value and counter_upper.
(b) [6 marks] The counterInitialize function can be used toinitialize any Counter variable to any appropriate given values forthe counter value and its upper bound. The provided values shouldbe nonnegative and the counter value should be less than its upperbound. Write a comment that describes the counterInitializefunction in the style described in the CS 115 “Program OrganizationPrinciples” notes.
// counterInitialize//// Purpose: //// Parameter(s):////////// Precondition:////// Returns://// Side Effect://
[5 marks] the following terms clearlyand concisely. Point form may be used.
(b) Modular programming
(c) Top-down design
(d) Loop invariant
(e) Selection sort
(a) [2 marks] Use typedef to define aSpreadsheet type corresponding to a 2-dimensional array of positiveor negative integers with dimensions NUMROWS and NUMCOLS, assumingNUMROWSand NUMCOLS have been defined as constants.
(b) [6 marks] Write a calledwriteSpreadsheet that, for example, can be called by
writeSpreadsheet (my_array, 21, 5, “my_file.txt”);
to write 21 lines of 5 integers each into a file called”my_file.txt” from a Spreadsheet my_array.
(c) [1 mark] EITHER explain why your writeSpreadsheet functionin part (b) facilitates ORwrite a line of code that could be added to facilitate design bycontract and explain its purpose.
(d) [1 mark] EITHER explain why your writeSpreadsheet functionin part (b) facilitates ORwrite a line of code that could added to facilitate defensiveprogramming and explain its purpose.
. . .