lab7-arrays

EECS 183 Lab 7: Arrays

Lab attendance Due at your scheduled lab time and day, Thursday or Friday, March 18th or 19th

Lab assignment Due Monday, March 22, 2021, 11:59 pm Eastern

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

Prerequisite

Attend the discussion with your lab instructor at your assigned lab time. Check here for the lab section Zoom link

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

Starter Files

You can download the starter files using this link.

The IDE setup tutorials for Visual Studio and XCode include a video about how to set up a project using the starter files. You can access the tutorials here:

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 to be implemented function. In all projects and labs so far in EECS 183, we have provided all of the function stubs for you. Like the previous Lab 5, 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 submission for Labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.