Source of datatypes_structured.cpp


  1: //datatypes_structured.cpp
  2: //C++ code examples illustrating (non-class) structured data types

  4: //Definitions of structured types
  5: typedef char LineType[81];
  6: typedef int BowlingScoreType[10];
  7: struct StudentType
  8: {
  9:     string name;
 10:     int idNumber;
 11:     double balance;
 12: };

 14: //Declarations of variables of structured types
 15: int a[10];
 16: double temperaturGrid[20][20];
 17: char name[21];
 18: LineType inputLine;
 19: BowlingScoreType myScores;

 21: const int CLASS_SIZE = 100;
 22: StudentType class[CLASS_SIZE];

 24: //Initializations of variables of structured types
 25: int a[] = {2, 4, 6, 8};
 26: int b[4] = {2, 4, 6, 8};
 27: int c[4] = {2, 4};
 28: int d[3][4] = { {1, 3, 5, 9}, {2, 4, 6, 8}, {12, 10, 8, 6} };
 29: int e[3][4] = { {1, 3}, {2, 4, 6}, {12} };

 31: StudentType bestStudent = {"John", 1234567, 23.95};