0% found this document useful (0 votes)
37 views

MECN2012 - June Exam

mech engineering

Uploaded by

2706478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

MECN2012 - June Exam

mech engineering

Uploaded by

2706478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Assessment Date Assessment Session Format

Duration
06/2024 3 Hours 09:00 CLM/FNB PC POOL

University of the Witwatersrand, Johannesburg


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

MECN2012A
Course Code No(s)

Course Description name(s) COMPUTING SKILLS AND SOFTWARE DEVELOPMENT

Date of Assessment 06/2024

Year of Study 2

Programme Code EF005; EF006; EF007; SB000


(Degree Code) EFA005; EFA006; EFA007; SBA000

Faculty/ies presenting ENGINEERING AND THE BUILT ENVIRONMENT


candidates

Internal examiner(s) Ms ME Moyo (X77322)


and telephone extension
number(s)

Mr B Chirewa
External examiner(s)

Open Book Assessment


Computer with MATLAB installed or with access
MATLAB Grader and MATLAB Online
Electronic Devices/Computers. Please indicate if any
devices will be used during the exam and if so
what device/devices will be used?

Special materials required (graph/music/drawing Access to MATLAB help files is permitted


paper) maps, diagrams, tables, computer cards, etc.

Time allowance
Course MECN2012 Hours 3
Nos.

Instructions to candidates (Examiners may wish to ANSWER ALL QUESTIONS.


use this space to indicate, inter alia, the contribution Exam duration is 3hr including reading time
made by this examination or test towards Students can use a computer with access to MATLAB
the year mark, if appropriate) Grader, MATLAB online and offline.
Access to MATLAB help files is permitted
Total Marks:80
As Internal Examiner/Head of Department, I certify that this question paper is in final form, as approved by the
External Examiner, and is ready for reproduction.
** As Internal Examiner/Head of Department, I certify that this question paper is in final form and is ready for reproduction.
* applicable to formal examinations as approved by an external examiner.
** applicable to formal tests not requiring approval by external examiner.
Delete whichever not applicable.

Name:. Makhosazana Moyo


(INTERNAL EXAMINER)

Signature: ..........................................................

BLESSING CHIREWA
Name: ……………………………………………
(EXTERNAL EXAMINER)

Signature: …………………………………………...

Name:
Chioniso Kuchwa-Dube
……………………………………………
(HEAD OF DIVISION)

Signature: …………………………………………...

Name: Robert Reid


……………………………………………
(HEAD OF SCHOOL)

Signature: …………………………………………...
MECN2012/A
PAGE 1 of 9

QUESTION 1: Error Checking and Debugging


9:00-9:40 (5 minutes reading, 30 minutes working, 5 minutes submission)
Question 1 of 3
Reading time: 09:00 to 09:05
Working time: 09:05 to 09:35
Submission time: 09:35 to 09:40

Part A
Find and correct the ten errors in the provided code (BaseAddition.m). BaseAddition.m calculates the
sum of two numbers of any base less than base 11.

The program first ensures the lengths of two the numbers are equal by padding the shorter one with
leading zeros. For example, when adding the following binary numbers: Num1 = [1 1 1 0 1 1] and
Num2 = [1 1 1], the first part of the program must produce:

After which, the program iteratively calculates the sum of corresponding digits from the two numbers,
Num1 and Num2, considering a carry value from the previous digit addition. The final result,
FinalSum will be as follows:

Provided is a MATLAB script called Q1_InputData.m that contains the matrices Num1, and Num 2
that represent digits of the first and second number involved in the addition, listed in their original
length, as shown below.

QUESTION 1 TO BE CONTINUED OVERLEAF….

PTO/Page 1…
MECN2012/A
PAGE 2 of 9

You are required to submit only the corrected MATLAB script for Part A. The errors given will not be
of the incorrect mathematical operator (e.g. multiplication) but may be of the incorrect type thereof (e.g.
matrix multiplication instead of element-wise multiplication), however incorrect logical operators may
have been used. Note as well that there will be NO more than one error per line. Do not move, adjust
or change the line numbering in the code, if you wish to delete a line of code simply comment it
out. (10 Marks)

Part B
You are also required to submit a separate script in the tab labeled Question 1 B on MATLAB
Grader. This script must contain ONLY the error description of the 10 identified errors. Each
error description will be of the form [Line number]-[Error effect]-[Error type] where each of the
fields is as follows:
• [Line number] - the line of the original program file in which the error occurred;
• [Error effect] - the letter describing the type of effect that the error would have on the
execution of the code (from the list provided in Addendum 1 A);
• [Error type] - the number describing the type of error (from the list provided in
Addendum 1.B).
Note the following formatting requirements for the error descriptions in the separate script:
• There must be no more than 10 lines in the submitted file;
• There must be only one error description per line;
• Error descriptions must be entered in increasing order of line number;
• There should be no spaces between the segments of the error description;
• There should be no brackets in the error descriptions;
• There should be no quotation marks or any other punctuation except the hyphen.
For example, supposing there is an error due to an unrecognised variable on line 5, the
corresponding error code would be 5-B-6.

See ADDENDUM 1 A and ADDENDUM 1 B for the listed error effects and types.
(10 Marks)
(Total: 20 Marks)
ADDENDUM 1 A: Error Effect Codes
While this is not a comprehensive list of all possible error effects, when describing any error
select the effect which best describes the expected or observed effect.
A: Compilation error - Program does not run at all
B: Runtime error - Program starts execution but fails at the point of error
QUESTION 1 TO BE CONTINUED OVERLEAF….

PTO/Page 2…
MECN2012/A
PAGE 3 of 9

C: Infinite loop - Program starts execution but becomes stuck in an infinite loop due to error
code
D: Output value error - Program completes execution but output is of unexpected or incorrect
value
E: Output format error - Program completes execution but output is of unexpected or incorrect
format

ADDENDUM 1 B: Error Type Codes


Use the error effect codes below to describe the error. This is a generalised list, select the error
type code that best matches the identified error

1. Unbalanced quotation marks


2. Unbalanced parenthesis (missing bracket, mis-matched brackets)
3. Incorrect parenthesis (incorrect use of comma, semi-colon, colon)
4. Incorrect parenthesis (incorrect brackets)
5. Unknown variable (spelling/case)
6. Unknown variable (uninitialised)
7. Unknown variable (prematurely deleted)
8. Function input (incorrect syntax - spelling of function name)
9. Variable manipulation (bad index)
10. Variable manipulation (incorrect data type)
11. Variable manipulation (excess contents deleted)
12. Variable manipulation (storing order incorrect)
13. Variable manipulation (incorrect order of assignment)
14. Variable manipulation (use of equality (= =) instead of assignment (=))
15. Algorithm declaration fault (incorrect syntax)
16. Algorithm fault (missing algorithm elements)
17. Logical error (use of assignment (=) instead of equality (= =))
18. Logical error (incorrect logical operator)
19. Incorrectly implemented solution (Semantic Error)

PTO/Page 3…
MECN2012/A
PAGE 4 of 9

QUESION 2: Flowcharting and General Scripting


09:40-10:20 (5 minutes reading, 30 minutes working, 5 minutes submission)
Question 2 of 3
Reading time: 09:40 to 09:45,
Working time: 09:45 to 10:15,
Submission time: 10:15 to 10:20

Consider a program that sorts a sequence of numbers in descending order and displays the final
result. For example if given the following numbers: 1 3 2 5 3 4 10 9 8 9; the displayed output of the
program will be: 10 9 9 8 5 4 3 3 2 1. Figure 1 shows a flowchart for the given program. You are
required to convert the flow chart (as is) into a MATLAB script.

Figure 1: Flowchart for the program


Provided is a MATLAB script called Q2_InputData.m that contains the matrix Numbers, see below.

(Total: 20 marks)

PTO/Page 4…
MECN2012/A
PAGE 5 of 9

QUESTION 3: Functions and Sub-Routines

10:20-12:00 (5 minutes reading, 90 minutes working, 5 minutes submission)


Question 3 of 3
Reading time: 10:20 to 10:25
Working time: 10:25 to 11:55
Submission time: 11:55 to 12:00

You are to write three separate functions to modularise the process of reading data from multiple excel
files into a nested structure array. The main function MUST call GetFileNames and GetData in its
execution. The functions, inputs and outputs are defined as follows.

Sub-function 1: GetFileNames

This function must retrieve the file names of multiple excel files that contain the KeyWord, from your

current working directory. For example the KeyWord may be ‘Drone’.

Examples of two excel files named, ‘DroneMasses.xlsx’ and ‘DroneProperties.xlsx’ are:

‘DroneMasses.xlsx’ ‘DroneProperties.xlsx’

NB: The excel files will have multiple worksheets.

QUESTION 3 TO BE CONTINUED OVERLEAF….

PTO/Page 5
MECN2012/A
PAGE 6 of 9

The returned variable, function name and parameter list are given below:

[FileNames] = GetFileNamess (KeyWord, filetype)

The function uses as input:


1. KeyWord, the file name key word that will be used to distinguish the relevant files from
the other files in your working directory. Do not hardcode the KeyWord as it may vary.
2. filetype - is the extension of the files that contain the data that you need, i.e. ‘.xlsx’

The function must produce as output:


1. FileNames, a 1×n cell array containing the full file names of the files that contain your
desired KeyWord and extension.

Sub-function 2: GetData

This function retrieves information from the worksheets in the excel files saved in FileNames. This
function then saves the information in a structure array called Data.

Data= GetData(FileName,SheetName,CurrentSheet,Data)

This function must use as input:

1. FileName, a character array containing the full file name of each Microsoft Excel file that
contains your desired prefix and extension. Note this is singular.

2. SheetName, the name of the current worksheet in the given spreadsheet file.

3. CurrentSheet, a cell array containing all the data in the current worksheet, SheetName.

4. Data, a structure array containing all the information in the relevant excel files the working
directory. It will be initially empty.

The function must produce as output:

1. Data, a nested structure array containing all the information in the relevant excel files from
the working directory.

The numerical information from the columns in the excel spreadsheet must be saved in Data in the
following manner: Data.FileName.SheetName.ColumnName = ColumnNumericalData
QUESTION 3 TO BE CONTINUED OVERLEAF….
PTO/Page 6
MECN2012/A
PAGE 7 of 9

Where FileName no longer includes the file extension .xlsx. Note: You might find the MATLAB
built-in function split useful (only for this sub-routine).

Main: Main_Function

This main function, called Main_Function retrieves the data from the relevant files and saves the
information in a structure array called Data. The main function MUST call GetFileNames and
GetData in its execution. This function then saves the structure array, Data in a .mat file called
Q3_Output.mat.

Data = Main_Function (KeyWord, filetype)

This function must use as input:

1. KeyWord, which is the file name key word that will be used to distinguish the relevant
files that you should use from the other files in your working directory.
2. filetype, which is the extension of the files that contain the data that you need, i.e. ‘.xlsx’

Note that this function MUST call the functions GetFileNames and GetData in its execution. Failure
to do so as well as any hard coding will result in a mark of zero for this section.

This function must give as output:

1. Q3_Output.mat, a .mat file where the nested structure array Data is saved.

2. Data, a nested structure array containing all the information in the relevant excel files
from the working directory.

The numerical information from the columns in the excel spreadsheet must be saved in Data in the
following manner: Data.FileName.SheetName.ColumnName = ColumnNumericalData

Your program must run completely silently and must not require any manual inputs from the user.
Do not deviate from the structure described above. Any unexpected behaviour or code structure that
deviates from what has been outlined in here will be heavily penalised.

PTO/Page 7
MECN2012/A
PAGE 8 of 9

An example of a possible output for Data is:

QUESTION 3 TO BE CONTINUED OVERLEAF….


PTO/Page 8
MECN2012/A
PAGE 9 of 9

subfunc1 and subfunc2 are marking parameters and have automatically been included in your
solution template on MATLAB Grader. You don't have to worry about these parameters.

PROVIDED FILES

• Multiple .xlsx files – files that contain data.

DELIVERABLES
• MATLAB function submitted on MATLAB Grader that performs all the actions listed above.

Each code must contain an opening comment in the first two lines of the file with the student number
as well as the date of finalisation of the code in the following format:
%1234567
%YYYY-MM-DD
Note: Your script will be tested with different input data to what has been supplied in this exam. Do not
attempt to ‘hard code’ for any of these input cases.
(Total: 40 Marks)

(TOTAL: 80 MARKS)
----------------------END OF ASSESSMENT ----------------------

Page 9

You might also like