-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.studentGradeParallelArrays.cpp
More file actions
63 lines (48 loc) · 1.64 KB
/
Copy pathDemo.studentGradeParallelArrays.cpp
File metadata and controls
63 lines (48 loc) · 1.64 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
//**********************************************************************************
// Author: Rolando Carreon
// Date: 8 Apr 2025
// Language: C++
// Assignment: Demo
// Description: Manage grades for students and calculate an average
//**********************************************************************************
#include<iostream>
#include<iomanip>
using namespace std;
// function prototypes
double computeAverage( int[] );
// global variables
const int ARRAY_SIZE = 5;
int main()
{
// declare local variables
int studentGrades[ARRAY_SIZE];
string studentNames[ARRAY_SIZE] = {"Kevin", "Fred", "Sally",
"Cecilia", "Sam" };
// loop through the arrays to get the students' grades
for(int i = 0; i < ARRAY_SIZE; i++)
{
cout << "Enter grade for " << studentNames[i] << ": ";
cin >> studentGrades[i];
}
// set the output to two decimal places
cout << fixed << showpoint << setprecision(2);
// get and display the average
cout << "The average grade is "
<< computeAverage(studentGrades) << endl;
return 0;
}
// function definitions
// function will accept an array of integers, it will find the sum of
// the values, calculate and return the average as a double
double compueAverage(int pArray[] )
{
// declare the local variables
int mySum = 0;
double myAverage = 0.0;
// iterate throught the array and the total values
for(int i = 0; i < ARRAY_SIZE; i++)
mySum += pArray[i];
// calculate the average value
myAverage = static_cast<double>(mySum) / ARRAY_SIZE;
return myAverage;
}