Assignment J

Problem J1

Linear Search

Introduction and requirements

Name an int vector as: vector
Initialize the vector with the values: 2 3 5 8 13 21 34
Declare a variable of type int, named result, which can be set to the offset where the target was found, or can be -1 if the target is not found
Declare a variable of type int, named target, which is set to the number we are looking for.

Ask the user for the target
Write a loop to find the result.
Print the result with an appropriate message.

Test twice:
First with target 5
Second with target 7

Problem J2

Vectors and functions

Write a function named input
It has NO parameters
In this function ask the user how many numbers they wish to enter.
Save that in a variable named count.
Read that number of real numbers and save them in a vector.
Return the vector.

Write a function named output
It has one vector parameter and no return value.
Print the numbers from the vector, separated by two spaces.

Write a main function
Declare a vector for use with the data.
Do NOT specify a size for the vector.
Make these four function calls in this order:

  1. input
  2. output
  3. input
  4. output

Test it once
The first time the input function is runs specify the count as 3 and input these values:
1.1 2.2 3.3
The second time the input function runs specify the count as 5 and input these values:
5.1 6.1 7.1 8.1 9.1