211-lab-review
.pdf
keyboard_arrow_up
School
University of Illinois, Chicago *
*We aren’t endorsed by this school
Course
211
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
4
Uploaded by UltraFang12731
Question
: When does it return true? Consider the following function
bool mystery(const char s1[ ], const char s2[ ])
{
int i=0; bool result;
while ( s1[i] == s2[i] &&
s1[i] != '\0' &&
s2[i] != '\0' )
++i;
if ( s1[i] == '\0' && s2[i] == '\0' )
result = true;
else
result = false;
return result;
}
Options:
When s1 is a different length than s2
When we successfully copy s2 into s1
When s1 and s2 are the same length
When s1 and s2 have the same length and same characters
Answer
: When s1 and s2 have the same length and same characters
Question
: What does it do? Consider the following function:
void
mystery2
(char
s1[],
char
s2[]) {
int i;
for(i=0; s2[i]!='\0'; ++i)
s1[i] = s2[i];
s1[i] = '\0';
}
Options:
Compare s1 and s2 WRONG
Copy s2 into s2 COULD BE THIS
Copy s1 into s2 WRONG
Overwrite s1 and s2 with NULL characters OR THIS
Question
: C-strings automatically grow or shrink, depending on the need?*
Answer
: False
Question
: Assume we are writing a program to grow a dynamic array. Consider the following
options: (How many of the above options would work correctly?)
Options:
Declare a larger array statically within a function.
Allocate space using malloc
Allocate space using calloc
Allocate space using realloc
Answer
: 3 of them would work
Question
: Imagine that we have a variable declared as:
int * pBestArray = NULL;
And we have passed it to function
void setIt(...)
which changes it to point to some array, where that change is reflected back to the calling part of
the program. How would we declare the parameter in the function declaration?
Options:
void setIt( int pBestArray);
void setIt( int *pBestArray);
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Draw a flowchart for the Frazzle function.
arrow_forward
Perform in C#
arrow_forward
10
arrow_forward
Consider the following function:
void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?
arrow_forward
How do I go about solving this?
arrow_forward
Write a recursive function 'void reverse(string &word)' that reverses the given input string.
string name = "lexa";
reverse(name);
cout << name << endl; //should display "axel".
without using the following loops:
-no for loops
-no while loops
-no do-while's
-no while-do's
-no for-while's
-no while-for-do's
arrow_forward
// Description: Write a program that outputs a root of a given function f(x) by using a bi-section method.
// f(x) = x3 + 5x2 +7x +2
arrow_forward
Q1: Complete the following program by writing its functions:
static void Main (....)
{
double z; long P-1; int a, b, c=-4;
int[] f = {1, 3, 9, 10, 12, 7, 8};
int g = abs (c) ;
Prime (f,out b) ;
Find (g, out z);
Power (a [1] , a[2],ref p); // where P= a[1]a(2]
double d=fact(g);
// return absolute value of C
// b=the average of Prime numbers in f
// z = 1! + 2! + ...
+ g!
// return the factorial of x using
// recursion principle
// print the maximum value of f
Маx (f) ;
Console.Write ("{0}: {1}: {2}:{3}: {4}",g,b, z,p,d);
arrow_forward
Part (a)
Write a python function that computes the binomial coefficient ("). The function should return the correct answer for any positive integer n and k where
k=m
pass
Part (c)
Suppose that the number of people in the trial is 100. Then:
• Plot a curve that shows how the probability of type 1 error changes with the choice of m, for m = 1,...n assuming that the null hypothesis holds (in red),
• On the same picture, plot the probability of type 2 error vs the value of m in the case in which the new drug is effective with proability 0.68 (in blue).
You can plot the two curves using matplotlib.pyplot. You can select the color by passing color='r' or color='b' to the plt.plot() function.
[4]: n - 100
# your code here
def plot_curve ():
pass
[5]: plot_curve()
Part (d)
Based on the picture above, what value of m do you think would be suitable to keep both type 1 and type 2 error small at the same time?
(You may assume that the company claims the new drug has 68% accuracy)
[6]: # your…
arrow_forward
Q1: Complete the following program by writing its functions:
static void Main (... .)
{
double z; long P=1; int a, b, c=-4;
int[] f = {1, 3, 9, 10, 12, 7, 8};
int g = abs (c);
Prime (f, out b) ;
Find (g, out z);
Power (a [1], a[2], ref p); // where P= a[1]a121
double d=fact (g) ;
// return absolute value of c
// b=the average of Prime numbers in f
// z = 1! + 2! +
+ g!
...
// return the factorial of x using
// recursion principle
// print the maximum value of f
Max (f) ;
Console.Write ("{0}: {1}:{2}:(3} : {4}",g,b, z,p,d);
arrow_forward
The following function will correctly return true if its argument is an odd
integer
bool Isodd (int x) {
return (x / 2 == 1);
}
True
False
arrow_forward
Solution in java
arrow_forward
Write a recursive function definition for the following function: int squares(int n); //Precondition: n >= 1 //Returns the sum of the squares of numbers 1 through n. For example, squares(3) returns 14 because 12 + 22 + 32 is 14.
arrow_forward
Solve in JS
arrow_forward
The function ver() is defined as follows:
void ver(char "pc)
{
char c;
if( "pc == "\O' )
return;
c = "pc;
++pc;
ver(pc);
putchar(c);
Show the output when function ver() is called as follows:
ver("recursion");
arrow_forward
The following is a
implementation of the Ackermann function:
public static long Ackermann(int m, int n){
0)
return n + 1;
if (m
==
else if (n
==
return Ackermann(m
1, 1);
else
return Ackermann(m
1, Ackermann(m, n - 1));
arrow_forward
c++
A palindrome is a string that reads the same both forward and backward. For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameter.
arrow_forward
Consider the following recursive function:void recFun(int u){if (u == 0)cout << "Zero! ";else{cout << "Negative ";recFun(u + 1);}}What is the output, if any, of the following statements? a. recFun(8); b. recFun(0); c. recFun(-2);
arrow_forward
Write a recursive function that returns the sum of the digits of an integer.int sumOfDigits(int x);
arrow_forward
7. Convert this iterative function into recursive function.
[s]
int factorial (int num){
int answer=1;
for(int t = 1; t>num; t++)
{
answer answer * (t);
return (answer);
}
arrow_forward
MULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS
Use #include<stdio.h>
Implement the picture shown below.
arrow_forward
Consider the following recursive function. What does it calculate in terms of x, y, and z?
01: Private Function CalcRecurse(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer
02: If x <= 1 Then 'Assume that CalcRecurse always starts with x > 1
03: Return y
04: Else
05: Return z + CalcRecurse(x - 1, y, z)
06: End If
07: End Function
arrow_forward
write a recursive version. The function takes two string parameters, s1 and s2 and returns the starting index of s2 inside the first string s1, or -1 if s2 is not found in s1.
You must not use any loops; you also cannot use the string member functions find or rfind. You may use the member functions size, at and substr. Your function must be recursive.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Related Questions
- Consider the following function: void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?arrow_forwardHow do I go about solving this?arrow_forwardWrite a recursive function 'void reverse(string &word)' that reverses the given input string. string name = "lexa"; reverse(name); cout << name << endl; //should display "axel". without using the following loops: -no for loops -no while loops -no do-while's -no while-do's -no for-while's -no while-for-do'sarrow_forward
- // Description: Write a program that outputs a root of a given function f(x) by using a bi-section method. // f(x) = x3 + 5x2 +7x +2arrow_forwardQ1: Complete the following program by writing its functions: static void Main (....) { double z; long P-1; int a, b, c=-4; int[] f = {1, 3, 9, 10, 12, 7, 8}; int g = abs (c) ; Prime (f,out b) ; Find (g, out z); Power (a [1] , a[2],ref p); // where P= a[1]a(2] double d=fact(g); // return absolute value of C // b=the average of Prime numbers in f // z = 1! + 2! + ... + g! // return the factorial of x using // recursion principle // print the maximum value of f Маx (f) ; Console.Write ("{0}: {1}: {2}:{3}: {4}",g,b, z,p,d);arrow_forwardPart (a) Write a python function that computes the binomial coefficient ("). The function should return the correct answer for any positive integer n and k where k=m pass Part (c) Suppose that the number of people in the trial is 100. Then: • Plot a curve that shows how the probability of type 1 error changes with the choice of m, for m = 1,...n assuming that the null hypothesis holds (in red), • On the same picture, plot the probability of type 2 error vs the value of m in the case in which the new drug is effective with proability 0.68 (in blue). You can plot the two curves using matplotlib.pyplot. You can select the color by passing color='r' or color='b' to the plt.plot() function. [4]: n - 100 # your code here def plot_curve (): pass [5]: plot_curve() Part (d) Based on the picture above, what value of m do you think would be suitable to keep both type 1 and type 2 error small at the same time? (You may assume that the company claims the new drug has 68% accuracy) [6]: # your…arrow_forward
- Q1: Complete the following program by writing its functions: static void Main (... .) { double z; long P=1; int a, b, c=-4; int[] f = {1, 3, 9, 10, 12, 7, 8}; int g = abs (c); Prime (f, out b) ; Find (g, out z); Power (a [1], a[2], ref p); // where P= a[1]a121 double d=fact (g) ; // return absolute value of c // b=the average of Prime numbers in f // z = 1! + 2! + + g! ... // return the factorial of x using // recursion principle // print the maximum value of f Max (f) ; Console.Write ("{0}: {1}:{2}:(3} : {4}",g,b, z,p,d);arrow_forwardThe following function will correctly return true if its argument is an odd integer bool Isodd (int x) { return (x / 2 == 1); } True Falsearrow_forwardSolution in javaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning