DAPPLE Example: grades
Source code:
// grades -- compute weighted average for homework grades
// written using the Data-Parallel Programming Library for Education (DAPPLE)
//
// This program demonstrates some very simple DAPPLE features. A set
// of students' grades are represented as vectors, and then the
// program computes the weighted averages.
//
// David Kotz 1995
// $Id: grades.cc,v 1.1 95/02/21 18:11:55 dfk CS15 Locker: dfk $
#include
#include
#include "dapple.h"
const int N = 5; // number of students, presumably large
int
main(int argc, char **argv)
{
// homework grades, each for N students
floatVector hw1(N), hw2(N), hw3(N);
// weighted average grade
floatVector average(N);
// relative weights of the homeworks (should add to 1)
const float w1 = 0.40, w2 = 0.25, w3 = 0.35;
cout << "Enter " << N << " HW1 grades: ";
cin >> hw1;
cout << "Enter " << N << " HW2 grades: ";
cin >> hw2;
cout << "Enter " << N << " HW3 grades: ";
cin >> hw3;
cout << endl;
cout << "HW1 (" << w1*100 << "%): " << hw1 << endl;
cout << "HW2 (" << w2*100 << "%): " << hw2 << endl;
cout << "HW3 (" << w3*100 << "%): " << hw3 << endl;
average = (hw1 * w1) + (hw2 * w2) + (hw3 * w3);
cout << "Averages: " << average << endl;
cout << "Best is " << max_value(average) << endl;
cout << "Worst is " << min_value(average) << endl;
return(0);
}
Demonstration:
grades < grades.data
Enter 5 HW1 grades: Enter 5 HW2 grades: Enter 5 HW3 grades:
HW1 (40%): 98 87 94 84 76
HW2 (25%): 90 93 80 88 83
HW3 (35%): 100 85 88 89 85
Averages: 96.7 87.8 88.4 86.75 80.9
Best is 96.7
Worst is 80.9