#define NUM_TERMS 3 #define FALL 0 #define WINTER 1 #define SPRING 2 typedef int coinValue; coinValue quarter = 25; coinValue dime = 10; #define TRUE 1 #define FALSE 0 typedef int boolean;
• – – –
•
•
•
typedef struct { char name[40]; int year; double gpa; } Student; M e g a n … 2014 3.78
typedef struct { char name[40]; int year; Student student; double gpa; } Student; strcpy(student.name, "Megan"); student.year = 2014; student.gpa = 3.78;
typedef struct { char name[40]; int year; Student makeStudent ( char name[], int year, double gpa; double gpa) { } Student; Student student; strcpy(student.name, name); student.year = year; student.gpa = gpa; return student; }
typedef struct { char name[40]; int year; Student student1, student2; double gpa; … } Student; student1 = makeStudent("Bob", 2012, 2.52); student2 = makeStudent("Crystal", 2013, 3.1);
typedef struct { char name[40]; int year; double gpa; } Student; Student student = {"Bob", 2012, 2.52}; // Doesn't work: // Student student; // … // student = {"Bob", 2012, 2.52};
typedef struct { char name[40]; int year; void printStudent (Student s) { double gpa; printf("%s:\n Class of %d\n GPA: %4.2lf\n", } Student; s.name, s.year, s.gpa); }
• • • –
Recommend
More recommend