Sample-Exam-Final - It will merge the two array into a...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Solution for Homework #2 int main() { int freq[6][6] = {0}; int i, j; srand(time(NULL)); for (i = 0; i < 10000; i++) freq[rand() % 6][rand() % 6]++; cout << setw(10) << "Face 1" << setw(20) << "Face 2" << setw(30) << "Frequency" << endl; for (i = 0; i < 6; i++) for (j = 0; j < 6; j++) cout << setw(10) << i+1 << setw(20) << j+1 << setw(30) << freq[i][j] << endl; return 0; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Write a C++ function called zeroSmaller that is given two double value arguments and should initialize the smaller of them to zero. Write the main method that practices this function.
Background image of page 2
Write a C++ program that will get an input string of maximum 80 characters from the user, breaking the string into the equivalent tokens, and storing the extracted tokens into a string array. Assume that the input string has at most 10 tokens, and the maximum token length is 20 characters.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Trace the following program to know its output:
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: It will merge the two array into a sorted array. 1 2 5 6 7 9 10 11 12 13 18 19 20 21 22 24 29 30 32 35 #include &lt;iostream&gt; using namespace std; void someFunction( int , int , int , int, int, int ); int main() { const int size = 20, size1 = 10, size2 = 10; int a = {1, 5, 6, 9, 10, 12, 19, 20, 22, 29}; int b = {2, 7, 11, 13, 18, 21, 24, 30, 32, 35}; int c[size] = { 0 }; someFunction(a, b, c, size, size1, size2); for (int i = 0; i &lt; size; i++) { cout &lt;&lt; c[i] &lt;&lt; ; } return 0; } void someFunction(int s, int t, int u, int size, int size1, int size2) { int i, j, k; i = j = k = 0; while ( (i &lt; size1) &amp;&amp; (j &lt; size2)) { if (s[i] &lt; t[j]) { u[k] = s[i]; i++; } else { u[k] = t[j]; j++; } k++; } if (i&lt; size1) for (int n = i; n &lt; size1; n++) u[k++] = s[n]; else if (j &lt; size2) for (int n = j; n &lt; size2; n++) u[k++] = t[n]; }...
View Full Document

Page1 / 4

Sample-Exam-Final - It will merge the two array into a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online