#include #include using namespace std; // class definition class Employee { public: // data members, same syntax as variable declarations string name, title; int reviews[10]; int review_ct; }; // functions work with class variables just like any other variables // note: this function works at the level of an Employee, doesn't // have to care where that Employee comes from (abstraction!) void addReview(Employee &emp, int score) { // member access operator (.) used to indicate parts of the Employee object emp.reviews[emp.review_ct] = score; emp.review_ct++; } int main() { // class is a type, used to declare variables (class variable are called objects) Employee boss; Employee dept[10]; // pay attention to variable names and types! // dept is an array of Employees // dept[7] is an Employee (subscript operator to get part of an array) // dept[7].name is a string (member access operator to get part of an object) // use it like any other string! dept[7].name = "Tim"; // setting the third review to the average of the first two, for Employee 10 // same formula as: r3 = (r1 + r2) / 2.0 // just more complex variable names dept[10].reviews[2] = (dept[10].reviews[0] + dept[10].reviews[1]) / 2.0; // better: use a function that works at the level of employee, that way we don't // need to worry out here about the internal structure of an Employee (abstraction!) addReview(dept[10], 87); system("pause"); return 0; }