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

Info iconThis 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]
Background image of page 1

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

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

This document was uploaded on 02/10/2011.

Page1 / 2

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

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

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