Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 - Write a program that searches the array of up to 21 data values, in the range of 10 70 using a linear

Problem 1 - Write a program that searches the array of up to 21 data values, in the range of 10 70 using a linear search. The array is filled with random numbers. A symbolic Constant should be used to establish the array size of 21. The main program will be used to print the heading and for declaration and to call user defined functions The main only calls functions and functions do all the work for this problem. Use

The UDF1 is called from the main and will ask the user for a seed value from (1-10) to generate up to 21 random numbers in the range of 10 70. The numbers are used to fill the array. No check is needed for the (1-10)

The UDF2 is called from the main and will print the array of 21 random numbers in the range of 10 70 to the screen (console) with 7 numbers to a line.

The UDF3 is called from the main and will ask the user for a search key. The search key will be used in that same function to look for and identify the position of the key value in the array. This same function will print to a text file (data file), the value and the position or positions of the found value or print a message stating the value and that the values was not found. The rules for the output file: The data file must have the students lastname_keyword included in the filename. The data file should have the extension .txt. The cprogram should print a start to the data file with name and date. The cprogram file must open the datafile with a statement. The cprogram should print an end to the data file with name and date. The cprogram file must close the datafile with a statement. Please see the sample files.

Students will upload a filename.c file that has a copy of the console input and a copy of the text file output, and upload a text file that has a copy of the output. Students will print and turn in a filename.c file that has a copy of the console input and a copy of the text file output, and print and turn in a copy of the text file that has a copy of the output.

Students should follow the sample output by using the inputs given and provide sample output of 2 scenarios. Use 7 and use 10 for input. One scenario is for random data with the target found and the other scenario is for random data with the target not found.

(use the following filename system: student's last name_key_firstinitial.c)

Sample Output: Scenario1

(heading)

Enter a seed value in this function (1-10) so the function can generate random numbers in the range of 10 - 70: 7 filling the array in a function .........

The random numbers printed from a function, 7 per line are:

Computer is printing the array in a function .........

10 47 36 35 37 60 28

31 43 41 70 54 42 60

35 64 12 43 23 28 28

Enter the Integer search key into this function (in the range of 10-70): searching the array in a function .........

28

Press any key to continue . . .

(add output text file rule items)

The value, 28, was found at array position 6.

The value, 28, was found at array position 19.

The value, 28, was found at array position 20.

Sample Output: Scenario2

(heading)

Enter a seed value in this function (1-10) so the function can generate random numbers in the range of 10 - 70: 10 filling the array in a function .........

The random numbers printed from a function, 7 per line are:

Computer is printing the array in a function .........

20 12 49 40 43 67 22

33 24 18 53 64 69 23

39 35 46 31 25 64 43

Enter the Integer search key into this function (in the range of 10-70): searching the array in a function .........

70

Press any key to continue . . .

(add output text file rule items)

1.0 point(s) = 2 @ 0.5 points for misc or general items and stdlib.h for srand, time.h is optional

0.5 point(s) = 1 @ 0.5 points for

# define for the size of 21

We are sorry to report that the value, 70, was not found. Thank you for conducting a linear search. #include

#include

#include

#define SIZE 21

3.0 point(s) = 6 @ 0.5 points for

prototypes, check for void and int, check for array using [])

void seeder_random(int array1[], int qty); void printer_instructor(int array1[], int quantity); void finder_instructor(int array1[], int quantity);

0.5 point(s) = 1 @ 0.5 points for declaration of array

void main(void)

{

int array1[SIZE];

printf("Name and Date:instructor "); printf("Course and Section:ENGR 197 ");

printf("Statement:searches for and finds a value in an array ");

3.0 point(s) = 6 @ 0.5 points for call statements

seeder_random(array1, SIZE); printer_instructor(array1, SIZE); finder_instructor(array1, SIZE);

}

void seeder_random(int array1[], int qty)

{

int loop, input1;

4.0 point(s) = 8 @ 0.5 points for Basics of function header and body:

a) void header b) header inputs c) printf /scanf

d) srand(some type of seed) d) for loop

e)loop range < SIZE or <= (SIZE -1) f) rand ()

h) range = [ % (61) + 10 ]

printf("Enter a seed value in this function (1-10) so the function can generate "); printf("random numbers in the range of 10 - 70: "); scanf("%d", &input1); srand(input1);

printf("filling the array in a function ......... ");

for (loop = 0; loop < SIZE; loop++) array1[loop] = rand() % (61) + 10;

}

void printer_instructor(int array1[], int quantity)

{

int num= 0, loop;

printf("The random numbers printed from a function, 7 per line are: ");

printf("printing the array in a function ......... ");

for(loop = 0; loop < quantity; loop++)

4.0 point(s) = 8 @ 0.5 points for Basics of function header and body:

a) void header b) header inputs c) printf

d) for loop e) loop range < SIZE or <= (SIZE -1)

f)array [ ] g) counting: num += 1;

h) some method of 7 values: count 1 to 6; or if value ==7; or value%7 ==0;

{ printf("%d\t", array1[loop]);

num += 1; if(num == 7)

{ printf(" "); num = 0;

}//end if

}//end for

}//end function

2.5 point(s) = 5 @ 0.5 points for data file / text file

file with a name : File *outfile;

outfile: Outfile = fopen(name_output.txt, w);

c)W is for writing

use of fprintf to get the results

e)close the file

void finder_instructor(int array1[], int quantity)

{

int loop, position=-99, key_value;

File *outfile; outfile = fopen(name_output.txt, w);

printf("Enter the Integer search key into this function (in the range of 10-70): ");

printf("searching the array in a function ......... ");

scanf("%d", &key_value);

5.0 point(s) = 10 @ 0.5 points for function header and body:

a) void header b) header inputs c) printf

d) for loop e) loop range < SIZE or <= (SIZE -1)

f)array [ ] g) comparison ==; target value

h) %d, Key values i) if statement to check if values was not found. j) %d, key value, not found

for(loop = 0; loop < quantity; loop++)

{

if (array1[loop] == key_value)

{ position = loop;

fprintf(outfile, "The value, %d, was found at array position %d. ", key_value, position);

} }

if (position == -99)

{

fprintf(outfile, "We are sorry to report that the value, %d, was not found. ", key_value);

0.5 point(s) = 1 @ 0.5 points for output as comments or attached output file.

}// end if fclose(outfile); }//end fun

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions

Question

2. Who do you need to persuade?

Answered: 1 week ago