Sample-Exam-Final

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

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

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; }

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

View Full Document
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.
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.

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

View Full Document
Trace the following program to know its output:
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 <iostream> 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 < size; i++) { cout << c[i] << “ “; } 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 < size1) && (j < size2)) { if (s[i] < t[j]) { u[k] = s[i]; i++; } else { u[k] = t[j]; j++; } k++; } if (i< size1) for (int n = i; n < size1; n++) u[k++] = s[n]; else if (j < size2) for (int n = j; n < size2; n++) u[k++] = t[n]; }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern