-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.StudentArrayParameters.cpp
More file actions
72 lines (49 loc) · 1.85 KB
/
Copy pathDemo.StudentArrayParameters.cpp
File metadata and controls
72 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//************************************************************************
// Author: Rolando Carreon
// Date: 10 apr 2025
// Language: C++
// Assignment: Demo
// Description: Hello World Program
//************************************************************************
#include<iostream>
using namespace std;
// function prototypes
void displayArray(string[], int);
void copyArray(string[], string[], int);
int main()
{
// declare local variables
const int ARRAY_SIZE = 5;
string studentName[ARRAY_SIZE] = {"Kevin", "Fred", "Sally",
"Cecilia", "Sam"};
string studentNameTwo[ARRAY_SIZE];
// display the original array
cout << "Let's look at the original array\n";
displayArray(studentName, ARRAY_SIZE);
// copy the array
cout << "\n\nCopying the array\n\n";
copyArray(studentName, studentNameTwo, ARRAY_SIZE);
// display the copied array
cout << "Let's look at the copied array\n";
displayArray(studentNameTwo, ARRAY_SIZE);
return 0;
}
// function definitions
// function will accept a string array and an integer as the size of the
// array. it will display the contents of the array.
void displayArray(string pArray[], int size)
{
cout << "Displaying Array\n";
// loop through the array and display each element
for (int i = 0; i < size; i++)
cout << "Index " << i << " is " << pArray[i] << endl;
}
// function to copy an array, the first parameter is the orginal string
// array. the second parameter is the array to copy to, and the third
// parameter is a int for the size of the arrays
void copyArray(string pArray[], string pCopyArray[], int size)
{
// loop through the array size, copying one element at a time
for (int i = 0; i < size; i++)
pCopyArray[i] = pArray[i] + " - copy ";
}