Académique Documents
Professionnel Documents
Culture Documents
Announcements
Last date for course drop is 20th October. p
I will sign drop requests till 17th October.
Lec-25
Recap
Structures
members functions returning structures passing structures to functions pointers to structures nested structures array of structures pointer in a structure
Lec-25
ptr = &p; modify_right (ptr, 12.0, 8.0); // Now p would have been modified printf (%lf %lf %lf %lf\n, p.x, p.y, ptr->x, ptr->y); // if (q == p) }
Lec-25
// error
Value x of point p of variable l of type struct line can be accessed as: l.p.x The . operator has left-to-right associativity
Lec-25
Lec-25
Lec-25
Modular programming
Divide your problem into smaller manageable parts Write functions to solve each small part If your code is more than what you can see in one screen, then perhaps it is better to divide this into functions
Lec-25
10
struct student { int roll; char *name; int hostel; int room; long mobile; struct date bday; struct marks esc101; struct marks phy; }
11
Lec-25
12
Lec-25
13
void sortstudents ( int n) // n records to be sorted { // Using Bubblesort will do sorting later int i, k, swap; for (k = n; k > 1; k--) { swap = 0; for (i = 0; i < k; i++) // In each iteration, shift the bigger value record to the right if stucompareless (slist[i], slist[i+1]) { swapstudents (&slist[i], &slist[i+1]); swap = 1; } if (!swap) break; } }
Lec-25 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 14
int findstudent (struct student s1, int n) { int i; for (i = 0; i < n; i++) { if (s1.roll == slist[i].roll) return i } return (-1); }
Lec-25
15
Lec-25
16
Wishing all of you a very happy Dussehra Enjoy you vacat o s joy your vacations
Lec-25 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 17