Starting from:

$35

Programming II Lab 3 Solution


Objectives:

    • Review call-by-reference

    • Review array operation

    • Review for-loop operation

    • Review File I/O

Description:

Given an array of integers, some elements appear more than once.

Count the number of times k appears in the array where k is an integer between 1 to 10.

Return count.

*Note: The array must be malloced and free() after displaying result.

Use the implementation of file I/O operations you’ve done in prelab to read the given file.

The first number in the file is the array size.

Then create an integer array with the given array size using ‘malloc’.

Every user-defined function must have a comment describing:

    • What function does;

    • What parameter values are;

    • What value it returns.

Function Prototype:

    • int countDuplicateValue(int* array, int arraySize, int k);

Example:


    • gcc lab3.c -Wall -Werror

    • ./a.out


Input array: [4,3,2,7,8,2,3,1,7]

Input:

k = 7

Output:

Please pick an integer between 1-10: 7

7 appears 2 times in the array.



1
Section A




Grading Criteria:

•    Main program:    10 points

•    Working function:    5 points

Note:

    • If your code does not compile with –Wall and –Werror, you will receive a zero for this assignment.

    • You need to finish at least three peer reviews within three days of this lab. Otherwise, you will get a 20% penalty.
    • You will lose points if you don’t have enough comments.



















































2

More products