程序代写案例-ECE 3514
时间:2021-09-07
ECE 3514: Project 1.1
Ryan M. Gerdes & Sook Shin Ha
{rgerdes,sook}@vt.edu
Virginia Tech — 2021-09-02
Introduction
This is our first homework for 3514 and it has a few foci:
1. Writing a basic class in C++
2. Writing some basic tests using a framework called Catch
3. Submitting to the autograder for this class
4. Using CMake
Essentially, the goal of this assignment is to refresh your programming skills, recall material from ECE 2804/2514,
and get familiar with the course work-flow. If you struggle with this assignment it means that you will need
to devote additional time to the course, including seeking advice from the TAs and myself, or as a last resort
drop.
1 The Matrix Class
The class you are to define and implement represents a two-dimensional matrix. The class itself is not terribly
difficult but rather it is meant to get you back in the mode of writing code and writing classes in C++. The
class, named Matrix, will support common arithmetical/operational functions:
• a default constructor that creates a 2-by-2 matrix with all elements equal to zero
• construction of a matrix initialized with user-provided elements
• methods to return an element of the matrix
• methods to set the elements of the matrix
• a method to return the size of the matrix’s dimensions
• a method to check if two matrices are equal
• a method to add two matrices
• a method to subtract two matrices
• a method to multiply two matrices
• a method to multiply a matrix by a scalar
• a method to raise a matrix to a power
• a method to transpose a matrix.
1
The outline of the class is defined in the starter code inside the file Matrix.hpp. Do not modify the
public or private portions of the class definition. You will need to define the internal members and methods
and implement all methods in the Matrix.cpp file. You should add appropriate comment blocks to each
method, as well, in Matrix.cpp. You will need to write tests in the student_tests.cpp using the Catch
testing framework, as described in class. The included CMakeLists.txt file sets up everything for you. Just
generate your build directory for your development environment as described in the course work-flow tutorial.
Info: Catch is one (of many) unit testing platform in C++. It’s relatively easy to use: you simply need to
#include the catch header and you’re off and running. The tests then consist of a series of functions that
will test your code. The tests looks something like this:
TEST_CASE( "default␣constructor", "[Matrix]" )
{
INFO("Hint:␣default␣constructor␣(linear␣get()␣must␣work)");
Matrix A;
REQUIRE(A.get(0) == 0);
REQUIRE(A.get(1) == 0);
REQUIRE(A.get(2) == 0);
REQUIRE(A.get(3) == 0);
REQUIRE(A.size (1) == 2);
REQUIRE(A.size (2) == 2);
}
The file will consist of a series of these TEST_CASEs. The test cases have a string in the parenthesis
that “names” the test case and so it must be unique. Then in the test case, you write code that will test
your code. In the example, I have made a Matrix object, A, using the default constructor and the header
file tells me that after using the default constructor a 2-by-2 matrix with all elements set to zero should
be created, so I’m using the REQUIRE function to state that elements 0, 1, 2, 3 must equal 0 and the first
and second dimension of the matrix should be 2.
After this, you’ll be adding other test cases that will test the rest of the class. You’ll need to test each
method at least once. Writing good tests is a skill and can take time to work out. Focus on what the class
says it should do and think logically about how to test to see if it does.
i
2 Grader
We will be using an automatic grader to help you determine your assignment’s completeness and correctness.
A portion of each assignment grade will be determined by the number of passing tests as determined by the
autograder, with our evaluation filling in the rest. This means you know before you turn in your submission
that all is well. You can submit to the autograder as many times as you like, but it is rate limited (4 submissions
every hour) to keep you from using it as your compiler. See this canvas for a summary of how to use the grader
(Note is is not WebCAT, which many of you may be familiar with).
For this assignment you should upload a zip file containing only the files: Matrix.cpp and student_tests.cpp.
There is a build target called “submission” configured by default to create this file with the correct contents
in your build directory.
3 Submission
Once you are satisfied with your code, upload a zip file containing (only) Matrix.cpp and student_tests.cpp
through Canvas at the assignment link. You should not submit the other files from the starter code, nor your
2
build directory. There is a build target called “submission” configured by default to create this file with the
correct contents in your build directory.
4 Grading
There are 40 points allocated to this assignment.
• Correctly submitting the required files: 2 points
• Your tests compile: 3 points
• Your tests pass: 10 points (proportional)
• Instructor tests compile with your code: 3 points
• Instructor tests pass: 17 points (proportional)
• Design requirements met (e.g., code and test quality, comments): 5 points
As per the syllabus, good faith efforts must be made to write comprehensive tests. Since there is no way to
test for this at compile or run time (at this point), should the grader (person) deem your tests to be woefully
lacking you will lose not only design points but also the points given by the autograder. Each method should
be tested.
3

欢迎咨询51学霸君