Having difficulty with assignment!

closed account (1y7j1hU5)
I am taking this class and am almost finished! This is the second to last assignment I have to do do but I am having computer issues. Please help me pass this class! Thank you!

Assignment 14.1 [15 points]

This assignment will not be graded for style issues. If your code works correctly, you'll get 15 points. Style will be graded next week.

Note: Full documentation (comments) is required as described in Style Convention 1D

Create a class named boolMatrix for storing and processing a two-dimensional array of bool values. The class should be saved in a specification file and an implementation file. A client file is not provided. You'll need to write your own client file to test your class. I'll be creating my own client program to test your class after you submit it.

You'll be defining two constants in your class, but you need to know a little bit about "static" members of classes first. With all of the class members we have used so far, each class object that the client declares has its own copy. With a "static" member, there is just one copy of the member that all objects share. Since constants don't change, it makes sense to just have one copy that all objects share. So, when you declare constants, you must make them static.

In the public area of your class you must define two public constants, NUM_ROWS AND NUM_COLS. I'll give you this code for free:

static const int NUM_ROWS = 20;
static const int NUM_COLS = 20;
In your client program, if you need to use these constants, you can't access them in the usual way of using a calling object and a dot operator, because they aren't associated with one particular object. So you'll use the scope resolution operator instead. For example:

if (myRow < boolMatrix::NUM_ROWS)
There are a few places in the descriptions of the member functions below where you are required to use "assert()". Here is a quick tutorial on using assert. First, you need to place #include <cassert> at the top of your implementation file. Then you can call a function named assert(), placing a logical expression inside the parentheses. If the logical expression is true, nothing happens. If the logical expression is false, the program exits and an error message is printed. For example, your assert might look like this:

assert(row >= 0 && row < NUM_ROWS);
In the functions below that state that assert() is required, the purpose is to ensure that the client has provided legal parameters. This means that it will be the first line of the function.

The class will have exactly one private data member that is an array of bool. The class will have seven member functions:

default constructor: initialize all of the array elements to false
get: return the current contents of a single array element. Use arguments to indicate the row and column of the array element that should be returned. This function must use assert to exit the program if the row or column is out-of-bounds.
set: set the contents of a single array element. Use arguments to indicate the row and column of the array element that should be set, and the value to which it should be set. This function must use assert to exit the program if the row or column is out-of-bounds.
rowCount: return the number of true values that exist in any given row. This function must use assert to exit the program if the row is out-of-bounds.
colCount: return the number of true values that exist in any given column. This function must use assert to exit the program if the column is out-of-bounds.
totalCount: return the number of true values that exist in the entire array.
neighborCount:Given two arguments that indicate the row and column of a particular cell in the matrix, this function returns the number of neighbors that have the value "true". Most positions in the grid have 8 neighbors like the center square in a tic-tac-toe game. The four corner positions have only 3 neighbors each. The remaining positions around the edge of the grid have 5 neighbors each. This function must use assert to exit the program if the row or column is out-of-bounds.

Additional neighborCount() Requirement: In this function you must use your "get()" function to access the matrix, instead of accessing your 2D array data member directly. So, if your data member is named "m", you'll say "get(row, col)" instead of "m[row][col]". This will be a safer programming practice, since the get() function will do range checking for you (i.e., it will make sure that row and col are not out-of-bounds of the 2D array).

print: display the contents of the array, including the row and column indices. For each element of the array, a true value must be displayed as an asterisk ("*") and a false value must be displayed as a space. This member function is the only one that displays output. It should be formatted as demonstrated here. Make sure that the row and column labels still work correctly if the constants (NUM_ROWS and NUM_COLS) are set to something different, say, 30 instead of 20.
01234567890123456789
0
1 * *
2 * * *** *
3 * **** *
4 * * * **
5 * * ***** *
6 ** * * *** *
7 * *** * *
8 ****
9 * ******
10* * *
11 * * ** *
12** **** ***
13 * *** ** *
14 * * * ***
15 ** *** ** **
16 * * **
17
18
19
The above picture is just for illustration. It's not necessary to create a grid this complex for purposes of testing your class. Note that if you only have a constructor and a print() function, the picture above will be completely blank except for the row and column labels.
Hints and Additional Requirements:

The neighborCount() function is the most difficult part of this assignment. It's possible to write this function in 8 lines (not counting lines that have only a close curly brace). If you can keep it under about 20 lines that's still pretty good. Here's a hint: write the function so that it only works on cells in the middle of the matrix first. Then you should be able to just add a few lines to handle the boundaries. If you take this approach but then find that you are adding a lot of code to handle corner and edge cells, then you are thinking about it wrong.

Many students struggle with this assignment because you are not writing to produce any particular output. Unlike previous assignments, what you are creating here is a tool for someone else to use, not an actual program that does something. You will create a client program that does whatever you want it to do, but the sole purpose of that client program will be to test your class and make sure it works. You won't submit your client program, and no one else will ever see it.

As always when writing code, write as little code as possible and then test it to see whether what you have so far is working. For this assignment, one idea would be to just write your constructor, and then test it with a client program that does nothing other than declare a boolMatrix object. If that compiles, add a print() function so that you can then check to see if the constructor is initializing the boolMatrix correctly. And so on.

Use const to indicate const functions and unchangeable reference parameters whenever possible.

Here is a small client program that might help to get you started. It is far from exhaustive and you should do further testing before you submit your class.

#include <iostream>
#include "boolmatrix.h"
using namespace std;

int main() {
boolMatrix matrix1;

for (int i = 0; i < 50; i++) {
matrix1.set(rand() % 20, rand() % 20, true);
}

matrix1.print();
cout << endl;
cout << matrix1.rowCount(10) << endl;
cout << matrix1.colCount(10) << endl;
cout << matrix1.totalCount() << endl;

for (int row = 0; row < boolMatrix::NUM_ROWS; row++) {
for (int col = 0; col < boolMatrix::NUM_COLS; col++) {
cout << matrix1.neighborCount(row, col);
}
cout << endl;
}
}
Do not submit the client program that you created to test your class.

Submit Your Work

Name your source code files boolmatrix.cpp and boolmatrix.h. Do not submit your client, and do not paste your output. Use the Assignment Submission link to submit the source files. When you submit your assignment there will be a text field in which you can add a note to me (called a "comment", but don't confuse it with a C++ comment). In this "comments" section of the submission page let me know whether the class works as required.


We don't do homework, good luck with your class.
@Swimmmer

I have to do do but I am having computer issues. Please help me pass this class! Thank you!


For someone having computer problems, you didn't seem to any problem logging into this site, and posting your homework.

And, I'm guessing here, only YOU can make sure you pass the class.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/219812/
Topic archived. No new replies allowed.