EECS 183 Labs

EECS 183 Lab 6: Arrays

Lab due on your scheduled lab day (October 7-11)

Lab accepted for full credit until Tuesday, October 15 Wednesday, October 16 2024, 11:59 pm Eastern

In this lab, you are writing code and solving practice exam questions to master the use of arrays.

After completing this lab, you will be able to:

You should complete this lab in small groups of about four students. For all labs in EECS 183, to receive a grade, every student must individually submit the Lab assignment.

Starter Files

You can download the starter files using this link.

After downloading and unzipping, you will find the following files in the starter-files folder:

IMPORTANT: For this lab, you must include all three files in a single project in Xcode or Visual Studio.

Lab Assignment

Tasks to Complete

  1. Start a new project with your IDE using the starter files according.
  2. Stub all of the functions in arrays.cpp - see Function Stubs for details.
  3. Write your test cases in test.cpp to test the functions you will implement in arrays.cpp.
  4. Write the implementations for the functions in arrays.cpp:
    • negate_all()
    • is_sorted()
    • copy_positive_elements()
    • sort_array()
  5. Test your functions using the test cases you have written.
  6. Submit your arrays.cpp to the autograder.
    • For this lab, you will not submit test.cpp

Multiple Files

Function Stubs

A function stub is a temporary substitute for a function that needs to be implemented. In all projects and labs so far in EECS 183, we have provided all of the function stubs for you. Like the previous lab, you will need to create function stubs for all of the functions you will implement.

negate_all()

int values[5] = {1, -2, 3, -4, 5};
negate_all(values, 5);
print_array(values, 5);
{-1, 2, -3, 4, -5}

is_sorted()

int values1[5] = {1, -2, 3, -4, 5};
int values2[6] = {1, 2, 3, 3, 4, 5};
cout << is_sorted(values1, 5) << endl;
cout << is_sorted(values2, 6) << endl;
0
1

copy_positive_elements()

NOTE: Zero is not a positive number.

int values1[5] = {1, -2, 3, -4, 5};
int values2[5] = {2, 0, 8, 5, 1};
copy_positive_elements(values1, values2, 5);
print_array(values2, 5);
{1, 3, 5, 0, 0}

sort_array()

int values1[5] = {1, -2, 3, -4, 5};
sort_array(values1, 5);
print_array(values1, 5);
{-4, -2, 1, 3, 5}

How to Submit

IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the Lab Submission. Late submissions for labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.