Lab Sheet 4

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Birla Institute of Technology and Science TA C252 Computer Programming II LabSheet IV Date: 17th September 2011

----------------------------------------------------------------------------------------------------------------------------------------

Problem Statement:
Write a program to generate a phone list. This phone list maintains the details of person along with his/her phone number. A structure for phone is defined below. #define MAX 20 typedef struct { int phoneid;//unique id for each number int cellNo;//mobile no int llNo; //LandLine no char name[MAX]; char email[MAX]; //email address }phone; Create a list of phone numbers by declaring an array of phone structure. Perform the operations mentioned below by accessing the phone list (or array) with . Operator (i.e without pointer). Also perform the operations mentioned below by accessing the phone list through a pointer. Driver program is also given below. Operations: void readPhoneLst(phone phLst[],int n); void printPhoneLst(phone phLst[],int n); int searchCellNo(phone phLst[],int n,int phoneid); // returns cell no void read(phone *p,int n); void print(phone *p,int n); int searchLLNo(phone *p,int n,int phoneid); // returns Landline no

Driver Program int main() { phone phLst[20],*p; int n,ph,phid; printf("Enter Size of phoneList\n"); scanf("%d",&n); readPhoneLst(phLst,n); printPhoneLst(phLst,n); printf("Enter Phone id\n"); scanf("%d",&phid); ph = searchCellNo(phLst,n,phid); printf("Cell No for phone id %d = %d\n",ph); //Accessing phonelist through a pointer p = phLst; read(p,n); print(p,n); printf("Enter Phone id\n"); scanf("%d",&phid); ph = searchLLNo(p,n,phid); printf("Landline No for phone id %d = %d\n",ph); }

You might also like