1 / 9

Today’s Agenda

Today’s Agenda. Programming Exercise on data driven programming. Consider a police department containing N police officers. Each police officer contains the following information in his record. 1. An unsigned int id representing the unique identification number of the police.

minh
Download Presentation

Today’s Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s Agenda Programming Exercise on data driven programming

  2. Consider a police department containing N police officers. Each police officer contains the following information in his record. 1. An unsigned int id representing the unique identification number of the police. 2. A character array of maximum 30 characters for the name. 3. An unsigned int sc for the number of cases solved 4. An unsigned int ac for the number of cases attended 5. An unsigned int age for storing the age of the police 6. An unsigned int jyr to store the joining year. • A police department is a list containing maximum of MAX_POL number of police officers where MAX_POL is 1000.

  3. readPoliceDept() • rank() • countPoliceOnRank() • countPoliceOnAge() • comparePolice() • sortPoliceDept() • printPoliceDept()

  4. Operations (1) rank() • The rank of police officer is computed as follows. • rank = (100 * solvedCases / attendedCases) • if attendedCases = 0, rank = 0;

  5. comparePolice() • compares police p1 and p2 based on rank, if rank is same then compare based on id .

  6. PoliceDef.h #define NAME_LEN 50 // Maximum length of Name #define MAX_POL 1024 // Max number of Police in one Dept typedef unsigned int ID; // Unique Police identification number typedef char NAME[NAME_LEN]; // Name of Police typedef unsigned int solvedCases; // Number of cases solved typedef unsigned int attendedCases; // Total no. of cases attended typedef unsigned int AGE; // Police officer's Age typedef unsigned int joiningYear; // Police officer's joining year typedef unsigned int noOfPolice; // number of Police officers in Dept

  7. PoliceDef.h typedef enum { GREATER = 1, EQUAL = 0, LESSER = -1 } ORDER; typedef struct { ID id; NAME name; solvedCases sc; attendedCases ac; AGE age; joiningYear jyr; } police; // The police structure typedef police policeDept[MAX_POL]; // the policeDept

  8. PoliceOps.h • Extern void readPoliceDept(policeDeptpdt, noOfPolice N); • Extern float rank(police p); • Extern int countPoliceOnRank (policeDept pdt, noOfPolice N); • Count the number of police who has rank more 75. • Extern int countPolice2(policeDept pdt, noOfPolice N); • Count the number of police who has completed 25 years of service. • Extern order comparePolice(policep1,police p2); • Extern void sortPoliceDept(policeDept pdt, noOfPolice N); • Sort police based on their ranks. • Extern void printPoliceDept(policeDept pdt, noOfPolice N);

  9. comparePolice() ORDER comparePolice (police p1, police p2) { if(rank(p1)<rank(p2)) return LESSER; else if(rank(p1) == rank(p2)) { if(p1.id < p2.id) return LESSER; else if(p1.id == p2.id) return EQUAL; else return GREATER; } else return GREATER; }

More Related