Programming Problems: Solve no more than three. 1. A certain secret spy agency i
ID: 3827791 • Letter: P
Question
Programming Problems: Solve no more than three.
1. A certain secret spy agency is gathering information. The information is divided into several broad categories, (M)ilitary, (U)S Civilian, and (C)orporate. There are events in each category, for this exercise they are just described by the following comma delimited string: “category, Event_Id, Priority, abstract” For example:
“U,E101, 2, a diabetic native American was seen waving feathers at the white house”
Or
“M,E302, 9, POTUS has lost his ducky”
Create a data file that contains 10 such events sorts them into a vector of priority queues with the highest priority being first. Display the contents of this structure to the screen.
2. Create a binary tree structure that is populated by nodes that consist of a random integer and a frequency. The key is the integer value, the frequency is an integer that shows how many times that value has been generated. Allow the user to generate N random nodes, with N entered from the keyboard. Display the contents in a depth first manner to the screen. Then load those nodes into a pqueue based not on the value, but on the frequency. The nodes should be displayed as (value, frequency) pairs. Empty the queue and display them according to the priority criteria.
3. Create a class asteroid (or roid for short) and randomly place them in 3d space. Each has an id number, a mass, and an array of size three that contains the %mass for three important natural resources, these percentages MUST sum to less than 100, and usually are far less, the rest of the mass is considered waste. The average sum is 21% for all asteroids. You can consider each then to have a mean of 21/3 or 7% with a standard deviation of 4. No percentage can be negative. These asteroids lay in a ring of radius 50 from a center of rotation (our star). Their radius from the ring has a mean of 8 and a standard deviation of 5. They are uniformly distributed along the ring (0 to 2PI) AND from the ring. No two asteroids can exist in the same location as any other. Allow the user to enter N, the number of asteroids, generate all the values, display the data to the screen, then create a 3d gnuplot of this ring of asteroids.
4. Imagine we are far in the future, we are mining asteroids from problem 8 above, for natural resources. To achieve this we have created a suite of bots. Survey bots (SB), mining bots (MB) and transport bots (TB). Create a class asteroid (or roid for short). You are to create a list of queues of these bots. A queue for each type of bot. Each bot as a unique identifier (int). Allow the user to enter just how many of each kind is to be created. These bots function as follows: Given a list of asteroids The survey bots begin to search through random asteroids, if they find an asteroid whose sum is greater than 15, they send a message to the next available mining bot. The mining bot will travel there (instantaneously for this project) and begin operations. When a number of time steps equal to the percent sum is over, the mining bot returns to the queue to wait for its next assignment. A transport bot is dispatched to pick up the resources. This is a time stepping simulation, controlled by the user, you need only print to the screen when bots are doing something, a run time sample follows:
How many asteroids? 100
How many survey? 3
How many mining? 6
How many transport? 2
Ready:
Survey bots 1, 2, 3 dispatched
Time 1:
SB1 searching asteroid 55
SB2 searching asteroid 27
SB3 searching asteroid 60
Time 2:
SB1 searching asteroid 4
SB1 resources found, sum = 18
MB1 dispatched to asteroid 4
SB2 searching asteroid 9
SB3 searching asteroid 100
Time 3:
…..etc…
Time 18:
MB1 finished at asteroid 4
MB1 returns to queue
TB1 dispatched to asteroid 4
SB1 searching asteroid 89
….etc…
5. Cell phone data is accumulated through COP, the civilian observation program, 24-7. The government forces all cell communications to be forwarded through communication hubs in Central America so no warrant is required. (If you send me a text message, the request is forwarded through those sites so they can listen in without committing a felony.) Create a simulation that consists of 1) a list of communication nodes that are sender/receivers (These are our cell phones). Randomly choose a number of nodes and mark them with a bool AGENT as true, all others are false. THEN randomly choose source and destination nodes from that list, display that pair, and if at least one of the two nodes is AGENT=true, add that data pair to a multimap of those ids. This is the NSA listening to us. If there are 500 nodes in the initial list, Display how many data pairs must be generated until ALL nodes with the bool AGENT=true is mapped? (Who talks to them is not important, only that they are contacted). Then Display all the communications to the AGENT nodes, who they are to and who they are from. All other communications can be ignored.
6. If you do questions 8 and 9 and make it an animation showing the bot movements this will count as buy 2 get 3 answers.
(Implement in C++. Please and Thank you!)
Explanation / Answer
import java.awt.*; // Uses AWT's Layout Managers import java.awt.event.*; // Uses AWT's Event Handlers import javax.swing.*; // Uses Swing's Container/Components /** * The Sudoku game. * To solve the number puzzle, each row, each column, and each of the * nine 3×3 sub-grids shall contain all of the digits from 1 to 9 */ public class Sudoku extends JFrame { // Name-constants for the game properties public static final int GRID_SIZE = 9; // Size of the board public static final int SUBGRID_SIZE = 3; // Size of the sub-grid // Name-constants for UI control (sizes, colors and fonts) public static final int CELL_SIZE = 60; // Cell width/height in pixels public static final int CANVAS_WIDTH = CELL_SIZE * GRID_SIZE; public static final int CANVAS_HEIGHT = CELL_SIZE * GRID_SIZE; // Board width/height in pixels public static final Color OPEN_CELL_BGCOLOR = Color.YELLOW; public static final Color OPEN_CELL_TEXT_YES = new Color(0, 255, 0); // RGB public static final Color OPEN_CELL_TEXT_NO = Color.RED; public static final Color CLOSED_CELL_BGCOLOR = new Color(240, 240, 240); // RGB public static final Color CLOSED_CELL_TEXT = Color.BLACK; public static final Font FONT_NUMBERS = new Font("Monospaced", Font.BOLD, 20); // The game board composes of 9x9 JTextFields, // each containing String "1" to "9", or empty String private JTextField[][] tfCells = new JTextField[GRID_SIZE][GRID_SIZE]; // Puzzle to be solved and the mask (which can be used to control the // difficulty level). // Hardcoded here. Extra credit for automatic puzzle generation // with various difficulty levels. private int[][] puzzle = {{5, 3, 4, 6, 7, 8, 9, 1, 2}, {6, 7, 2, 1, 9, 5, 3, 4, 8}, {1, 9, 8, 3, 4, 2, 5, 6, 7}, {8, 5, 9, 7, 6, 1, 4, 2, 3}, {4, 2, 6, 8, 5, 3, 7, 9, 1}, {7, 1, 3, 9, 2, 4, 8, 5, 6}, {9, 6, 1, 5, 3, 7, 2, 8, 4}, {2, 8, 7, 4, 1, 9, 6, 3, 5}, {3, 4, 5, 2, 8, 6, 1, 7, 9}}; // For testing, open only 2 cells. private boolean[][] masks = {{false, false, false, false, false, true, false, false, false}, {false, false, false, false, false, false, false, false, true}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}}; /** * Constructor to setup the game and the UI Components */ public Sudoku() { Container cp = getContentPane(); cp.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE)); // 9x9 GridLayout // Allocate a common listener as the ActionEvent listener for all the // JTextFields // ... [TODO 3] (Later) .... // Construct 9x9 JTextFields and add to the content-pane for (int row = 0; rowRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.