User Tools


#include <iostream>

using namespace std;

//The following declares a simple structure with a few simple members.
struct Student{
        string name;
        unsigned int ID;
        float scores[3];
};

main() {
        //An instance of the structure is made just as with a normal variable.
        Student example_student;

        //The . operator is used to access the members of the structure.
        example_student.name = "Albert";
        example_student.ID = 12345678;
        example_student.scores[0] = 0.97;
        example_student.scores[1] = 1.00;
        example_student.scores[2] = 0.99;

        cout << "Name        : " << example_student.name << endl;
        cout << "ID          : " << example_student.ID << endl;
        cout.precision(3);
        cout.width(4);
        cout.setf(ios::fixed);
        cout << "Lab 1 Score : " << example_student.scores[0] << endl;
        cout << "Lab 2 Score : " << example_student.scores[1] << endl;
        cout << "Lab 3 Score : " << example_student.scores[2] << endl;
}

Top