Sunteți pe pagina 1din 4

SIE1003 – C Programming

SIE1003 – C Programming Tutorial 5: C Arrays

Tutorial 5

1. Find the error(s) in each of the following program segments and explain how the error can be corrected.

(a)

(b)

(c)

(d)

(e)

(f)

(g)

the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to
the error can be corrected. (a) (b) (c) (d) (e) (f) (g) 2. Write statements to

2. Write statements to accomplish each of the following.

(a)

Input a value into the element that is present in the 5th row and 6th column of the double subscripted integer array matrix.

(b)

Initialise each of the 4 elements of the double subscripted integer array doubleArray to the product of its subscripts. Assume the integer variables a and b are control variables, and the symbolic constant LENGTH has a value of 2.

(c)

Multiple the elements of the integer array intArray of 50 elements.

(d)

Determine the sum and difference values contained in 50 element integer array m.

SIE1003 – C Programming

Tutorial 5

3. What does each of the following programs do?

(a)

SIE1003 – C Programming Tutorial 5 3. What does each of the following programs do? (a)

(b)

SIE1003 – C Programming Tutorial 5 3. What does each of the following programs do? (a)

SIE1003 – C Programming

Tutorial 5

4. A pharmaceutical company pays its medical representatives (MRs) on a commission basis. The MRs receive 6% commission of their sales for that month. For example, a MR who grosses $15000 in sales in a month receives 6% of $15000, or a total of $900. Write a program (using an array of counters) that determines how many of the MRs earned commissions in each of the following ranges (assume that each MR’s commission is truncated to an integer amount):

a) $0 – 120

b) $121 – 240

c) $241 – 360

d) $361 – 480

e) $481 – 600

f) $601 – 720

g) $721 – 840

h) $841 – 960

i) $961 and above

Use function printCommission to print the number of employees in each range.

5. Write a program that reads 10 letters from A to Z. Among the 10 letters, store the non duplicated ones in an array and then print those non duplicated letters.

6. Write a program to simulate the rolling of two dice. The program should use rand twice to roll the first die and second die, respectively. The sum of the two values should then be calculated. Since each die can show an integer value from 1 to 6, then the sum of the two values will vary from 2 to 12. The program should roll the two dice 36000 times. Use a single subscripted array to tally the number of times each possible sum appears. Print the results in a tabular format. Find and display the mode and its corresponding number of occurrences.

7. Forty customers were asked to rate the service quality in a shopping mall on a scale of 1 to 10. Place the 40 responses in an unsigned integer array and determine the median of the survey results from function median . Use function bubbleSort to sort the array of responses. Eventually, plot the results using a histogram of asterisks.

Responses = { 1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 }

SIE1003 – C Programming

Tutorial 5

8. A company has four salesperson (0 to 3) who sell five different products (P0 to P4). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains the salesperson number and product number. Assume that the information from all the slips for last month is available, write a program that reads all this information and summarise the total sales by salesperson and by product. All totals should be stored in the double subscripted array sales. After processing all the information for last month, print the results in tabular format with each of the rows representing a particular salesperson and each of the columns representing a particular product. Cross total each row to get the total sales by each salesperson for last month; cross total each column to get the total sales of each product for last month. The tabular printout should also include these cross totals to the right of the totalled rows and to the bottom of the totalled columns, as shown below.

 

P0

P1

P2

P4

P5

0

1.00

2.00

3.00

4.00

5.00

15.00

1

1.00

2.00

3.00

4.00

5.00

15.00

2

1.00

2.00

3.00

4.00

5.00

15.00

3

1.00

2.00

3.00

4.00

5.00

15.00

4.00

8.00

12.00

16.00

20.00