Question

== Programming Assignment == For this assignment you will write a program that controls a set...

== Programming Assignment ==

For this assignment you will write a program that controls a set of rovers and
sends them commands to navigate on the Martian surface where they take
samples. Each rover performs several missions and each mission follows the
same sequence: deploy, perform one or more moves and scans, then return to
base and report the results. While on a mission each rover needs to remember
the scan results, in the same order as they were taken, as well as remember
the way to get back to the base. The scan results should be stored in a queue
and the return instructions should be stored in a stack.

The objective of this assignment is to learn how to implement and use both a
queue and a stack. Since the objectives include learning how to implement a
stack and a queue, you cannot use a premade stack or queue (e.g. the STL stack
or queue classes).

== Program Design ==

Your program should use good design methodologies so you should have separate
classes for each of the following:

- rover -- This class represents the rover. Each rover has an ID (integer) as
well as an x, y coordinate to represent its current location relative to the
base. In addition, it needs to have the following public methods:

- void deploy(); -- this deploys a rover on a new mission
- void move(int x, int y) -- this moves a rover to the new x,y coordinates
- void corescan() -- this performs a core sample scan and stores the resuls
- void dock() -- this method returns to the base station and reports the results

Since you are not really on Mars and there aren't really rovers, your rover
class is actually just going to simulate the movements and actions by
printing messages on the screen.

The "deploy" method will print the message "Rover (<ID>) deploying..."
followed by "Rover (<ID>) ready.". The string "Rover (<ID>)" should include
the actual ID of the rover.

For example, the deploy method does this:

void rover::deploy()
{
printID();
cout << " deploying..." << endl;
printID();
cout << " ready." << endl;
}

The "move" method changes the rover's x,y coordinates, stores the new
location on the stack, and prints a message that indicates the that rover
moved. The message is "Rover (<ID>) moving to location <x>, <y>.".

The "corescan" method prints a message "Rover (<ID>) scanning." then calls the
scandata class with the rover's current x, y location, and stores the result
in the results queue.

The "dock" method prints "Rover (<ID>) returning to base." then uses the entries
from the stack to issue a sequence of moves to backtrack back to the
base. It needs to print out each move (just like the move method). Once at
the base the rover needs to print "Rover (<ID>) at base. Sending results...". Then
it needs to pull each of the results off of the queue and print them. When
all results are printed the rover needs to print "Rover (<ID>) result transmission
complete.". Finally, the "dock" method needs to print "Rover (<ID>) docked.".

Refer to the "expected.txt" file to make sure that your printed messages are
correct.

- stack -- This class should implement a stack. It is used to store the
locations as the rover moves on a mission.

- queue -- This class should implement a queue. It is used to store the scan
results.

== Other Files ==

I have provided a class called "scandata". This class contains all of the
simulated scan data that the rover will read. There is a single method
"getScandata(int x,int y)" that takes in an x, y coordinate and returns the
scan data for that location. You will need to compile the scandata.cpp file
into your application. You should NOT edit or alter the scandata.h or
scandata.cpp files.

I have also provided two test programs: teststack.cpp and testqueue.cpp. These
are for your use. You are not required to use them but they will be helpful
for developing and debugging your queue and stack classes.

Finally, for your convenience I have provided a "makefile". If you name all of
your files the same as I have then you can use the following make commands:

- make rovercontrol -- this builds the entire rovercontrol program
- make testrover -- this builds the rovercontrol program and tests it
against expected.txt
- make testqueue -- this builds the testqueue program and runs it
- make teststack -- this builds the teststack program and runs it

Using the makefile is optional. You are welcome to modify it anyway you
want. You do not need to turn in the makefile.

== External Requirements ==

- The main driver (rovercontrol.cpp) will provide a sequence of commands to a
set of rovers. Each rover needs to respond to the commands. Any number of
rovers can be active at the same time and the commands for different rovers
are interlaced.
- Rover scan results should be reported, after docking, in the same order that
they were collected. You must use a queue to store these.
- Each rover must keep track of the path it follows during its mission so it
can find its way home when the DOCK command is issued. You must use a stack
to store this.
- The output from your program must match expected.txt exactly.

== Internal Requirements ==

- The program must use the supplied rovercontrol.cpp file, unmodified, as the
main driver.
- Each rover must have its own queue and stack.
- All of the scan results must be stored in a queue in each rover.
- All of the route information must be stored in a stack in each rover.
- No memory leaks.

example of commands.txt (not entire commands.txt file)

DEPLOY
1
DEPLOY
2
DEPLOY
3
DEPLOY
4
DEPLOY
5
DEPLOY
6
DEPLOY
7
MOVE
4
4989
5060
MOVE
6
5900
5193
MOVE
5
5838
5002
MOVE
3
5014
5986
MOVE
3
5223
6371
MOVE
4
5637
5769
MOVE
5
6819
5848
MOVE

rovercontrol.cpp

#include <iostream>
#include <fstream>
#include <cstring>
#include "rover.h"

using namespace std;

int main(int argc, char** argv) {

// Set up the program constants
const int NUMBER_OF_ROVERS = 7;
const int MAX_COMMAND_LENGTH = 16;
const int MAX_RESULTS = 128;
const char* CMD_END = "END";
const char* CMD_DEPLOY = "DEPLOY";
const char* CMD_MOVE = "MOVE";
const char* CMD_CORESCAN = "CORESCAN";
const char* CMD_DOCK = "DOCK";

rover** rovers;

if (argc != 2) {
cout << "Usage: " << argv[0] << " <datafile>" << endl;
return(0);
}

// Create the rovers
rovers = new rover*[NUMBER_OF_ROVERS];
for (int i=0;i<NUMBER_OF_ROVERS;i++)
{
rovers[i] = new rover(i+1,MAX_RESULTS);
}

// Read the data
char* datafile = argv[1];
ifstream infile(datafile);
char command[MAX_COMMAND_LENGTH];
int roverID;
int commandArg1;
int commandArg2;


infile >> command;
while (strcmp(command,CMD_END) != 0) {
infile >> roverID;

if (strcmp(command,CMD_DEPLOY) == 0)
{
rovers[roverID-1]->deploy();
}
if (strcmp(command,CMD_MOVE) == 0)
{
infile >> commandArg1;
infile >> commandArg2;
rovers[roverID-1]->move(commandArg1, commandArg2);
}
if (strcmp(command,CMD_CORESCAN) == 0)
{
rovers[roverID-1]->corescan();
}
if (strcmp(command,CMD_DOCK) == 0)
{
rovers[roverID-1]->dock();
}

infile >> command;
}

// Free up memory for the allocated rovers
for (int i=0;i<NUMBER_OF_ROVERS;i++)
{
if (rovers[i] != nullptr)
{
delete rovers[i];
rovers[i] = nullptr;
}
}
delete [] rovers;
}

scandata.h

#ifndef SCANDATA_H
#define SCANDATA_H

#define NUM_SCANDATA_VALUES 1000

class scandata
{
private:
static const int m_data[];

public:
static int getScandata(int x,int y);
};

#endif

scandata.cpp

#include <iostream>
#include "scandata.h"

int const scandata::m_data[] = {
80, -56, 83, -6, 46, 78, 50, 46, -3, -5, 11, 85, -7, 45, -19, -49, 83,
-50, 21, 24, 1, 47, 20, 68, 21, -56, -31, 83, 95, -10, 43, -15, -42,
-75, -47, 18, 12, -95, 97, 39, 63, -62, -30, 84, 64, -22, 82, 21, -22,
92, -91, 40, 57, 38, 23, -29, -29, 100, 7, -68, 14, 100, -91, 99, -57,
55, 15, -21, -95, -1, 12, -57, -63, -78, 99, -67, -9, -83, -11, 67,
60, 70, -56, -91, 25, -81, -88, -86, 65, -32, -85, 88, -86, 12, 100,
-35, -1, 45, -55, -7, -95, 75, 61, 5, -4, 91, -84, -65, -71, -18, 28,
-28, 15, 5, 26, -4, -97, -89, 98, -54, 13, 100, -43, -24, -16, 72, 85,
23, 11, 94, 35, 39, -10, -90, 51, 90, -59, -64, -25, -100, -72, 11,
14, 76, 0, -64, -79, 38, 41, -6, -54, 41, 99, 60, -63, 31, 31, -92,
-43, 93, -64, -33, 45, -100, 80, 92, -7, -72, -78, -32, -93, 62, 18,
-52, 60, 98, 21, -16, 40, 74, -59, -93, 65, -26, -2, 70, -71, -95, 88,
33, 72, 55, 32, 12, 55, -37, -71, -92, 59, -31, -45, -12, 96, 30, -19,
65, -85, -81, 94, -27, 78, -58, -93, -41, -2, 29, 83, 57, 47, -65,
-38, -80, -6, 44, 65, -65, -94, -37, -28, -3, -61, -70, 77, 49, -82,
-98, -71, 47, -43, -97, 76, 34, -47, -31, -40, 49, -84, -87, -1, -34,
57, -20, -5, 53, -62, -74, 22, -46, 12, -24, -15, 32, 89, 5, 73, 30,
-79, 52, 80, 36, -35, -49, -13, 93, 59, 69, -34, -90, -88, -51, -32,
8, 29, -81, -12, 90, -36, 17, -89, -3, 82, 91, -89, 25, -87, 1, 81,
-32, 19, -63, -85, -78, 34, 42, 23, 9, 5, 14, 71, 56, 32, 62, -91, 84,
-68, -55, -74, 99, 88, -9, -40, -74, 38, 10, -80, 70, -13, 13, 44,
-53, -64, 65, -72, -60, -22, -12, 7, -73, -20, 72, -22, 72, -15, 56,
-54, 4, -66, 50, 89, -71, 89, -50, -85, 69, -93, 99, 71, 84, -71, 94,
-92, 8, -96, -75, -36, 65, 24, -45, -70, 67, -34, -75, 25, 0, 19, -2,
-32, 66, 96, 75, -12, 71, -43, -46, 69, -93, 37, -72, -28, 28, -96,
-39, -78, -19, 65, -25, -46, -38, 78, 12, -94, -28, -96, 32, -59, 37,
62, -57, 100, -32, 73, -91, 9, 2, -51, 71, 60, -42, -48, 98, 13, -37,
56, 15, -66, 90, -62, 31, 65, -27, -18, 94, -50, 52, -56, -33, 87,
-47, -21, -6, -75, 18, 91, -46, -66, -51, -70, -20, 41, -89, 48, -8,
-13, 40, -8, -25, -65, -14, -38, -36, -11, 67, -56, 27, -17, -2, -43,
-37, 100, 42, 10, 35, 49, -7, 45, 12, -51, 41, 73, 40, -82, 73, 25,
-23, -46, 98, -4, 31, -82, 0, -9, 73, -9, 67, -91, -29, 86, -49, -86,
100, 19, -19, 73, -46, -85, -42, 33, 27, -61, 71, -8, -26, -97, 73,
91, -47, 49, -61, -2, -39, 74, 89, -73, 79, 75, -64, 8, 56, 51, -86,
-29, -66, -95, -88, -18, -51, -17, -15, 29, 9, 75, -53, 97, -49, -2,
-56, -65, 80, 95, -20, -14, 25, -35, -26, -49, 30, 0, -27, -62, -42,
-66, -15, -94, -83, -6, 20, -20, -16, 46, -43, 50, 17, 74, -92, -50,
85, -28, -31, 57, -68, 64, -77, -79, -83, -85, 2, -20, -36, 59, -19,

12, 33, -92, -99, 37, 85, -68, 19, -14, 61, 69, 13, 81, -69, 9, 33,

100, -13, 27, 71, -3, 98, -20, -67, -41, -39, -70, -82, 21, -18, -8,
90, 51, 25, 14, -7, 99, -19, -99, 20, 8, -64, -43, 33, 31, 87, 57, 91,
-90, 69, 29, 38, 28, -29, -87, 39, 4, 11, 56, -2, -34, -4, -49, -74,
22, 43, -35, 17, -65, 64, -45, 13, 81, -74, -41, -91, 63, -25, 44, 90,
-96, 95, 32, 16, 56, 22, -13, -59, -6, -26, -77, -84, -100, 52, 89,
-93, 8, 16, -47, -54, 99, -13, -25, 40, -1, 95, -22, -19, -80, -43,
-17, 99, -3, 39, -52, 88, -73, -30, 89, 31, -56, -73, 75, 37, -33, 17,
12, 76, -27, 94, -61, -52, 80, 72, -21, 42, 2, 12, 38, -96, -27, 86,
-18, -35, -80, 4, 15, -51, -3, 1, 85, 21, 73, 33, 9, 84, 0, -67, -32,
-84, -74, -43, 80, 81, 99, 93, -18, -29, -70, 89, -39, 36, 95, 99,
-91, -89, 97, -100, 39, 8, 59, -31, 5, 35, -10, -77, -97, 44, 21, 34,
2, -25, -65, 75, -100, 81, 13, 38, -76, 34, 57, 9, -69, 45, 73, -60,
34, 73, -74, -59, -80, 54, -40, -19, 9, 5, 6, 83, 88, -27, -48, 21,
23, -21, -97, -10, -41, 9, 72, -67, 2, -65, -70, 70, 81, 85, -98, 57,
-79, -2, -34, 75, -5, 45, 55, -84, 96, 94, 49, -3, 67, 8, 57, -45,
-12, 88, -75, 91, -65, 57, -69, 36, 62, 72, 34, 78, 54, -66, -60, 69,
-71, 20, -45, 16, 29, 47, 54, 9, 89, -88, 77, -62, -2, -20, 83, -30,
8, 84, -75, 73, -25, 37, -62, -18, -58, 7, -42, 41, 52, -31, -50, -2,
55, -54, -80, -88, -34, 28, 48, 0, -66, -33, 75, -21, 64, -95, 59, 43,
76, 57, 70, 93, -78, 57, 61, -15, -37, 20, 93, 17, -66, 74, -74, -52,
25, 34, -44, 87, -59, -96, 94, -48, 1, 70, -17, -18, 65, 29, -60, 54,
91, 31, -28, -24, 33, -26, 60, 17, -12, 0, 52, -75, 77, 58, -12, -25,
69, -90, 72, -85, 41, -45, -43, 62, -92, 89, 59, -59, 25, -90, -57,
-85, 22, -57, -73, -66, -10, 22, 45, 96, -79, -50, -21, -16, -17, -40,
-12, 86, -61, 100, 21, -3, 33, -95, -50, -5, -88, -11, 56, 30};

int scandata::getScandata(int x,int y)
{
int ret = 0;

int index = (x * y);
index *= (index < 0) ? -1 : 1; // Make it positive
index = index % NUM_SCANDATA_VALUES;
ret = m_data[index];

return ret;
}

testqueue.cpp

#include <iostream>
#include "queue.h"

using namespace std;

void dumpQueue(queue &q)
{
cout << "Dumping the queue" << endl;
while (!q.isEmpty())
{
int result = q.dequeue();
cout << "Value: " << result << endl;
}
}

int main()
{
queue q(5);

q.enqueue(1);
dumpQueue(q);

q.enqueue(1);
q.enqueue(2);
// q.printInternals();
dumpQueue(q);

q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
q.enqueue(4);
q.enqueue(5);
q.enqueue(6);
// q.printInternals();
dumpQueue(q);

}

teststack.cpp

#include <iostream>
#include "stack.h"

using namespace std;

void dumpStack(stack &s)
{
cout << "Dumping the stack" << endl;
while (!s.isEmpty())
{
const stack_entry* result = s.pop();
cout << "Value: " << result->x << ", " << result->y << endl;
}
}

void pushHelper(stack &s,int x, int y)
{
stack_entry entry;

entry.x = x;
entry.y = y;
s.push(entry);
}

int main()
{
stack s(5);
stack_entry entry;

pushHelper(s,1,1);
dumpStack(s);

pushHelper(s,1,1);
pushHelper(s,2,2);
dumpStack(s);

}

example of expected.txt (not entire expected.txt file)

Rover (ID 1) deploying...
Rover (ID 1) ready.
Rover (ID 2) deploying...
Rover (ID 2) ready.
Rover (ID 3) deploying...
Rover (ID 3) ready.
Rover (ID 4) deploying...
Rover (ID 4) ready.
Rover (ID 5) deploying...
Rover (ID 5) ready.
Rover (ID 6) deploying...
Rover (ID 6) ready.
Rover (ID 7) deploying...
Rover (ID 7) ready.
Rover (ID 4) moving to location 4989, 5060.
Rover (ID 6) moving to location 5900, 5193.
Rover (ID 5) moving to location 5838, 5002.
Rover (ID 3) moving to location 5014, 5986.
Rover (ID 3) moving to location 5223, 6371.
Rover (ID 4) moving to location 5637, 5769.
Rover (ID 5) moving to location 6819, 5848.
Rover (ID 3) moving to location 5993, 6543.
Rover (ID 2) moving to location 5499, 4379.
Rover (ID 3) moving to location 6246, 6605.
Rover (ID 6) moving to location 6304, 5619.
Rover (ID 4) moving to location 5936, 6095.
Rover (ID 6) moving to location 6509, 6136.
Rover (ID 3) moving to location 6915, 7136.
Rover (ID 4) moving to location 5204, 6187.
Rover (ID 7) moving to location 5474, 5092.
Rover (ID 5) moving to location 7633, 5921.
Rover (ID 2) moving to location 4852, 5223.
Rover (ID 1) moving to location 5505, 5695.
Rover (ID 5) moving to location 8437, 6221.
Rover (ID 5) moving to location 9119, 6925.
Rover (ID 7) moving to location 6446, 5096.
Rover (ID 1) moving to location 5960, 5904.
Rover (ID 2) moving to location 5497, 4992.
Rover (ID 4) moving to location 6025, 5224.
Rover (ID 3) moving to location 7649, 7925.
Rover (ID 5) moving to location 9475, 7528.
Rover (ID 7) moving to location 7270, 5698.

:

:

:

Rover (ID 3) moving to location 8627, 8879.
Rover (ID 3) moving to location 8603, 8868.
Rover (ID 3) moving to location 8596, 8853.
Rover (ID 3) moving to location 8582, 8840.
Rover (ID 3) moving to location 8576, 8848.
Rover (ID 3) moving to location 8571, 8831.
Rover (ID 3) moving to location 8566, 8812.
Rover (ID 3) moving to location 8579, 8822.
Rover (ID 3) moving to location 7649, 7925.
Rover (ID 3) moving to location 6915, 7136.
Rover (ID 3) moving to location 6246, 6605.
Rover (ID 3) moving to location 5993, 6543.
Rover (ID 3) moving to location 5223, 6371.
Rover (ID 3) moving to location 5014, 5986.
Rover (ID 3) moving to location 0, 0.
Rover (ID 3) at base. Sending results...
Rover (ID 3) result: -92
Rover (ID 3) result: -19
Rover (ID 3) result: 41
Rover (ID 3) result: -28
Rover (ID 3) result: -14
Rover (ID 3) result transmission complete.
Rover (ID 3) docked.
Rover (ID 6) moving to location 9994, 9697.
Rover (ID 2) moving to location 6610, 6580.
Rover (ID 1) moving to location 5013, 5438.
Rover (ID 2) moving to location 6632, 6584.
Rover (ID 6) scanning.
Rover (ID 5) scanning.
Rover (ID 1) moving to location 5011, 5438.
Rover (ID 2) scanning.
Rover (ID 4) moving to location 5680, 4905.
Rover (ID 7) scanning.
Rover (ID 5) moving to location 1196, 9863.
Rover (ID 6) moving to location 9988, 9705.
Rover (ID 4) moving to location 5663, 4924.
Rover (ID 1) scanning.
Rover (ID 6) moving to location 9994, 9689.
Rover (ID 7) moving to location 7928, 6383.
Rover (ID 4) moving to location 5664, 4925.

CODE SHOULD BE IN C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

rovercontrol.cpp
------------------------------
#include <iostream>
#include <fstream>
#include <cstring>
#include "rover.h"

using namespace std;

int main(int argc, char** argv) {

    // Set up the program constants
    const int NUMBER_OF_ROVERS = 7;
    const int MAX_COMMAND_LENGTH = 16;
    const int MAX_RESULTS = 128;
    const char* CMD_END = "END";
    const char* CMD_DEPLOY = "DEPLOY";
    const char* CMD_MOVE = "MOVE";
    const char* CMD_CORESCAN = "CORESCAN";
    const char* CMD_DOCK = "DOCK";

    rover** rovers;

    if (argc != 2) {
   cout << "Usage: " << argv[0] << " <datafile>" << endl;
   return(0);
    }

    // Create the rovers
    rovers = new rover*[NUMBER_OF_ROVERS];
    for (int i=0;i<NUMBER_OF_ROVERS;i++)
    {
   rovers[i] = new rover(i+1,MAX_RESULTS);
    }

    // Read the data
    char* datafile = argv[1];
    ifstream infile(datafile);
    char command[MAX_COMMAND_LENGTH];
    int roverID;
    int commandArg1;
    int commandArg2;

    infile >> command;
    while (strcmp(command,CMD_END) != 0) {
   infile >> roverID;

   if (strcmp(command,CMD_DEPLOY) == 0)
   {
        rovers[roverID-1]->deploy();
   }
   if (strcmp(command,CMD_MOVE) == 0)
   {
        infile >> commandArg1;
        infile >> commandArg2;
        rovers[roverID-1]->move(commandArg1, commandArg2);
   }
   if (strcmp(command,CMD_CORESCAN) == 0)
   {
        rovers[roverID-1]->corescan();
   }
   if (strcmp(command,CMD_DOCK) == 0)
   {
        rovers[roverID-1]->dock();
   }

   infile >> command;
    }

    // Free up memory for the allocated rovers
    for (int i=0;i<NUMBER_OF_ROVERS;i++)
    {
   if (rovers[i] != nullptr)
   {
        delete rovers[i];
        rovers[i] = nullptr;
   }
    }
    delete [] rovers;
}
------------------------------------------------------
rover.cpp
------------------------------
#include <iostream>
#include "rover.h"

using namespace std;

rover::rover()
{
   _id = 0;
   _x = 0;
   _y = 0;
}

~rover::rover(){}

void rover::deploy()
{
   printID();
   cout << " deploying..." << endl;
   printID();
   cout << " ready." << endl;
}

void rover::move()
{
   // change the x,y coordinates
   _x = x;
   _y = y;
   // stores the new location on the stack
   r_stack.push(_x, _y);

   // prints a message that indicates that the rover moved
   printID();
   cout << "moving to location " << x << ", " << y << ".\n";
}

void rover::corescan()
{
// then calls the scadata class with the rover's current x, y location
   //scandata _scanData;
   //r_queue.enqueue(_scanData.getScandata(_x, _y));

// prints a message
   //printID();
   //cout << " scanning.\n";
}

void rover::dock()
{
   printID();
   cout << " returning to base.\n";
  
   // uses entries from stack to issue a sequence of moves to backtrack back to the base.

   // it needs to print out each move
   //call ? move()

   //once at base print out
   //printID();
   //cout << " at base. Sending results...\n";
}

void rover::printID()
{
   << "Rover (" << _id << ")";
}
------------------------------------------------------
rover.h
------------------------------
#ifndef ROVER_H
#define ROVER_H

#include "stack.h"
class rover
{
private:
   int _id;
   int _x;
   int _y;
   //queue r_queue;
   stack r_stack;
public:
   rover();
   rover(int id, int results);
   void deploy();
   void move(int x, int y);
   void corescan();
   void dock(); // returns to the base and prints results
   void printID();
};

#endif
------------------------------------------------------
queue.h
------------------------------
#ifndef QUEUE_H
#define QUEUE_H
#include <list>

class queue {
    public:
        queue();
        bool isEmpty() const;
        bool enqueue(const int& newItem);
        const int dequeue();
    private:
        std::list<int> items;
};

#endif
------------------------------------------------------
queue.cpp
------------------------------
#include "queue.h"

queue::queue() {}

bool queue::isEmpty() const
{
    return items.empty();
}

bool queue::enqueue(const int& newItem)
{
    items.push_back(newItem);
    return true;
}

const int queue::dequeue()
{
    int item = items.front();
    items.pop_front();
    return item;
}
------------------------------------------------------
scandata.h
------------------------------
#ifndef SCANDATA_H
#define SCANDATA_H

#define NUM_SCANDATA_VALUES 1000

class scandata
{
private:
    static const int m_data[];

public:
    static int getScandata(int x,int y);
};


#endif
------------------------------------------------------
stack.cpp
------------------------------
#include <iostream>
#include "stack.h"

using namespace std;

stack::stack()
{
   head = NULL;
}

stack::~stack()
{
  
}

bool stack::push(int x, int y)
{
   // instantiate and assign coordinates
   location* newLoc = new location;
   newLoc->_x = x;
   newLoc->_y = y;

        // create new node that holds location
        node* newNode = new node;
        newNode->xy = newLoc;
        if(!isEmpty())
        {
                newNode->next = NULL;
                head = newNode;
        }
        else
        {
                newNode->next = head;
                head = newNode;
        }

}
bool stack::pop()
{
        node* popNode;
        if(isEmpty())
                return false;
        else
        {
                head = popNode->next;
                delete popNode->xy;
                delete popNode;
       return true;
        }
}


bool stack::isEmpty(void)const
{
        if(head == NULL)
                return true;
        else
                return false;
}

bool stack::peek()
{
        if(isEmpty())
        {
                cout << "queue is Empty\n";
                return;
        }
        else
        {
                node* peekNode;
                peekNode = head;
                cout << peekNode->xy->_x << ", " << peekNode->xy->_y << endl;
        }
}
------------------------------------------------------
stack.h
------------------------------
#ifndef STACK_H
#define STACK_H

#include "location.h"

class stack
{
private:
   struct node
   {
       location loc;
       node* next;
   };
   node* head;
public:
   stack();
   ~stack();
   bool isEmpty();
   bool push(x, y); // adds to top of stack
   bool pop(); //removes top of sack
   bool peek(); // returns the top
}

#endif
------------------------------------------------------
scandata.cpp
------------------------------
#include <iostream>
#include "scandata.h"

int const scandata::m_data[] = {
    80, -56, 83, -6, 46, 78, 50, 46, -3, -5, 11, 85, -7, 45, -19, -49, 83,
    -50, 21, 24, 1, 47, 20, 68, 21, -56, -31, 83, 95, -10, 43, -15, -42,
    -75, -47, 18, 12, -95, 97, 39, 63, -62, -30, 84, 64, -22, 82, 21, -22,
    92, -91, 40, 57, 38, 23, -29, -29, 100, 7, -68, 14, 100, -91, 99, -57,
    55, 15, -21, -95, -1, 12, -57, -63, -78, 99, -67, -9, -83, -11, 67,
    60, 70, -56, -91, 25, -81, -88, -86, 65, -32, -85, 88, -86, 12, 100,
    -35, -1, 45, -55, -7, -95, 75, 61, 5, -4, 91, -84, -65, -71, -18, 28,
    -28, 15, 5, 26, -4, -97, -89, 98, -54, 13, 100, -43, -24, -16, 72, 85,
    23, 11, 94, 35, 39, -10, -90, 51, 90, -59, -64, -25, -100, -72, 11,
    14, 76, 0, -64, -79, 38, 41, -6, -54, 41, 99, 60, -63, 31, 31, -92,
    -43, 93, -64, -33, 45, -100, 80, 92, -7, -72, -78, -32, -93, 62, 18,
    -52, 60, 98, 21, -16, 40, 74, -59, -93, 65, -26, -2, 70, -71, -95, 88,
    33, 72, 55, 32, 12, 55, -37, -71, -92, 59, -31, -45, -12, 96, 30, -19,
    65, -85, -81, 94, -27, 78, -58, -93, -41, -2, 29, 83, 57, 47, -65,
    -38, -80, -6, 44, 65, -65, -94, -37, -28, -3, -61, -70, 77, 49, -82,
    -98, -71, 47, -43, -97, 76, 34, -47, -31, -40, 49, -84, -87, -1, -34,
    57, -20, -5, 53, -62, -74, 22, -46, 12, -24, -15, 32, 89, 5, 73, 30,
    -79, 52, 80, 36, -35, -49, -13, 93, 59, 69, -34, -90, -88, -51, -32,
    8, 29, -81, -12, 90, -36, 17, -89, -3, 82, 91, -89, 25, -87, 1, 81,
    -32, 19, -63, -85, -78, 34, 42, 23, 9, 5, 14, 71, 56, 32, 62, -91, 84,
    -68, -55, -74, 99, 88, -9, -40, -74, 38, 10, -80, 70, -13, 13, 44,
    -53, -64, 65, -72, -60, -22, -12, 7, -73, -20, 72, -22, 72, -15, 56,
    -54, 4, -66, 50, 89, -71, 89, -50, -85, 69, -93, 99, 71, 84, -71, 94,
    -92, 8, -96, -75, -36, 65, 24, -45, -70, 67, -34, -75, 25, 0, 19, -2,
    -32, 66, 96, 75, -12, 71, -43, -46, 69, -93, 37, -72, -28, 28, -96,
    -39, -78, -19, 65, -25, -46, -38, 78, 12, -94, -28, -96, 32, -59, 37,
    62, -57, 100, -32, 73, -91, 9, 2, -51, 71, 60, -42, -48, 98, 13, -37,
    56, 15, -66, 90, -62, 31, 65, -27, -18, 94, -50, 52, -56, -33, 87,
    -47, -21, -6, -75, 18, 91, -46, -66, -51, -70, -20, 41, -89, 48, -8,
    -13, 40, -8, -25, -65, -14, -38, -36, -11, 67, -56, 27, -17, -2, -43,
    -37, 100, 42, 10, 35, 49, -7, 45, 12, -51, 41, 73, 40, -82, 73, 25,
    -23, -46, 98, -4, 31, -82, 0, -9, 73, -9, 67, -91, -29, 86, -49, -86,
    100, 19, -19, 73, -46, -85, -42, 33, 27, -61, 71, -8, -26, -97, 73,
    91, -47, 49, -61, -2, -39, 74, 89, -73, 79, 75, -64, 8, 56, 51, -86,
    -29, -66, -95, -88, -18, -51, -17, -15, 29, 9, 75, -53, 97, -49, -2,
    -56, -65, 80, 95, -20, -14, 25, -35, -26, -49, 30, 0, -27, -62, -42,
    -66, -15, -94, -83, -6, 20, -20, -16, 46, -43, 50, 17, 74, -92, -50,
    85, -28, -31, 57, -68, 64, -77, -79, -83, -85, 2, -20, -36, 59, -19,
    12, 33, -92, -99, 37, 85, -68, 19, -14, 61, 69, 13, 81, -69, 9, 33,
    100, -13, 27, 71, -3, 98, -20, -67, -41, -39, -70, -82, 21, -18, -8,
    90, 51, 25, 14, -7, 99, -19, -99, 20, 8, -64, -43, 33, 31, 87, 57, 91,
    -90, 69, 29, 38, 28, -29, -87, 39, 4, 11, 56, -2, -34, -4, -49, -74,
    22, 43, -35, 17, -65, 64, -45, 13, 81, -74, -41, -91, 63, -25, 44, 90,
    -96, 95, 32, 16, 56, 22, -13, -59, -6, -26, -77, -84, -100, 52, 89,
    -93, 8, 16, -47, -54, 99, -13, -25, 40, -1, 95, -22, -19, -80, -43,
    -17, 99, -3, 39, -52, 88, -73, -30, 89, 31, -56, -73, 75, 37, -33, 17,
    12, 76, -27, 94, -61, -52, 80, 72, -21, 42, 2, 12, 38, -96, -27, 86,
    -18, -35, -80, 4, 15, -51, -3, 1, 85, 21, 73, 33, 9, 84, 0, -67, -32,
    -84, -74, -43, 80, 81, 99, 93, -18, -29, -70, 89, -39, 36, 95, 99,
    -91, -89, 97, -100, 39, 8, 59, -31, 5, 35, -10, -77, -97, 44, 21, 34,
    2, -25, -65, 75, -100, 81, 13, 38, -76, 34, 57, 9, -69, 45, 73, -60,
    34, 73, -74, -59, -80, 54, -40, -19, 9, 5, 6, 83, 88, -27, -48, 21,
    23, -21, -97, -10, -41, 9, 72, -67, 2, -65, -70, 70, 81, 85, -98, 57,
    -79, -2, -34, 75, -5, 45, 55, -84, 96, 94, 49, -3, 67, 8, 57, -45,
    -12, 88, -75, 91, -65, 57, -69, 36, 62, 72, 34, 78, 54, -66, -60, 69,
    -71, 20, -45, 16, 29, 47, 54, 9, 89, -88, 77, -62, -2, -20, 83, -30,
    8, 84, -75, 73, -25, 37, -62, -18, -58, 7, -42, 41, 52, -31, -50, -2,
    55, -54, -80, -88, -34, 28, 48, 0, -66, -33, 75, -21, 64, -95, 59, 43,
    76, 57, 70, 93, -78, 57, 61, -15, -37, 20, 93, 17, -66, 74, -74, -52,
    25, 34, -44, 87, -59, -96, 94, -48, 1, 70, -17, -18, 65, 29, -60, 54,
    91, 31, -28, -24, 33, -26, 60, 17, -12, 0, 52, -75, 77, 58, -12, -25,
    69, -90, 72, -85, 41, -45, -43, 62, -92, 89, 59, -59, 25, -90, -57,
    -85, 22, -57, -73, -66, -10, 22, 45, 96, -79, -50, -21, -16, -17, -40,
    -12, 86, -61, 100, 21, -3, 33, -95, -50, -5, -88, -11, 56, 30};

int scandata::getScandata(int x,int y)
{
    int ret = 0;

    int index = (x * y);
    index *= (index < 0) ? -1 : 1; // Make it positive
    index = index % NUM_SCANDATA_VALUES;
    ret = m_data[index];

    return ret;
}

------------------------------------------------------
testqueue.cpp
---------------------------
#include <iostream>
#include "queue.h"

void dumpQueue(queue &q)
{
    std::cout << "Dumping the queue" << std::endl;
    while (!q.isEmpty())
    {
   int result = q.dequeue();
   std::cout << "Value: " << result << std::endl;
    }
}

int main()
{
    queue* q = new queue();

    q->enqueue(1);
    dumpQueue(*q);

    q->enqueue(1);
    q->enqueue(2);
//    q.printInternals();
    dumpQueue(*q);

    q->enqueue(1);
    q->enqueue(2);
    q->enqueue(3);
    q->enqueue(4);
    q->enqueue(5);
    q->enqueue(6);
//    q.printInternals();
    dumpQueue(*q);

    delete q;
}
-----------------------------------------------
teststack.cpp
-----------------
#include <iostream>
#include "stack.h"

struct point {
    int x;
    int y;
};

void dumpStack(stack<point> &s)
{
    std::cout << "Dumping the stack" << std::endl;
    while (!s.isEmpty())
    {
        const point result = s.pop();
        std::cout << "Value: " << result.x << ", " << result.y << std::endl;
    }
}

void pushHelper(stack<point> &s, int x, int y)
{
    point a;
    a.x = x;
    a.y = y;
    s.push(a);
}

int main()
{
    stack<point>* s = new stack<point>();

    pushHelper(*s,1,1);
    dumpStack(*s);

    pushHelper(*s,1,1);
    pushHelper(*s,2,2);
    pushHelper(*s,3,3);
    pushHelper(*s,4,4);
    dumpStack(*s);

    delete s;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
== Programming Assignment == For this assignment you will write a program that controls a set...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

  • 1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand....

    1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...

  • Use the accompanying data set on the pulse rates​ (in beats per​ minute) of males to...

    Use the accompanying data set on the pulse rates​ (in beats per​ minute) of males to complete parts​ (a) and​ (b) below. LOADING... Click the icon to view the pulse rates of males. a. Find the mean and standard​ deviation, and verify that the pulse rates have a distribution that is roughly normal. The mean of the pulse rates is 71.871.8 beats per minute. ​(Round to one decimal place as​ needed.) The standard deviation of the pulse rates is 12.212.2...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • An article of the American Journal of Clinical Pathology, by Metz et al. (A-4) published the...

    An article of the American Journal of Clinical Pathology, by Metz et al. (A-4) published the comparison of three methods to determine the percentage of dysmorphic erythrocytes in the urine. They obtained the following results when using the A (X) and B (Y) methods in 75 urine samples. Draw a scatter diagram and obtain the regression equation and graph it on the diagram. X            Y            X            Y            X            Y            X            Y 0            0            20          16          65          55          89          81 0           ...

  • Find the indicated measure. The test scores of 40 students are listed below. Find P85.

    Find the indicated measure. The test scores of 40 students are listed below. Find P85. 30 35 43 44 47 48 54 55 56 57 59 62 63 65 66 68 69 69 71 72 72 73 74 76 77 77 78 79 80 81 81 82 83 85 89 92 93 94 97 98  1) 85  2) 87 3) 89 4) 34

  • Find the indicated measure. The test scores of 40 students are listed below. Find P85. 30...

    Find the indicated measure. The test scores of 40 students are listed below. Find P85. 30 35 43 44 47 48 54 55 56 57 59 62 63 65 66 68 69 69 71 72 72 73 74 76 77 77 78 79 80 81 81 82 83 85 89 92 93 94 97 98 1) 85 2) 87 3) 89 4) 34

  • Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding...

    Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding each answer to the nearest whole number. Using the frequency distribution below (scores on a statistics exam taken by 80 students), determine:ion 1 of the preliminary test (scores on a statistics exam taken by 80 students), determine: 68 84 75 82 68 90 62 88 76 93 73 79 88 73 60 93 71 59 85 75 61 65 75 87 74 62 95...

  • Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding...

    Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding each answer to the nearest whole number. Using the frequency distribution below (scores on a statistics exam taken by 80 students), determine:ion 1 of the preliminary test (scores on a statistics exam taken by 80 students), determine: 68 84 75 82 68 90 62 88 76 93 73 79 88 73 60 93 71 59 85 75 61 65 75 87 74 62 95...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT