Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1 CSC 101 Computer Science 1 – Exam 3 Fall 2021 Student Name: ________________________________________________ School ID: _____________________ Section Number: ______________ Sections: • H004 Test...

1 answer below »

1
CSC 101 Computer Science 1 – Exam 3
Fall 2021
Student Name: ________________________________________________
School ID: _____________________
Section Number: ______________
Sections:
• H004
Test Breakdown
Concept Knowledge 60 %
Program Analysis 25 %
Program Writing 15 %
Statement on Integrity
This test is closed note, closed book, closed electronic device, and closed partner.
You are permitted a calculator and a writing utensil. Any violation of these
policies will result in an automatic zero and an immediate refe
al to the Honor
Code office.
Last Name:____________________
2
Grade: ________________________________
Concept Knowledge
Match the following definitions and statements to the terms listed on the right. Note that some terms
may be used more than once while others may not be used at all. (3 pts each)
___________ 1.
This is another name for the process of
stepping through an a
ay.
A. Two Dimensional
B. Elements
C. Remove
D. Out of Bounds
E. Traversal
F. Index
G. Search
H. Read
I. Sub String
J. Pass by Value
K. Concatenation
L. Erase
M. String
N. In Bounds
O. Find
P. Write
Q. Pass by Reference
R. One Dimensional
S. Variable
___________ 2.
This is the process of creating a combination
of two or more strings into one new string.
___________ 3.
This type of a
ay organizes its elements in a
linear fashion, and each element has one
index number that represents its position in
the a
ay.
___________ 4.
This string function allows us to remove one
or more characters at a certain position.
___________ 5.
This type of argument passing results in the
argument’s values being copied to the
function’s parameters.
___________ 6.
This is the numerical non-negative position of
an element that is being accessed.
___________ 7. The process of outputting to a file is called this.
___________ 8. This is a cutout of a larger string, in a sense.
___________ 9. This are the individual components that make up an a
ay.
___________ 10.
This function allows a programmer to determine the index location of the
first occu
ence of a given character.
Last Name:____________________
3

___________ 11.
This is an issue when you try to access an element that does not exist in the
a
ay by using an invalid index.
___________ 12. The process of inputting from a file is called this.
___________ 13.
This type of argument passing is when a variable argument is
connected/attached to a function’s parameter.
___________ 14.
This type of a
ay organizes its elements in a table like fashion, and each
element has two index numbers that represents its position in the a
ay.
___________ 15. A
ays are automatically passed this way to a function.
Last Name:____________________
4
16. For the following a
ay of size 5, indicate the index position each element in the a
ay (5 pts).
Element
Value
XXXXXXXXXX
Index
17. For the following, give the name of a C++ built in function that would allow us to do the
following (5 pts).
a. Determine if a character is a letter of the alphabet.
. Determine if a character is a punctuation mark.
18. Briefly explain why it is unfeasible to only use variables in a program to store large amounts of
data, and why a
ays make data organization easier (5 pts).
Last Name:____________________
5

Analysis
19. Read the following code:
const int SIZE = 11;
int a
[SIZE] = { 49, 20, 19, 99, 92, 98, 74, 65, 84, 29, 97 };
int input;
cout
"Give me a number: ";
cin
input;
cout
"\n";
for (int i = 0; i < SIZE; i++)
{
if (a
[i] < input)
cout
a
[i]
"\n";
}
a. If the user enters “42” as input into this program, indicate the output of the
program. If there is no output, then specify “no output”. (2 pts)
. If the user enters “12” as the input into this program, indicate the output of the
program. If there is no output, then specify “no output”. (2 pts)
c. If the user enters “100” as the input into this program, indicate the output of the
program. If there is no output, then specify “no output”. (2 pts)
d. Describe the purpose of this program. (6 pts)
Last Name:____________________
6

20. Read and analyze the following snippets of code:
a. What is the output of Code A? (3 pts)
. What is the output of Code B? (3 pts)
c. Is there a difference? If so, explain why the difference occu
ed and what topic we
learned about that explain the difference. (7 pts)
Code A

int function_a(int a, int b)
{
a = 23;
b = 32;

int c = a + b;

return c;
}

int main()
{

int x = 9;
int y = 5;
int z = function_a(x, y);

cout
"x: "
x
"\n";
cout
"y: "
y
"\n";
cout
"z: "
z
"\n";

}
Code B

int function_a(int &a, int &b)
{
a = 23;
b = 32;

int c = a + b;

return c;
}

int main()
{

int x = 9;
int y = 5;
int z = function_a(x, y);

cout
"x: "
x
"\n";
cout
"y: "
y
"\n";
cout
"z: "
z
"\n";

}
Last Name:____________________
7

Programming Problem
21. The following program asks the user for their date of birth and favorite thing and generates a
password for the user to use. The password is generated by adding their favorite thing at the
eginning of the password, choosing a random symbol from a group of selected symbols, and
then adding their date in reverse to the end of the password. Complete the program by filling
in the missing blanks below XXXXXXXXXXpts)
#include
#include
#include
andom>

using std::string;
using std::cout;
using std::cin;
using std::getline;

int rand_range(int start, int end);
string reverse_str(string original);
string generatePass(string dob, string favorite_thing);

int main()
{
string name, dob, favorite_thing;
string password;


cout
"What is your DOB, entered as MMDDYYYY? ";
getline(cin, dob);

cout
"What is your favorite thing? ";
getline(cin, favorite_thing);


Set the password to a generated password by calling the appropriate function,
passing it the users date of birth and favorite thing. (3 pts)

________________________________________________________________

cout
"Your new password is: ";
cout
"\n"
password
"\n";

}

string generatePass(string dob, string favorite_thing)
Last Name:____________________
8

{
string pass = "";
int random_index;


Symbols used in password.
string symbols = "!^&@.%";


Use concatenation to add the string in favorite_thing onto the back of pass. (3 pts)

__________________________________________________________________________

Use the rand_range function defined above to pick a random symbol in the
symbols string and set it to random_index.

Hint: Remember the rand_range function includes both the starting and ending number
in the set of possible number. Take this into consideration when determine start/end.
(3 pts)

____________________________________________________________________________

Concatenate the symbol onto pass.
pass += symbols[random_index];


Reverse the date of birth and concatenate it onto pass.

Hint: A function has already been declared for reversing

a string below. Look at that function first. (3 pts)

____________________________________________________________________________

return pass;
}

Uses system hardware devices to produce a random number between
start and end.
int rand_range(int start, int end)
{
std::random_device rd;
obtain a random number from hardware
std::mt19937 gen(rd());
seed the generator
std::uniform_int_distribution
distr(start, end);
define the range

return (int)distr(gen);
generate numbers
}
Last Name:____________________
9

This function reverses a string.
string reverse_str(string original)
{
string rev;

for (int i = 0; i < original.size(); i++)
{

Determine the index of the next character to append for the next character
from original.

Hint: If "i" is 0, then rev_i should be size – 1.
XXXXXXXXXXIf "i" is 1, then rev_i should be size – 2.

(3 pts)

_______________________________________________________________________

ev += original[rev_i];
}

return rev;
}

Sample Output:
Answered 1 days After Nov 30, 2021

Solution

Vaibhav answered on Dec 02 2021
123 Votes
1
CSC 101 Computer Science 1 – Exam 3
Fall 2021
Student Name: ________________________________________________
School ID: _____________________
Section Number: ______________
Sections:
• H004
Test Breakdown
Concept Knowledge 60 %
Program Analysis 25 %
Program Writing 15 %
Statement on Integrity
This test is closed note, closed book, closed electronic device, and closed partner.
You are permitted a calculator and a writing utensil. Any violation of these
policies will result in an automatic zero and an immediate refe
al to the Honor
Code office.
Last Name:____________________
2
Grade: ________________________________
Concept Knowledge
Match the following definitions and statements to the terms listed on the right. Note that some terms
may be used more than once while others may not be used at all. (3 pts each)
___________ 1.
This is another name for the process of
stepping through an a
ay.
A. Two Dimensional
B. Elements
C. Remove
D. Out of Bounds
E. Traversal
F. Index
G. Search
H. Read
I. Sub String
J. Pass by Value
K. Concatenation
L. Erase
M. String
N. In Bounds
O. Find
P. Write
Q. Pass by Reference
R. One Dimensional
S. Variable
___________ 2.
This is the process of creating a combination
of two or more strings into one new string.
___________ 3.
This type of a
ay organizes its elements in a
linear fashion, and each element has one
index number that represents its position in
the a
ay.
___________ 4.
This string function allows us to remove one
or more characters at a certain position.
___________ 5.
This type of argument passing results in the
argument’s values being copied to the
function’s parameters.
___________ 6.
This is the numerical non-negative position of
an element that is being accessed.
___________ 7. The process of outputting to a file is called this.
___________ 8. This is a cutout of a larger string, in a sense.
___________ 9. This are the individual components that make up an a
ay.
___________ 10.
This function allows a programmer to determine the index location of the
first occu
ence of a given character.
Traversal
Concatenation
One Dimensional
Pass by Value
Remove
Index
Write
Substring
Elements
Find
Last Name:____________________
3

___________ 11.
This is an issue when you try to access an element that does not exist in the
a
ay by using an invalid index.
___________ 12. The process of inputting from a file is called this.
___________ 13.
This type of argument passing is when a variable argument is
connected/attached to a function’s parameter.
___________ 14.
This type of a
ay organizes its elements in a table like fashion, and each
element has two index numbers that represents its position in the a
ay.
___________ 15. A
ays are automatically passed this way to a function.
Out of bounds
Read
Pass by Reference
Two Dimensional
Pass by Reference
Last Name:____________________
4
16. For the following a
ay...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here