You are on page 1of 3

COMPUTER SCIENCE PROGRAM

FACULTY OF COMPUTING AND INFORMATICS


UNIVERSITI MALAYSIA SABAH

KT14303 PROGRAMMING PRINCIPLES


Lab 6 Arrays and Vectors
______________________________________________________________________________
Student Matric No: _____________________
Student Name: _________________________
Program: HC00/HC05/HC14
Course Code: KT14303

Learning Objectives/Outcomes:
Upon completion of this lab, the student should be able to:
i. define and initialize array and multi-dimensional array
ii. work with common algorithm for processing the value of array
iii. write a function that receive and return arrays
iv. apply the concepts of arrays in solving the complex programming problems

Practice 1: 30 minutes
Write a program that allow users to enter up to 50 integers and find the smallest value. You
should include find_smallest function to find and return the smallest value in the array.

Sample Run:
You may enter up to 50 integers.
How many integers would you like to enter? 8
Enter your Number 1 :6
Enter your Number 2 :7
Enter your Number 3 :8
Enter your Number 4 :1011
Enter your Number 5 :2
Enter your Number 6 :20123112
Enter your Number 7 :-1
Enter your Number 8 :10
The smallest value is : -1

Practice 2: 30 minutes
Write a program that gets a series of integers input from users and find the largest value. You
should include find_largest function to find and return the largest value in the vector.
Sample Run :
How many integers would you like to enter? 10
Enter your Number 1 :10
Enter your Number 2 :21
Enter your Number 3 :233
Enter your Number 4 :-2
Enter your Number 5 :99
Enter your Number 6 :2012
Enter your Number 7 :2901
Enter your Number 8 :1011
Enter your Number 9 :2012
Enter your Number 10 :2110 1
The largest value is : 2901
Practice 3: 60 minutes -5 Marks
A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scanned by
comparing the code’s largest digit (called a check digit) to its own computation of the check digit
from the first 11 digits as follows:

1. Calculate the sum of the digits in the odd-numbered positions (the first, third,….. eleventh
digits) and multiply this sum by 3.
2. Calculate the sum of the digits in the even-numbered position (the second, fourth….tenth
digits) and add this to the previous result.
3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherwise, subtract
the last digit from 10 to calculate the check digit.
4. If the check digit matches the final digit of the 12-digit UPC, the UPC is assumed correct

Write a program that prompts the user to enter the 12 digits of a barcode separated by space.
The program should store the digits in an integer array, calculate the check digit, and compare it
to the final barcode digit. If the digits match, output the barcode with the message “validated”.
If not, output the barcode with the message “error in barcode”.

Also output with labels the results from step 1 and 2 of the check-digit calculations. Note that the
“first” digit of the barcode will be store in element 0 of the array. Try your program on the
following barcodes, three of which are valid. For the first barcode, the result from step 2 is 79 ( 0
+ 9 + 0 + 8 + 4 + 0) * 3 + ( 7 + 4 + 0 + 0 + 5).

0 7 9 4 0 0 8 0 4 5 0 1
0 2 4 0 0 0 1 6 2 8 6 0
0 1 1 1 1 0 8 5 6 8 0 7
0 5 1 0 0 0 1 3 8 1 0 1

The program should included the given calculateTotal function to sum the the odd-number digits
and even-number-digits with the function signature as below:

void calculateTotal(unsigned int [], unsigned int&, unsigned int& );

Sample Run:

Enter 12 integers separated by blanks or <return>S:


0 5 1 0 0 0 1 3 8 1 0 1
The sum of the digits in the odd-numbered positions: 10
The sum of the digits in the even-numbered positions: 9
The sum of the digits in the even-numbered positions and odd-
numbered positions: 39
Entered Barcode:
051000138101
Result: Validated Barcode !

*****************************THE END***********************

2
Assessment Rubric:
Criteria Advanced Proficient Functional Developing
(10-9) (8-7) (6-4) (0-3)
Applicability of Shows excellent Shows a good Shows minimal Show no
Concepts in understanding of understanding of understanding of understanding of
solving given the theory taught the theory taught the theory taught the theory taught
problems and is able to and is able to and is able to and is able to
(2%) integrate the integrate the integrate the integrate the
concepts in solving concepts in solving concepts in solving concepts in solving
the given problems the given problems the given problems the given problems

Deliverables The deliverables The deliverables Minor flaws in Major flaws in


(3%) are precise as are appropriate, as deliverables as deliverables as
demonstrated demonstrated demonstrated demonstrated
sample run. sample run. sample run. sample run.

Program executes Program executes Program executes Program does not


correctly with no somewhat incorrectly with execute (consists
syntax or runtime correctly with <= 3 logic or runtime of syntax errors)
errors. logic and runtime errors >= 3 logic
errors. errors.

Highly efficient in Efficient in Somewhat efficient Inefficient in


managing process managing process in managing managing process
memory and CPU memory and CPU process memory memory and CPU
usage. usage and CPU usage usage

Plagiarism <30% Similarity 30-40% Similarity 40-50% Similarity >50% Similarity


Penalty
(deduction from
overall scoring)

Delivery The program was The program was The code was The code was
(Deduction from delivered on time delivered within a within 2 more
overall scoring) week weeks of the due than 2 weeks
of the due date. date overdue.

You might also like