I am completely stuck on this can anyone help me with a plac
I am completely stuck on this, can anyone help me with a place to start or advice? I am in a C programing course.
You are working on using the DualShock 4 as a data source for a game, but you are having trouble visualizing the readings from the DualShock 4 as a function of time. It would be nice to plot a bar graph in real time showing either the roll or pitch of the DualShock 4, but you realize that you are in a hurry and don\'t want to deal with getting the graphics code right. Suddenly, you realize that you can graph these variables as a horizontal bar chart using characters on the screen and then let the lines scroll down the screen to form a moving bar graph.
For our purposes, roll is defined as the angle the DualShock 4 is tipped left or right while holding it normally.
Pitch is the angle from level that the DualShock 4 is tipped forward or backward.
In this lab, you will use skeleton code as your starting point to design and implement a modular DualShock 4 graphing application. Download the skeleton code lab7.c. You must use the skeleton code\'s function and basic structure to implement your program. Carefully read the skeleton program before beginning. It may help you focus your strategy. Take your time and carefully write and test individual functions in lab.
Because both roll and pitch may be positive or negative, you will need a bar graph where 0 is halfway across the screen at column 40. In the sample output below, if the value is 0 (or not enough to justify printing a character) output a 0 at column 40. If the value is greater than 0, output r\'s at column 40 and to the right. The number should be proportional to the value being graphed and such that pi/2 maps to 39 characters. Similarly, the l\'s should be used when the value is less than 0.
0
rrrrrrr
rrrr
r
llllllllll
llllllllllllllll
llllllllllllllllllllllllllllll
The above output would show a graph of 0, a slight positive trend of 3 positive readings, and 3 increasingly negative readings. When run, the program should graph roll. To switch to roll, the user should press the TRIANGLE button. To switch to pitch, the user should press the X button.
Solution
public class ReverseInputNumbers { public static void main(String[] args) { int[] numbers; // An array for storing the input values. int numCt; // The number of numbers saved in the array. int num; // One of the numbers input by the user. numbers = new int[100]; // Space for 100 ints. numCt = 0; // No numbers have been saved yet. TextIO.putln(\"Enter up to 100 positive integers; enter 0 to end.\"); while (true) { // Get the numbers and put them in the array. TextIO.put(\"? \"); num = TextIO.getlnInt(); if (num <= 0) break; numbers[numCt] = num; numCt++; } TextIO.putln(\"\ Your numbers in reverse order are:\ \"); for (int i = numCt - 1; i >= 0; i--) { TextIO.putln( numbers[i] ); } } // end main(); } // end class ReverseInputNumbers // Add a new player, even if the current array is full. if (playerCt == playerList.length) { // Array is full. Make a new, bigger array, // copy the contents of the old array into it, // and set playerList to refer to the new array. int newSize = 2 * playerList.length; // Size of new array. Player[] temp = new Player[newSize]; // The new array. System.arraycopy(playerList, 0, temp, 0, playerList.length); playerList = temp; // Set playerList to refer to new array. } // At this point, we KNOW there is room in the array. playerList[playerCt] = newPlayer; // Add the new player... playerCt++; // ...and count it. public class DynamicArrayOfInt { private int[] data; // An array to hold the data. public DynamicArrayOfInt() { // Constructor. data = new int[1]; // Array will grow as necessary. } public int get(int position) { // Get the value from the specified position in the array. // Since all array positions are initially zero, when the // specified position lies outside the actual physical size // of the data array, a value of 0 is returned. if (position >= data.length) return 0; else return data[position]; } public void put(int position, int value) { // Store the value in the specified position in the array. // The data array will increase in size to include this // position, if necessary. if (position >= data.length) { // The specified position is outside the actual size of // the data array. Double the size, or if that still does // not include the specified position, set the new size // to 2*position. int newSize = 2 * data.length; if (position >= newSize) newSize = 2 * position; int[] newData = new int[newSize]; System.arraycopy(data, 0, newData, 0, data.length); data = newData; // The following line is for demonstration purposes only. System.out.println(\"Size of dynamic array increased to \" + newSize); } data[position] = value; } } // end class DynamicArrayOfInt
