{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_25_final - 1 item.h 16:35 David Nicol item.h...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1 · item.h · 2010-11-15 16:35 · David Nicol /* item.h */ typedef struct itemTag item; struct itemTag { char name[50]; int quantity; /* number of items */ float cost; /* cost each item */ item *next; /* pointer to next item in list */ };
Image of page 4
1 · linked.cc · 2010-11-16 09:05 · David Nicol /* linked.cc */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "item.h" int GetItemAttributes( char *, int *, float *, int ); int DeleteInv(item **, item **, char *, int , float ); int AddInv(item **, item **, char *, int , float ); int main() { char cmdstr[8]; char name[51]; item *inventory_head = NULL ; item *inventory_tail = NULL ; item *ptr = NULL ; int q; float c; while (1) { printf( "enter command L (list), A (add), D (delete), C (calculate) : " ); scanf( "%s" , cmdstr); switch (cmdstr[0]) { case 'L' : case 'l' : ptr = inventory_head; if (ptr) { printf( "----------------------------------------------\n" ); while (ptr) { printf( "There are %d items of stock %s, unit cost %f\n" , ptr->quantity, ptr->name, ptr->cost); ptr = ptr->next; } printf( "----------------------------------------------\n" ); } else printf( "list is currently empty\n" ); break ; case 'A' : case 'a' : if ( GetItemAttributes(name, &q, &c, 1) > 0 ) /* add to the inventory */ AddInv(&inventory_head, &inventory_tail, name, q, c); break ; case 'D' : case 'd' : if
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}