The following questions are on recursion in C++ Programming.
I had some trouble with these questions, can you please help me? Thank you!
Consider the following recursive function
void funcEx8(int u, char v) //Line 1
{ //Line 2
if (u == 0) //Line 3
cout << u << " "; //Line 4
else //Line 5
{ //Line 6
int x = static_cast (v); //Line 7
if (v < 'A') //Line 8
v = static_cast (x + 1); //Line 9
else if (v > 'Z') //Line 10
v = static_cast (x - 1); //Line 11
cout << v << " "; //Line 12
funcEx8(u - 2, v); //Line 13 }
//Line 14 }
//Line 15 }
Identify the base case? Using line numbers
| a. |
Lines 3,4 |
|
| b. |
Lines 1 through 4 |
|
| c. |
Lines 7,8 |
|
| d. |
Lines 5,6 |
Consider the following recursive function
void funcEx8(int u, char v) //Line 1
{ //Line 2
if (u == 0) //Line 3
cout << u << " "; //Line 4
else //Line 5
{ //Line 6
int x = static_cast (v); //Line 7
if (v < 'A') //Line 8
v = static_cast (x + 1); //Line 9
else if (v > 'Z') //Line 10
v = static_cast (x - 1); //Line 11
cout << v << " "; //Line 12
funcEx8(u - 2, v); //Line 13 }
//Line 14 }
//Line 15 }
Identify the Recursive case? Using line numbers
| a. |
Lines 5 Through 15 |
|
| b. |
Lines 3,4 |
|
| c. |
1,2 |
|
| d. |
Lines 2,3 |
Consider the following recursive function
void funcEx8(int u, char v) //Line 1
{ //Line 2
if (u == 0) //Line 3
cout << u << " "; //Line 4
else //Line 5
{ //Line 6
int x = static_cast (v); //Line 7
if (v < 'A') //Line 8
v = static_cast (x + 1); //Line 9
else if (v > 'Z') //Line 10
v = static_cast (x - 1); //Line 11
cout << v << " "; //Line 12
funcEx8(u - 2, v); //Line 13 }
//Line 14 }
//Line 15 }
Valid or Invalid
funcEx8(26, '$'); is a valid call,
| a. |
None |
|
| b. |
Yes and No |
|
| c. |
No |
|
| d. |
Yes |
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 recFun(8)
| a. |
Infinite loop, nonegative |
|
| b. |
5 |
|
| c. |
0 |
|
| d. |
8 |
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 recFun(0)
| a. |
12 |
|
| b. |
infinite loop |
|
| c. |
8 |
|
| d. |
zero |
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 recFun(-2)
| a. |
8 |
|
| b. |
Negative Negative Zero! |
|
| c. |
-2 |
|
| d. |
zero |
Consider the following recursive function:
void recFun(int x)
{
if (x > 0)
{ cout << x % 10 << " ";
recFun(x / 10);
}
else
if (x != 0)
cout << x << endl;
}
what is the output of the above statement if recFun(258)?
| a. |
12 |
|
| b. |
3 4 6 |
|
| c. |
15 |
|
| d. |
8 5 2 |
Consider the following recursive function:
void recFun(int x)
{
if (x > 0)
{ cout << x % 10 << " ";
recFun(x / 10);
}
else
if (x != 0)
cout << x << endl;
}
. what is the output of the above statement if recFun(7)?
| a. |
7 |
|
| b. |
8 |
|
| c. |
8 5 2 |
|
| d. |
12 |
Consider the following recursive function:
void recFun(int x)
{
if (x > 0)
{ cout << x % 10 << " ";
recFun(x / 10);
}
else
if (x != 0)
cout << x << endl;
}
what is the output of the above statement if recFun(36)?
| a. |
5 3 8 |
|
| b. |
12 |
|
| c. |
6 3 |
|
| d. |
2 4 5 |
Consider the following recursive function:
void recFun(int x)
{
if (x > 0)
{ cout << x % 10 << " ";
recFun(x / 10);
}
else
if (x != 0)
cout << x << endl;
}
what is the output of the above statement if recFun(-85)?
| a. |
12 |
|
| b. |
-85 |
|
| c. |
8 5 2 |
|
| d. |
85 |
In: Computer Science
How many words are in the Gettysburg Address?
Write a program that reads any text file, counts the number of characters, num- ber of letters and number of words in the file and displays the three counts.
To test your program, a text file containing Lincoln’s Gettysburg Address is included on the class moodle page.
Sample Run
Word, Letter, Character Count Program
Enter file name: GettysburgAddress.txt
Word Count = 268 Letter Count = 1149 Character Count = 1440
Do the following
To detect is a character ch is a letter use the following if statement if ch >= ‘A’ and ch <= ‘Z’ or ch >= ‘a’ and ch <= ‘z’:
You may want to embed this “if statement” in a Boolean valued function (isLetter(ch)) that returns True if ch is a letter; otherwise it returns False
Ask the user for the file name.
For this assignment, the easiest way do the following three counts is to first input the text file as one very long string using the read() method. Don’t use readline() or readlines()here, unless using the read() method crashes the program.
The character count is simply the length of the string you input from Step 3 above. Use the len() function
1
To determine the letter count you will need to go through the string character by character using a for loop testing if each character is a letter or not. If it is a letter, increment a letter count variable.
Checking for the number of words is easily done using the split method for strings (see page 136 for details). Recall that string.split( ) was used to break up a date such as “10/25/2016” into a list of three strings. That is "10/25/20165".split("/") returns the list ["10", "25", "2016"].
By default if no “split” character is given, the string will be split wherever a space occurs. This makes it perfect to split a text string into a list of individual words which then can be counted by using the len() to get the length of the list.
Output your three counts using string formatting to properly line up your three counts and close the file
In: Computer Science
There are three vectors in R4 that are linearly independent but not orthogonal: u = (3, -1, 2, 4), v = (-2, 7, 3, 1), and w = (-3, 2, 4, 11). Let W = span {u, v, w}. In addition, vector b = (2, 1, 5, 4) is not in the span of the vectors. Compute the orthogonal projection bˆ of b onto the subspace W in two ways: (1) using the basis {u, v, w} for W, and (2) using an orthogonal basis {u' , v' , w'} obtained from {u, v, w} via the Gram Schmidt process. Finally, explain in a few words why the two answers differ, and explain why only ONE answer is correct.
In: Advanced Math
(a) How many grams of CaCl2 are needed to make 798.0 g of a solution that is 32.5% (m/m) calcium chloride in water? Note that mass is not technically the same thing as weight, but (m/m) has the same meaning as (w/w).
-How many grams of water are needed to make this solution?
(b) What is the volume percent % (v/v) of an alcohol solution made by dissolving 147 mL of isopropyl alcohol in 731 mL of water? (Assume that volumes are additive.)
(c) The mass of solute per 100 mL of solution is abbreviated as % (m/v). (The abbreviation % (w/v) is also common.) How many grams of sucrose are needed to make 915 mL of a 38.0% (w/v) sucrose solution?
In: Chemistry
(a) How many grams of CaCl2 are needed to make 250.9 g of a solution that is 30.5% (m/m) calcium chloride in water? Note that mass is not technically the same thing as weight, but (m/m) has the same meaning as (w/w).
-How many grams of water are needed to make this solution?
(b) What is the volume percent % (v/v) of an alcohol solution made by dissolving 117 mL of isopropyl alcohol in 747 mL of water? (Assume that volumes are additive.)
(c) The mass of solute per 100 mL of solution is abbreviated as % (m/v). (The abbreviation % (w/v) is also common.) How many grams of sucrose are needed to make 735 mL of a 34.0% (w/v) sucrose solution?
In: Chemistry
define U=x+y, V=x-y.
find the joint and marginal pdf of U and V
In: Statistics and Probability
Marie earned her bachelor’s degree in HIM. After working intraditional HIM roles for a few years, she decided that she wanted tobe involved in the selection and implementation of the EHR andother healthcare information systems. Marie went back to school andearned her master’s degree in health informatics. After graduation,Marie worked for an information system vendor for several years.She decided to take another turn in her career path and become aprofessor in an accredited HIM program. She took a position as afaculty member in a bachelor’s-level HIM program. Marie nowteaches the information system courses for the HIM program and isable to give the students real world examples from her experience inthe traditional HIM departments and the information system vendor.Marie enjoyed her position so much that after teaching for a while,Marie went back to school again to earn her doctorate degree inadult education.
1. Identify how this Real-World Case ties to this chapter.
2. In the Real-World Case, Marie earned a bachelor’s degree, a master’s degree, and a doctoral degree. Do you think that some or all of the new roles discussed in this chapter will require graduate education? Why or why not? How do these roles tie into HIM Reimagined?
In: Nursing
Place the following activities in their correct order:
1.) Designing an experiment that yields data
2.) Deciding how much data to collect
3.) Running the experiment that generates the data
4.) Collecting the data
5.) Interpreting the data to validate or discredit a model
In: Biology
5. Why do different atoms/ions emit different colors of light?
2. An unknown solution tested in this experiment gave a yellow green flame test. Do you expect to observe a precipitate with the reagents used in Part C of this experiment?
In: Chemistry
A famous scientist, Mendel, conducted a genetic experiment with peas. One sample
from this experiment consisted of 152 yellow peas out of 580 peas. Calculate a 95%
confidence interval for the percentage of yellow peas. Also, find the estimation and
the margin of error.
In: Statistics and Probability