Question
2. (15 pts) You are required to fix all syntax and build errors. If the error is directly related to an environment specific condition (i.e.
2. (15 pts) You are required to fix all syntax and build errors. If the error is directly related to an environment specific condition (i.e. only works on Linux, but not Windows), then comment out the statement causing the problem. You do NOT need to find an equivalent fix for the other environment.
3. (45 pts 5 pts/test case) Once you have fixed all syntax and build errors, please place the class queue and all its function definitions to a separate header file called queue.h. You are required to write unit tests for all functions or units in queue.h excluding the constructor, and the destructor, in the project. Your objective is to achieve 100% branch coverage for each unit. For each unit test you are required to construct a comment block with the information described in the background section What is a test case?, and implement a test function for the corresponding test case. Each test function must have a function declaration that is placed in a file called testQueue.h or testQueue.hpp and all test function definitions and comment blocks must be placed in a file called testQueue.cpp. A test function should always be declared as void testFunctionName (void). This means we want these tests to be self-contained. They do not accept any arguments and do not return any results. All setup and evaluation for the test is done inside the function. Hint: you will need 1 test case for each of the following functions: queue::size () queue::isEmpty () queue::isFull (), you will need 2 test cases for the following: queue::dequeue () queue::enqueue () queue::peek () Call your test functions from main (). At this point do NOT fix the bugs discovered! This will be done as part of the next step! Place the results of each test case, i.e. pass or fail in the same comment block as the test case comment block.
4. (20 pts) Fix all bugs revealed by your test cases. Show a screen shot or picture of one break point that you have added to a unit to debug, where the bug was identified by one of your test cases. To this end, you should use a debugging tool (gbd, CLion, or VS Code). The picture should end up in a .pdf file.
5. (15 pts 3 pts/attribute) Using your understanding of design choices, software principles, and coding standards, which we will group under the general label attributes list and describe 5 attributes demonstrated by the code that you would consider poor. These should NOT be related to the syntax errors. Examples of poor attributes could be related to comments, file structure, data structure selection, algorithm efficiency, etc. Place your list in a comment block at the top of the main.cpp file.
IV. Submission options: 1. Option 1: Git (1) On your local file system, and inside of your Git repo for the class, create a new branch called MA1. In the current working directory, also create a new directory called MA1. Place all MA1 files in the directory, if you are not directly working in your repo. All files for MA 1 must be added, committed, and pushed to the remote origin which is your private GitHub repo created in PA1 (DO NOT CREATE NEW REPO).
(2) You must submit at least two header file (testQueue.h or testQueue.hpp file, and queue.h), two C++ source files (called main.cpp, which has your bug fixes, and testQueue.cpp), one .pdf file with your screen shots or pictures (paste all figures to a MS Word and save as .pdf), and a .txt file containing your building commands on Linux/WSL/MacOS (e.g., a CMakeLists.txt, a Make file or a plain .txt file including your g++ building command) which can compile your code.
This is the code to make test functions and fix bugs.
// This code was taken from https://www.techiedelight.com/queue-implementation-cpp/
// The code has been modified from the original to provide opportunities to learn
#include
#include
using namespace std; // define default capacity of the queue
#define SIZE 10
// Class for queue
class queue
{
int* arr; // array to store queue elements
int capacity; // maximum capacity of the queue
int front;// front points to front element in the queue (if any)
int rear;// rear points to last element in the queue
int count;// current size of the queue
public:
queue(int size = SIZE); // constructor
~queue(); // destructor
void dequeue();
void enqueue(int x);
int peek();
int size();
bool isEmpty();
bool isFull();
}
// Constructor to initialize queue
queue::queue(int size)
{
arr = new int[size];
capacity = size;
front = 0;
rear = -1;
count = 0;
}
// Destructor to free memory allocated to the queue
queue::~queue()
{
delete arr; // you are not required to test this function; // however, are there issues with it?
}
// Utility function to remove front element from the queue
void queue::dequeue()
{
// check for queue underflow
if (isEmpty())
{ cout << "UnderFlow Program Terminated "; return; }
cout << "Removing " << arr[front] << ' ';
front = (front + 1) % capacity; count--;
}
// Utility function to add an item to the queue
void queue::enqueue(int item)
{
// check for queue overflow
if (isFull())
{ cout << "OverFlow Program Terminated "; return; }
cout << "Inserting " << item << ' '; rear = (rear + 1) % capacity;
arr[rear] = size(); count++;
}
// Utility function to return front element in the queue
int queue::peek()
{
if (isEmpty()) { cout << "UnderFlow Program Terminated "; return numeric_limits::min(); }
return arr[rear];
}
// Utility function to return the size of the queue
int queue::size()
{
return count + 1;
}
// Utility function to check if the queue is empty or not
bool queue::isEmpty()
{
return (size() == 0);
}
// Utility function to check if the queue is full or not
bool queue::isFull()
{
return (size()-1 = capacity);
}
// main function
int main() {
// call your test functions here!
return 0;
}
IN C++ Code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started