final_exam_review(1) - CSC 2000 Final Exam Sample Questions 1 Write a function prototype and function implementation which takes as input an array of

# final_exam_review(1) - CSC 2000 Final Exam Sample Questions...

• Notes
• 6
• 100% (2) 2 out of 2 people found this document helpful

This preview shows page 1 - 3 out of 6 pages.

CSC 2000 Final Exam Sample Questions 1) Write a function prototype and function implementation which takes as input an array of type float (eg. decimal numbers) and the size of the array and returns the sum of the decimal numbers inside the array. Write a program to test your function (e.g. declare and initialize an array and call the function in your main passing the right actual parameters) a. float sum (const float a[], int n); int main() { float a[] = {1,2,3,4}; cout<<sum(a,4)<<endl; } float sum (const float a[], int n) { float sum_so_far = 0.0; int i; for (i = 0; i < n; i++) { sum_so_far += a[i]; } return sum_so_far; } b. float sum (const float a[]); int main() { float a[] = {1,2,3,4}; cout<<sum(a,4)<<endl; } float sum (const float a[]) { float sum_so_far = 0.0; int i; for (i = 0; i < 4; i++) { sum_so_far += a[i]; } return sum_so_far; } c. float sum (const float a[], int n); int main() { float a[4]; cout<<sum(a,4)<<endl; } float sum (const float a[], int n) { float sum_so_far = 0.0; int i; for (i = 0; i < n; i++) { sum_so_far += a[i]; } return sum_so_far; } d. float sum (const float a[], int n); int main() { float a[4]; a[0]=1, a[1]=2, a[2]=3, a[3]=4; cout<<sum(a,4)<<endl; } float sum (const float a[], int n) { float sum_so_far = 0.0; int i; for (i = 0; i < n; i++) { sum_so_far += a[i]; } return sum_so_far; }

Subscribe to view the full document.

2) Write a function prototype and function implementation which takes as input an integer and returns 1 if the number is even and 0 otherwise. Write a program to test your function. (e.g. call the function in your main program passing the right actual parameter) a.

### 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

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes