Program must be in C++, Set up a pair of parallel arrays of values with decimals
ID: 3678394 • Letter: P
Question
Program must be in C++,
Set up a pair of parallel arrays of values with decimals.
Implement any of the sorting algorithms from class. Specifically tell which algorithm you are implementing in your header comments.
In doing your sort, sort according to the values in one of the arrays, but be careful to move both data points in each pair while sorting. See the example below.
Print out the data in both arrays both before and after sorting. In doing so...
Put each array in a column of width 10, where values are right-aligned.
Display each value with exactly one decimal place.
Sample Starting Arrays:
Here is code to set up those arrays that you may copy and paste to save time:
Sample Arrays, Sorted by x:
Sample Arrays, Sorted by x and with Output Decimals as Directed:
x y 33.35 1 26 3.2 20.1 2.1 28.123 4.3 12 5.4Explanation / Answer
// Structure struct Array { int date; double snowDepth; void SnowData(int d, double sD) { date = d; snowDepth = sD; } }; // Main Function int main() { /* *--------------------* | VARIABLES | *--------------------* */ // Constant Variables const int NUM_ELEMENTS = 7; const int NUM_MONTHS = 12; // String, Numerical, and Boolean Variables string month; int startDate; int endDate; int a; int b; int flag = 0; double result; bool monthMatch = false; // Array Variables Array snowData[NUM_ELEMENTS]; string name[NUM_MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /* *--------------------* | USER INSTRUCTIONS | *--------------------* */ coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.