-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex37.cpp
More file actions
60 lines (48 loc) · 877 Bytes
/
Copy pathex37.cpp
File metadata and controls
60 lines (48 loc) · 877 Bytes
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
/*
CPSC 121-0X
Paul De Palma
depalma
Example 37
*/
//arrays of structs
#include <iostream>
#include <cmath>
using namespace std;
const int MAX = 10;
struct record
{
int num;
char ch;
};
/*
Pre: data is an array of structs of type struct record
Post: num and ch are filled with successive integers and characters
*/
void load(record data[]);
/*
Pre: data is an array of structs of type struct record
Post: num and ch for each element in the array are displaye
*/
void display(record data[]);
int main()
{
record data[MAX];
load(data);
display(data);
return 0;
}
void load(record data[])
{
int value = 0;
for (int i = 0; i < MAX; i++)
{
data[i].num = value;
data[i].ch = 'A' + value;
value++;
}
}
void display(record data[])
{
for (int i = 0; i < MAX; i++)
cout << data[i].num << " " << data[i].ch << endl;
}