#include #include using namespace std; //classess allow you to create //new data types, or "super variables" class student { public: //feel free to ingore this public string fname; string lname; int id; double ex1; double ex2; double ex3; }; //Return the average exam score //for the given student double computeAverage(student someStudent) { double avg; avg = (someStudent.ex1 + someStudent.ex2 + someStudent.ex3) / 3; return avg; } int main() { student x; //use the . operator to access //the interal variables (or attributes) //of a class object x.fname = "Robbie"; x.lname = "Schweller"; x.id = 1234; x.ex1 = 71.2; x.ex2 = 80; x.ex3 = 91.3; cout << "Student name: " << x.fname << " got a " << x.ex2 << " on exam 2." << endl; student y; y.fname = "Johan"; y.lname = "Chavarria"; y.id = 23498; y.ex1 = 80; //y.ex2 = 93; y.ex3 = 30; cout << "Student name: " << y.fname << " got a " << y.ex2 << " on exam 2." << endl; cout << "whoops, " << y.fname << " must have forgotten to take exam 2." << endl; cout << "Please enter your exam 2 score " << y.fname << endl; cin >> y.ex2; cout << "Cool, let's take another look: " << endl; cout << "Student name: " << y.fname << " got a " << y.ex2 << " on exam 2." << endl; //Can pass supervariables to functions double avgX = computeAverage(x); double avgY = computeAverage(y); cout << x.fname << " has an average of " << avgX << endl; cout << y.fname << " has an average of " << avgY << endl; //You can also make an array of classes! student studentArray[10]; //an array of 10 students! studentArray[5].fname = "Victoria"; studentArray[5].ex1 = 99.5; studentArray[3].fname = "Alenis"; studentArray[3].ex1 = 95; studentArray[9].fname = "Juan"; studentArray[9].ex1 = 0.3; for (int i = 0; i < 10; i++) { cout << studentArray[i].fname << " has score " << studentArray[i].ex1 << endl; } return 0; }