Lab Exercise 03 Please write a program to implement the following tasks:
Task1: 1-D Array
Please compute the average (technically, the arithmetic mean) and standard deviation
of a 1-D array with N elements, all of which are double.
The average is = i . The standard deviation, stdDev, is the square root of i =1
the average of the squares of the differences of each Ai and the average avg , N
N
avg A N
( Ai i=1
stdDev =
Sample output:
avg)2 N
Task 1:.
The Average of this array: 17.50
The Standard Deviation of this array: 15.2115
Task 2 2-D Array
Given an M*M matrix A, please write a function to get the transpose matrix of matrix A. Hint:
You may considering using 2-D array to represent matrix although 1-D array may work.
Sample output:
Before
transpose:
1
2
3
0
-1
2
0
0
1
After transpose:
1
0
0
2
-1
0
3
2
1
Bonus: Minesweeper (20 points)
Have you played the minesweeper game? In this task, you dont need to implement the minesweeper game. But you need to simulate it.
Please complete the following requirements:
Randomly put 10 mines into the array of 9*9.
Next, calculate the hint numbers.
Last, print out the 2D array as a 9 rows x 9 colum ns map with the following
symbols:
Output
The first map is the 99 map with 10 mines generated.
The second map is the 99 map with mines and all hint numbers calculated.
Sample output
The mine map without hints:
..* .*.*.. *.. *.**.. *.. ..*
Object
Symbol
Empty space
.
Mine
*
Hint numbers
1
-8
.*.
The mine map with hints:
.111..
12*1.111.
2*21.1*1.
*4321111.
*3**1111.
122211*21
..123* 1.2
Hints:
Please use srand() and rand() to generate random numbers.
Write a program
1. Please complete the above task within the given program framework, which can be found at http://moodle.must.edu.mo/ (see lab03.cpp).
2. Please have a careful look at the comments.
Submission method:
Submit your completed answers according to the following rules:
1. Go to: http://moodle.must.edu.mo/
2. Following the submission rules to submit your answer.
Reviews
There are no reviews yet.