demo-array-pass - Demonstration of passing arrays to...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Demonstration of passing arrays to methods #include <iostream.h> #include <ctype.h> // for toupper, strlen char FirstInitial(const char firstName[]) // PRE: firstName is a valid null-terminated string // POST: FCTVAL == first letter of firstName { return firstName[0]; } // What happens if we pass name as const? void MakeNameUppercase(char name[]) // PRE: name is a valid null-terminated string // POST: name is now all uppercase { for(int i = 0; i < strlen(name); i++) // go through string { // making each letter name[i] = toupper(name[i]); // uppercase } } void PrintArray(const int input[], int size) // PRE: input[0] through input[size-1] are initialized // POST: every element of input has been displayed, separated by spaces { for(int i = 0; i < size; i++) // go through all elements { cout << input[i] << " "; } cout << endl; } int SumArray(const int input[], int size) // PRE: input[0] through input[size-1] are initialized // POST: FCTVAL == sum of all entries stored in input[0..size-1] { int sum = 0; // sum of all elements so far for(int i = 0; i < size; i++) // add each element to the sum
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern