Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ENCMP Assignment, I'm very confused on how to do it. ENCMP 100-Computer Programming for Engineers Page 1 of 7 ENCMP 100 - Computer Programming for

ENCMP Assignment, I'm very confused on how to do it.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

ENCMP 100-Computer Programming for Engineers Page 1 of 7 ENCMP 100 - Computer Programming for Engineers Assignment #2 Due: Friday, Feb. 12, 2021 at 6:00pm MST Objective This assignment is designed to provide you with practice using selection statements to solve an encoding problem. There are many applications for encoding and decoding information in engineering contexts. For example, in the area of Computer Engineering there is often a need to transmit information from one place to another, e.g. the Internet. In some situations, the information must be converted into a form suitable for transmission from the source to the destination. The encoded information must then be decoded at the destination before it can be used. There are several ways to encode and decode information, e.g., some are designed for secure data transmission, while others decrease the size of the data to be stored or transmitted (compression). Marking Scheme You will get a total of 100 points for completing the following: TASK Successful testing of Rules Quality of code TOTAL POINTS 50 50 100 . Points for Quality of Code Complete file header (see Hints for an example) Design (appropriate use and naming of variables) Comments in the code Layout (indentation/spacing) Did you follow filename naming convention . Submission Filename naming convention Assign2 .m Ex. CCID or email: jmac filename for assignment #1 is Assign2jmac.m Submit only your .m file under Assignment 2 in your eClass/Moodle account. The assignment is due on Friday, Feb. 12 2021 at 6:00 pm MST Please thoroughly test your code to ensure functionality. OneClass you have 20 submissions or updates until the deadline. . ENCMP 100-Computer Programming for Engineers Page 2 of 7 Background Your friend Maverick recently landed a lucrative engineering co-op work term in an oil- rich country. Meanwhile, you chose to make a modest salary as a co-op intern with the Canadian Security Intelligence Service (CSIS). A week after arriving in the foreign country, Maverick is kidnapped by rebels opposed to oil exploration. He is held captive in a small village within rebel territory. Luckily, a group of disenchanted rebels are willing to smuggle Maverick to one of seven rendezvous points: the village bridge the village library river crossing nearby airport bus terminal hospital at St. Pete's Church where an allied helicopter will pick them up and fly them to safety. For the plan to work, the friendly rebels need to know two pieces of information: the day of the rendezvous the rendezvous point CSIS has devised a nine-digit code to carry this information to the friendly rebels. When the time is ripe, CSIS will insert a coded message into the online newspaper of the oil- rich country, as a number on the front page. The rebels have Internet access via satellite links and follow the news. While it is helpful (as a decoy strategy) that the newspaper has other numbers on the front page, e.g. in real adverts, it is vital that the rebel insiders can detect and decode the secret message. CSIS has found a way to smuggle a decoder to the friendly rebels. You are asked to program the decoder in MATLAB. The safety of your friend Maverick depends on your ability to program the decoder correctly. Details The four rules for detecting and decoding the code are as follows: 1. Prompt the user to enter a code using the input command, and a valid code must be a 9-digit number e.g. 123456789, message MAY be valid e.g. 12345678, message invalid e.g. 1234567890, message invalid Assume that the input data contains only digits, with a non-zero first digit. ENCMP 100-Computer Programming for Engineers Page 3 of 7 2. The code must pass the odd-even truth" test. - If the sum of the digits is odd, the message is invalid. e.g. 222222223, sum - 19, message invalid - If the sum of the digits is even, the message MAY be valid. e.g. 222222222,, sum=18, message may be valid 3. To determine the rescue day, multiply the Ist digit by the 3rd digit, then subtract the 5th digit. The answer indicates the rescue day, as follows: 7 - Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4= Thursday 5 - Friday 6 = Saturday Any other number indicates that the message is invalid. Examples: 234567890 712245420 2x4-6 = 2 7x2-4 = 10 Rescue is on Tuesday Message is invalid. 4. To determine the rendezvous point, this is completed in two steps, first multiply the 2nd digit by the 4th digit, then subtract the 6th digit second determine if the resulting value is divisible by 3 If the following result when you multiply the 2nd digit by the 4th digit, then subtract the 6th digit is divisible by 3, then the rendezvous point is 7th digit minus 9th digit If the following result when you multiply the 2nd digit by the 4th digit, then subtract the 6th digit is not divisible by 3, then the rendezvous point is 8th digit minus 9th digit . If the result is one of the following rendezvous numbers, the message is valid: Rendezvous Number 2 3 Rendezvous Point bridge library river crossing airport bus terminal hospital St. Petes Church 4 5 6 7 Any other rendezvous number means that the message is invalid ENCMP 100-Computer Programming for Engineers Page 4 of 7 Output Your output should look like the example screenshots below. Here are 3 valid messages: Command Window Please enter a code to break: 111600542 Rescue on Monday at the river crossing. >> | X Command Window Please enter a code to break: 364686902 Rescue on Thursday at St. Petes Church. fx >> Command Window Please enter a code to break: 332837840 Rescue on Wednesday at the airport. fx >> Your output for invalid messages should indicate only the first reason encountered for rejecting the message. The reasons are one of the following, in this order: Decoy Message: Not a nine-digit number. Decoy Message: Sum is odd. Decoy Message: Invalid rescue day. Decoy Message: Invalid rendezvous point. ENCMP 100-Computer Programming for Engineers Page 5 of 7 Command Window Please enter a code to break: 1234567 Decoy message: Not a nine-digit number. >> Command Window Please enter a code to break: 364686910 Decoy message: Sum is odd. >> | Command Window Please enter a code to break: 362182666 Decoy message: Invalid rescue day. Command Window Please enter a code to break: 364686911 Decoy message: Invalid rendezvous point. ENCMP 100-Computer Programming for Engineers Page 6 of 7 Code Requirements You are required to use two switch statements in this assignment, one to determine the rescue day and another to determine the rendezvous point. Failure to use two switch statements in this assignment will result in a mark of zero on Successful testing of the rules portion of the mark breakdown. Use the input command to enter the code to test. Do not use the error function, use either disp or fprintf functions to display outputs to the command window. Hints 1. Before you even begin to write out any MATLAB code, sit down and sketch out your program design in abbreviated English. This kind of high-level program design is called pseudo code. Please see secondary link for full pseudo code of the assignment two. It would start off something like this: Get secret code from user as a string Get an array of the individual digits If code not 9 digits Output error message Else Get sum of digits If sum is odd Output error message Else Get rescue day Etc. ... Notice how the logic naturally translates into an if-else chain. The if clauses in the chain contain messages for invalid codes. After such a message is output, the control flow breaks out of the entire chain. You end up reaching the final else clause in the chain only if the code is valid. It is there that the valid message is composed and output. For the complete pseudo code for this assignment, please see second link on Class site under Assignment #2. Please note that the posted pseudo code is a "first pass" attempt of what you should do when creating pseudo code for your assignments. 2. To help you read in a secret code from the user as a string, type in help input on the command window or search the input command using the help function. 3. When converting an array of characters (string) to an array of numbers, you need to subtract the ASCII value of zero from each character. For example, if your string is called code_str and your number array is called digits, you can do the following: digits = code_str - '0'; ENCMP 100-Computer Programming for Engineers Page 7 of 7 4. Remember to use the built-in MATLAB functions. For example, to check if the string contains nine digits, you might find the length function helpful. To find the sum of the digits, you might find the sum function helpful. To check if the sum of digits is odd or even, you may find the mod function helpful. 5. Build up your program design in stages. After you have completed the code for Rule 1, compile and test with a variety of codes that satisfy and fail to satisfy the rule. Then go on to write the code for the next rule, etc. 6. Please remember to include your header at the top of your.m file. Copyright (c) 2020, Dileepan Joseph All rights reserved. Student name: Student CCID: Others: To avoid plagiarism, list the names of persons, whose code, ideas, images, or data are used in any derivative work. To avoid cheating, list the names of persons, other than your course or lab instructor who provided compositional assistance. After each name, including the student's, enter in parentheses an estimate of the person's contributions in percent. Without these numbers, which add to 100%, follow-up questions will be asked. For an unknown person, e.g., an anonymous online source that should be avoided, enter a code name in uppercase, e.g., SAURON, and email the lab instructor prior to submission with the corresponding URL. clear; deletes all the saved variables clc; clears the Command Window

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions