CS 20A Santa Monica College Data Structures with C++ Quiz 1 Paper


Assignment has attached below. Please read the instruction before starting. Thank you!

Santa Monica College
Spring 2019
CS 20A: Data Structures with C++
Quiz 1
Problem 1: Fish pointers
For each of the following parts, write a single C++ statement that performs the indicated task. For each part,
assume that all previous statements have been executed (e.g., when doing part e, assume the statements you
wrote for parts a through d have been executed).
a. Declare a pointer variable named fp that can point to a variable of type string.
b. Declare fish to be a 5-element array of strings.
c. Make the fp variable point to the last element of fish.
d. Make the string pointed to by fp equal to “salmon”, using the * operator.
e. Without using the fp pointer, and without using square brackets, set the element at index 3 of the fish
array to have the value “yellowtail”.
Move the fp pointer back by three strings.
g. Using square brackets, but without using the name fish, set the element at index 2 of the fish array to have
the value “eel”.
h. Without using the * operator, but using square backets, set the string pointed to by fp to have the value
Declare a bool variable named d and initialize it with an expression that evaluates to true if fp points to the
string at the start of the fish array, and false otherwise.
Using the * operator in the initialization expression, declare a bool variable named b and initialize it to true
if the string pointed to by fp is equal to the string immediately following the string pointed to by fp, and
false otherwise.
Page 1 of 6
Santa Monica College
Spring 2019
CS 20A: Data Structures with C++
Quiz 1
Problem 2: Déjà vu Pointers (This is different problem)
Suppose you’re tasked with fixing a function definition that does not work as intended. The function is
supposed to compare two strings and set the count to the number of identical characters, two characters are
identical if they are the same character and are in the same position in the cstring. This function will be case
sensitive so the character ‘a’ is not the same as ‘A’. Note that cstrings are just character arrays that have ‘’
as their last character, for example
char name[7] = “harry”;
might looks like this in memory:

Usage of this function might look like:
int count = 0;
compareCstrings(“tacocat”, “TACOCAT”, count);
compareCstrings(“Harry”, “Malfoy”, count);
compareCstrings(“SMC”,”SBCC”, count);
// should set count to 0
// should set count to 1
// should set count to 2
Currently the function definition is:
void compareCstrings(const char *str1, const char *str2, int &count) {
*count = 0;
while (str1 != ‘’ || str2 != ‘’) {
if (*str1 == *str2)
Identify the errors in the above implementation and rewrite the function so that it satisfies specification. Try to
keep the general form of the original code, you should not have to add or remove any lines of code, just
modify the existing ones. You may not use the indexing operator [].
Page 2 of 6
Santa Monica College
Spring 2019
CS 20A: Data Structures with C++
Quiz 1
Problem 3: Delete All the Things
Write delete statements that correctly delete the following dynamically allocated entities. Hint: draw out the
memory layout on scratch paper.
int *p1 = new int[10];
int *p2[15];
for (int i = 0; i < 15; i++)
p2[i] = new int[5];
int **p3 = new int*[5];
for (int i = 0; i < 5; i++)
p3[i] = new int;
int *p4 = new int;
int *temp = p4;
p4 = p1;
p1 = temp;
Problem 4: Build it up, Break it down
Consider the following 7 classes and a main function. What is printed to the console with the complete
execution of main?
class Hey {
Hey() { cout
Purchase answer to see full

We offer the bestcustom writing paper services. We have done this question before, we can also do it for you.

Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.