lecture_25 - 525. p/. W 3 113.3‘ “E’ flint/(d1 Jram...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 525. p/. W 3 113.3‘ “E’ flint/(d1 Jram Prey/bus [wk/fie. ~> L/u/Zal 4’qu 39 (e 042 Joe 5741M v4”? WNW” MM ['21 W W4 , a sin/ugfirhj, Joawrrwgiju [/51ng [#31 Sjcar-ex .019 (91 U34 (97L equg ‘> oli‘vférewfl 4wfiqwr‘fla) 9M 8W4— z'az 422W [1'31 Aw; a may! 6W!) 217/16. Wflfllg [ADJ- Qeg/uemll’ayfla adj'QwI/LcL 1'14 max/nary; _7 TO /‘ :Efiw 4&4; ‘> WWI/3% JAM/8 Qtlyed Sf’ie) 0:468 \> acid-[(143 W 6W3 icy dreads Magical" cat/m3. L‘s FragKam/ai/Zl) awth 90 I"; 012/81!”th ~> fig.) 0 deZe‘zle 91,. eWJ M wrrafy we Wlfl We/ $0 regewa Wig dim» M eMJire'ie earns; W4 J—o pal/(3 £04”er weka via cred/Jed WNW/é W gal?” V‘W‘Y/I m Me flrltg/LW «Haws. ‘ z, :29. M -> [2 AWeC/ [xiii 1“; a2 (la/[2000M 0;; wJeS, where flea/(z twig fig 014? "WI/j" 0V[ dfla. "—> {\ug‘leéfld fiJ OWP‘él'Mg (I qu/guous Staggwa (94 WV?) (20205! [i'flvl €ZW¢I dee/ Mulazifmg a (WWII/7% -,Lo 0%? hey/1L Male [2; MI 4&7- WW3 m m —->~~. 4&1 5} aw swab; (Msz W (2 gegz/ym/afl/ [gage (9/ (Lad. aw Wei, We 70044 hoe/e. 2% $42.. 6ng fig MM 1436201. «2ch 1‘9 wag-gee” avg/mg 0% had. 19/25/61: 13w Nrfii'md Mela x‘m $42 [3% 2‘9 W M}. ULL. , “‘> FuudAJ/Mwhj dr”$§£flfl4w @VZW«2% Mrwsc Mal [H14 {lb/1&1. We aw cucng 52 Madam awn] 1% ; can WY‘VZS) gal W2 W (QM/egg McL/QQ Hm W “in Veal “3% WLS gag/aim Walla/1‘ égsfgecflel I a M; gm; [tgmmfl 0{ W W’ 5093/” HF pmml's MW earl (V41 Quad/:43} he Law man/a (2%,? /'§' gazed/AW jCLwL pm‘ce) A)! Ffl‘ce oVL fihé filer/n 52/ Hem melI-lm, law ply/$4M 0% W Mex-l I‘M 2'14 Z/‘zJ af/ @JWQ (ff L: t} Q>Mudh l, ['2 (“i M [LVWJMD wgvl 4?] ,9 pm», fumaizwué N) .IugeV4l- IILW . “'9 FchJ ‘9 Free [(1:84 item.h typedef struct itemTag item; struct itemTag { char name[50]; /* part's name */ int quantity; /* how many are in stock */ float cost; /* cost of a single item */ item *nextltem; /* pointer to the next item in the list */ }; /* add item to the end of th elist */ int Addltem(item *head, char *n, int q, float p); /* delete item by its name */ int Deleteltem(item *head, char *n); /* compute total cost of all items in the database */ float CalculatelnventoryCost(item *head); item.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include "item.h" /* add item to the end of th elist */ int Addltem(item *head, char *n, int q, float p) { item *current_item = head; item *new_item; /* get to the end of the list */ while (current_item->nextltem != NULL) current__item = current__item->nextltem; /* allocate memory for a new item */ new_item = (item *)malloc(sizeof(item)); if (new_item == NULL) return 0; /* copy data */ strcpy(new_item->name, n); new_item—>quantity = q; new_item->cost = p; new_item->nextltem = NULL; current__item—>nextltem = new_item; return 1; item.c /* delete item by its name */ int Deleteltem(item *head, char *n) { item *current__item = head->nextltem; item *prevltem = head; int retval = O; /* assume that no items was deleted */ /* find item whose name is n */ while (current_item != NULL) { if (strcmp(current_item->name, n) == 0) { prevltem->nextltem = current_item->nextltem; free(current__item); retval = 1; /* indicate that item was deleted */ break; } prevltem = current__item; current__item = current_item—>nextltem; return retval; } item.c /* compute total cost of all items in the database */ float CalculatelnventoryCost(item *head) { item *current_item = head; float totalcost = 0.0f; while (current_item—>nextltem != NULL) { totalcost += current_item->cost * current_item->quantity; current_item = current_item->nextltem; } return totalcost; ppm.c /* load image from file */ PPM *Loadlmage(char *fname) { FILE *f; PPM *im = NULL; int rows, cols, max__c; char buf[8]; int stat, i; f = fopen(fname, "r"); if( == NULL) { printf(”Unable to open file %s\n", fname); return NULL; } stat = fscanf(f, "%s %d %d %d", buf, &co|s, &rows, &max_c); if (stat != 4) { printf("Unab|e to read file %s\n", fname); fclose(f); I return NULL; } main.c #include <stdio.h> #include "item.h” int main() { item inventory = { "part1", 2, 2.5, NULL}; float cost; Addltem(&inventory, "part2", 10, 1.0f); Addltem(&inventory, "part3", 3, 5.1f); cost = CaIculatelnventoryCost(&inventory); printf("|nvoentory cost: %f\n", cest); Deleteltem(&inventory, "part2"); cost = CalcuIatelnventoryCost(&inventory); printf("|nvoentory cost: %f\n”, cost); return 0; $> gcc main.c item.c —0 example $> ./example ...
View Full Document

This note was uploaded on 01/24/2012 for the course ECE 190 taught by Professor Hutchinson during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 9

lecture_25 - 525. p/. W 3 113.3‘ “E’ flint/(d1 Jram...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online