EE1301_HW5
pdf
keyboard_arrow_up
School
University of Minnesota-Twin Cities *
*We aren’t endorsed by this school
Course
1301
Subject
Electrical Engineering
Date
Apr 3, 2024
Type
Pages
7
Uploaded by KidFishPerson934
EE 1301: Introduction to Computing Systems
Homework 5 - Arrays and Strings
Purpose
Now that you have rich sources of data, like files, you will likely need new programming
constructs to organize your data. In this assignment, you will begin to store and process
information in arrays and use strings to parse data.
Recommended Reading (zyBooks)
❏
7.1 Arrays
❏
7.2 Iterating through arrays
❏
7.6 Functions with array parameters
❏
6.5 File input
❏
6.7 File output
❏
7.12 Command-line arguments
❏
8.12 Two-dimensional arrays
❏
8.13 Char arrays / C strings
❏
8.14 String library functions
Libraries
You may use the following libraries for this assignment:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
Problem A: Maze Runner 2.0 (5 points)
You
have
been
hired
to
develop
a thrilling C++-based game called Maze Runner (see
mazeRunner_v2.cpp
). Go play this game now to see what you are getting yourself into!
Through extensive play testing research, your marketing team has determined that you must
add two new features to the Maze Runner game: “walls” and a “custom level”.
The “walls” feature adds impassable terrain to the game, which will appear as a ‘W’ in the maze
and should stop the Robot from moving into that square. First, you will need to add the ability to
add ‘W’s to the maze to represent the walls. Then, you must modify the robot movement,
defined in updateGrid(), so that if you try to move into a wall, you will not go anywhere. You
should create a new default board, defined in initBoard() by adding some ‘W’s (walls), changing
the initial position of ‘X’ (robot start), and moving the goal ‘O’ (cookie) to a different location.
The “custom level” feature will allow players to modify the game board with a simple text editor.
To support this feature, you must modify mazeRunner_v2.cpp to read in a maze from a file
named maze.txt. The file will specify the locations of game elements (i.e., '-', ‘X’, ‘O’, or ‘W’) in
the maze. If maze.txt does not exist in the current directory, your program should default to the
board you defined above. You can assume that the custom levels all match the size of the
default board, which is 10x10.
An example file (
maze.txt
) is provided for you to test with, which corresponds to the example
below.
Example Output
WWWW-O-WWW
---W-X----
--WWWWWW-W
----------
WWWWWWWWW-
----------
-WW-WW-WW-
----------
WW-WW-WW-W
----------
Where would you like to go? (l, r, u, d)
u
WWWW-X-WWW
---W------
--WWWWWW-W
----------
WWWWWWWWW-
----------
-WW-WW-WW-
----------
WW-WW-WW-W
----------
You found the cookie! Congratulations!
Edit the provided
mazeRunner_v2.cpp
file to include the changes described above. Rename
and submit the Maze Runner 2.0 file using the normal convention (e.g., “username_hw5A.cpp”).
Problem B: Random Matrix (5 points)
Write a program that generates a 2D matrix filled with random values and stores it in an output
file “randArray.txt” in the same directory as the program. Your program should take three integer
values as
command line inputs
: the number of rows in the matrix (numRows), the number of
columns (numColumns), and a number specifying the range of random values stored in the
matrix (arrayMax). On the first line of the output file, you will write the number of rows and the
number of columns in the matrix, separated by a space. Starting on the second line of the
output file, you will write a 2D matrix with numRows rows and numColumns columns. The
values in the matrix will be random numbers between -arrayMax and +arrayMax, inclusive.
Values on the same row will be space-delimited, and each row will end with a newline.
DO
NOT
USE
“cin”
in
any
way. Your program should utilize the command line
arguments as the *only* input.
Your program must check if the right number of command line arguments have been provided. If
not, print to the terminal an appropriate error message, as shown below, and exit your program
with a return value >0.
Example Output
$ ./HW5B 2
$ Please provide exactly 3 integer values as command line
arguments.
Correct usage: ./HW5B <numRows> <numColumns> <arrayMax>
$ ./HW5B 4 4
$ Please provide exactly 3 integer values as command line
arguments.
Correct usage: ./HW5B <numRows> <numColumns> <arrayMax>
Note that you do not actually need to store the array in your code.
You are simply
generating a series of numbers and printing them to the output file as a space-delimited matrix.
Example Output
$ ./HW5B 2 3 0
$ cat ./randArray.txt
2 3
0 0 0
0 0 0
$ ./HW5B 4 4 8
$ cat ./randArray.txt
4 4
-1 4 -2 -3
1 6 -8 2
6 -4 -4 -6
2 8 -2 -2
Name
and
submit
your
source
file
using
the
normal
convention
(e.g.,
username_hw5B.cpp).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Problem C: Pixel Averaging (5 points)
You are given a computer system that stores gray-scale images using a 2D array of pixels. Each
pixel stores the intensity value as an integer. A common image filtering function (called blurring
or smoothing) replaces the intensity value of each pixel with the average of the intensities of the
given pixel and each pixel surrounding it.
For example, in the grid shown below, the intensity value for pixel Y is replaced with the average
of Y and all of the pixels marked X that surround it.
X
X
X
X
Y
X
X
X
X
B
1
B
2
A
B
3
D
1
D
2
B
5
B
4
D
3
C
If the pixel is on the edge of the image so that it does not have a full set of eight neighbors, such
as pixel A (shown above), the new value is the average of only the pixel and its existing
neighbors, marked B
i
in this example.
A
new
= (A+B
1
+B
2
+B
3
+B
4
+B
5
) / 6
Likewise, if the pixel is in the corner (in other words, on 2 edges), the average will be:
C
new
= (C+D
1
+D
2
+D
3
) / 4
Write a program that reads a 2D array of signed integers from an input file, whose name is
provided by a command line argument, and performs this averaging process on the input array.
The first line of the input file will contain the number of rows and columns in the array, separated
by a space, and the remaining rows of the file will contain the space-delimited array. The output
generated by performing the average filtering on the input should also be stored in an array. The
output intensity values should be printed from this array to
console out
as integer values. You
may assume that the input arrays will not be larger than 100x100, but your code should make
the maximum array dimension a configurable value controlled by a constant integer.
You should use functions appropriately to make your program easy to read and understand. You
should be able to use your array-generating program from Problem B to generate inputs to test
this program.
Example Input - randArray.txt
$ cat randArray.txt
4 4
-1 4 -2 -3
1 6 -8 2
6 -4 -4 -6
2 8 -2 -2
Example Output
$ ./HW5C randArray.txt
0 -1 0 -1 -1
1 -1 0 0 1
0 -1 0 -1 0
1 0 0 0 2
4 0 1 0 2
Hints
This program is more complex than most that you have written so far this semester. It may be
helpful to split the problem into different sections and solve each section in sequence. For
example, reading the input, performing the computation, and writing the output. Debug each of
these independently, then combine them. For example, use a static array in memory to test the
computation stage, rather than testing with random data from the input stage. Use a static test
input for which you know what the output should be (e.g., an array containing all ones). This will
allow you to more easily check for correct behavior. Each of these stages can be encapsulated
into its own independent function(s). In the computation stage, check whether each neighboring
location to a pixel exists before using it in the average calculation.
How to Test Your Program
It can be difficult to test programs with random inputs. You will need to generate ‘deterministic’
test cases for your program that are fixed and non-random.
There are at least two good ways to do this. First, you may want to use manual input for your
test array. In developing these test cases, make sure you exercise your program with different
types of input combinations, and try to think of how you can cover any corner cases. These are
often the places where small errors result in outputs that are slightly off. As mentioned above, a
good manual test case is an array containing all ones, since it is easy to verify whether the
output is correct. The second option you can use to generate good test cases is to capture one
set of random data and re-run your code over that data set multiple times, checking that the
corresponding responses are correct and consistent.
Run your code a couple times in a row with the exact same inputs as well, which will help show
if your arrays are actually random or if there is an issue with your random number seeding.
Example Test Case
Note: You can create a text file just by opening a text editor, such as geany, with the name of the
new file and then saving it once you have entered the data.
$ geany manualArray.txt
“Typing in array manually and saving file”
$ cat manualArray.txt
3 3
1 2 3
4 5 6
7 8 9
$ ./HW5C manualArray.txt
3 3 4
4 5 5
6 6 7
Submission
Please submit the following files in Canvas - Gradescope:
username
_hw5A.cpp
username
_hw5B.cpp
username
_hw5C.cpp
It is important that you follow the file naming conventions carefully.
Please note that the
auto-grader will not compile your submission if it is named incorrectly. Please also note the
following:
●
Your username should be all in lowercase
●
You should not include “@umn.edu”
●
The filename should contain an underscore (not a dash)
●
The ‘A’ in “5A” is upper case
●
The extension for your source files is .cpp
Following rigorous naming conventions is something computer programmers often must do, and
submitting your program with the correct name is part of doing this assignment correctly.
Grading
As in Homework 1, all submissions should be in the form of a source file that compiles without
error and executes correctly on the CSE Linux machines / Gradescope.
This assignment will be graded as follows.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Problem A - 15pts
●
Manual Grading
○
(1 pt) Default Board
○
(2 pts) Basic Movements
○
(1 pt) Movement against Wall
○
(2 pts) Initialize Board & Exit
○
(4 pts) Custom Board - File Handling - Open, Check if open, Close
○
(2 pts) User interface (I/O formatting)
○
(3 pts) Coding Style - readability, header, and comments with your name, etc.
Problem B - 15pts
●
Autograder:
○
(2 pts) Invalid number of Arguments & Exit
○
(1 pt) Output File - randArray.txt in the same directory
○
(2 pts) User interface (I/O formatting)
●
Manual Grading
○
(4 pts) Randomization & Range
○
(3 pts) File Handling - Open, Check if open, Close
○
(3 pts) Coding Style - readability, header, and comments with your name, etc.
Problem C - 15pts
●
Autograder
○
(1 pt) Invalid Input & Exit
○
(6 pts) Testcases
●
Manual Grading
○
(3 pts) File Handling - Open, Check if open, Close
○
(2 pts) User interface (I/O formatting)
○
(3 pts) Coding Style - readability, header, and comments with your name, etc.
Related Documents
Related Questions
How to do ?
Need
*State diagram
*State/output table
*Transition table
*Transition equation
*Excitation equation and output equation
*Logic circuit diagram
arrow_forward
Using the assembly of Mano’s Basic Computer, write a program That finds the division of two numbers to be taken from the input device as 8 bits two signed binary numbers ( X and Y). The Z register( X/Y) will be sent to Out device as 8 bits.
Please below schema includes mano symbols.
arrow_forward
Translate the following C program into an assembly program. The C program finds the
minimal value of three signed integers. Assume a, b, and c are stored in registers r0, r1, and
r3, respectively. The result "min" is saved in register r4.
if(a <= b && a < c)
{
min = a;
}
else if(b < a && b
arrow_forward
Design a code converter that converts a decimal
digit from BCD to excess-3 code, the input variables
are organized as (A B C D) respectively with A is the
MSB, the output variables are organized as (W XY
Z) respectively with W is the MSB, put the invalid
decimal numbers as don't care.
W=A+BD+BC'
W=A+BD+BC,
W=A'+BD+BC
W= BC'D'+B'D+B'C
arrow_forward
could you help me with question d) pls
thanks
arrow_forward
Number 2 please
arrow_forward
Answer the question B, no need to answer A
arrow_forward
Explain how you would derive Hamming codes for 1 byte data values. Then find the Hamming codes for the following data values (all in decimal): (a) X = 5, (b) X = 7, (c) X = 12, (d) X = 15. Express your answers in hexadecimal.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you

Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:PEARSON

Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning

Programmable Logic Controllers
Electrical Engineering
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education

Fundamentals of Electric Circuits
Electrical Engineering
ISBN:9780078028229
Author:Charles K Alexander, Matthew Sadiku
Publisher:McGraw-Hill Education

Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:9780134746968
Author:James W. Nilsson, Susan Riedel
Publisher:PEARSON

Engineering Electromagnetics
Electrical Engineering
ISBN:9780078028151
Author:Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:Mcgraw-hill Education,
Related Questions
- How to do ? Need *State diagram *State/output table *Transition table *Transition equation *Excitation equation and output equation *Logic circuit diagramarrow_forwardUsing the assembly of Mano’s Basic Computer, write a program That finds the division of two numbers to be taken from the input device as 8 bits two signed binary numbers ( X and Y). The Z register( X/Y) will be sent to Out device as 8 bits. Please below schema includes mano symbols.arrow_forwardTranslate the following C program into an assembly program. The C program finds the minimal value of three signed integers. Assume a, b, and c are stored in registers r0, r1, and r3, respectively. The result "min" is saved in register r4. if(a <= b && a < c) { min = a; } else if(b < a && barrow_forwardDesign a code converter that converts a decimal digit from BCD to excess-3 code, the input variables are organized as (A B C D) respectively with A is the MSB, the output variables are organized as (W XY Z) respectively with W is the MSB, put the invalid decimal numbers as don't care. W=A+BD+BC' W=A+BD+BC, W=A'+BD+BC W= BC'D'+B'D+B'Carrow_forwardcould you help me with question d) pls thanksarrow_forwardNumber 2 pleasearrow_forwardarrow_back_iosarrow_forward_ios
Recommended textbooks for you
- Introductory Circuit Analysis (13th Edition)Electrical EngineeringISBN:9780133923605Author:Robert L. BoylestadPublisher:PEARSONDelmar's Standard Textbook Of ElectricityElectrical EngineeringISBN:9781337900348Author:Stephen L. HermanPublisher:Cengage LearningProgrammable Logic ControllersElectrical EngineeringISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
- Fundamentals of Electric CircuitsElectrical EngineeringISBN:9780078028229Author:Charles K Alexander, Matthew SadikuPublisher:McGraw-Hill EducationElectric Circuits. (11th Edition)Electrical EngineeringISBN:9780134746968Author:James W. Nilsson, Susan RiedelPublisher:PEARSONEngineering ElectromagneticsElectrical EngineeringISBN:9780078028151Author:Hayt, William H. (william Hart), Jr, BUCK, John A.Publisher:Mcgraw-hill Education,

Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:PEARSON

Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning

Programmable Logic Controllers
Electrical Engineering
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education

Fundamentals of Electric Circuits
Electrical Engineering
ISBN:9780078028229
Author:Charles K Alexander, Matthew Sadiku
Publisher:McGraw-Hill Education

Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:9780134746968
Author:James W. Nilsson, Susan Riedel
Publisher:PEARSON

Engineering Electromagnetics
Electrical Engineering
ISBN:9780078028151
Author:Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:Mcgraw-hill Education,