Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Average of an array (struct)
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- const int CLASSIZE = 1;
- struct student
- {
- string firstName;
- string lastName;
- void printTheInfo()
- {
- cout << "Name: " << firstName << " " << lastName;
- }
- void loadMe()
- {
- cout << "First Name: ";
- cin >> firstName;
- cout << "Last Name: ";
- cin >> lastName;
- }
- };
- struct grades
- {
- int grade1;
- int grade2;
- int grade3;
- int grade4;
- int grade5;
- void printTheGrades()
- {
- cout << " Grades: " << grade1 << " " << grade2 << " " << grade3
- << " " << grade4 << " " << grade5 << endl;
- }
- void loadGrades()
- {
- cout << "Grade 1: ";
- cin >> grade1;
- cout << "Grade 2: ";
- cin >> grade2;
- cout << "Grade 3: ";
- cin >> grade3;
- cout << "Grade 4: ";
- cin >> grade4;
- cout << "Grade 5: ";
- cin >> grade5;
- }
- };
- void printAllStudents(student [], grades [], int);
- void loadAllStudents(student [], grades [], int);
- int main(int argc, char *argv[])
- {
- student theStudent[CLASSIZE];
- grades theGrade[CLASSIZE];
- loadAllStudents(theStudent, theGrade, CLASSIZE);
- printAllStudents(theStudent, theGrade, CLASSIZE);
- system("PAUSE");
- return EXIT_SUCCESS;
- }
- void loadAllStudents(student theStudents[], grades theGrades[], int s)
- {
- for(int i = 0; i < s; i++)
- {
- theStudents[i].loadMe();
- theGrades[i].loadGrades();
- }
- }
- void printAllStudents(student theStudents[], grades theGrades[], int s)
- {
- for(int i = 0; i < s; i++)
- {
- theStudents[i].printTheInfo();
- theGrades[i].printTheGrades();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment