pizzaSystem

来源:互联网 发布:新歌2016网络红歌视频 编辑:程序博客网 时间:2024/05/22 17:03
;Structure Definition for Pizza Details

(define-struct pizzaDetails (id name price status count))

(define pizza1(make-pizzaDetails 1 "bigPizza" 16.99 #t 200))

(define pizza2(make-pizzaDetails 2 "nomalPizza" 6.99 #t 100))

(define pizza3(make-pizzaDetails 3 "extraPizza" 36.99 #f 258))

;************Defining Pizza List*****************have the default value

(define pizza-list (list pizza1 pizza2 pizza3))

;************define the temp-list------- for addPizza*******in order to append to the pizza-list*********

(define temp-list (list ""))

(set! temp-list (make-pizzaDetails 3 "tempPizza" 56.99 #f 738))

;(set! pizza-list (append pizza-list (list pizza3)))

;pizzaSystem

;;--------------------

;;------------

;;contract: pizzaSystem() -->get in the pizzaSystem

;;purpose: first welcome to get in the pizzaSystem.

;;example: (pizzaSystem )----expected O/P: input message: Pizza System-------------1.Add Pizza2.Update Pizza3.View

Pizza4.Exit;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define pizzaSystem

(lambda()

(let loop()

(newline)

(display "Pizza System/n")

(display "-------------/n")

(display "1.Add Pizza/n")

(display "2.Update Pizza/n")

(display "3.View Pizza/n")

(display "4.Exit/n")

(let ([option (getPizzaSystemOption)])

(cond

[(not(number? option)) (display "Invalid Choice entered-number!/n")(loop)]

[(inexact? option) (display "Invalid Choice entered-inexact!/n")(loop)]

[(or (> option 4) (< option 1)) (display "Invalid Choice entered-!/n")(loop)]

[(= option 1)(display "1.Add Pizza have choosed/n")(addPizza)(loop) ]

[(= option 2)(display "2.Update Pizza have choosed/n")(updatePizza)(loop) ]

[(= option 3)(display "3.View Pizza have choosed/n")(viewPizza pizza-list)(loop) ]

[(= option 4)(display "4.Exit have choosed/n")(exit) ]

)

))))

;getPizzaSystemOption

;;------------

;;contract: getPizzaSystemOption(input) -->get the input message

;;purpose: in order to return the message you inputed

;;example: (getPizzaSystemOption )----expected O/P: input message

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define getPizzaSystemOption

(lambda()

(display "Enter your PizzaSystem choice ::")

(let([option1 (read)])

option1

)))

;showStruct

;;contract: showStruct(string struct) -->show struct details

;;purpose: in order to add show the struct of the details.

;;example: (showStruct 'success (make-pizzaDetails '1 '1 '1 '1 '1))----to O/P success pizza id:1 pizza name:1 pizza price:1 pizza status:1 pizza count:1

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define showStruct

(lambda (message a)

;(display (pizzaDetails? a))

;(if (not(pizzaDetails? a))(set! a (car a)))

(display message)

(display " pizza id:")

(display (pizzaDetails-id a))

(display " pizza name:")

(display (pizzaDetails-name a))

(display " pizza price:")

(display (pizzaDetails-price a))

(display " pizza status:")

(display (pizzaDetails-status a))

(display " pizza count:")

(display (pizzaDetails-count a))

(display "/n")

))

;test case----->;(showStruct 'success (make-pizzaDetails '1 '1 '1 '1 '1))

;AddPizza

;;-------------

;;contract: addPizza() -->show added the details

;;purpose: in order to add the pizza than show the added the details.

;;example: (addPizza )----to O/P the message that you added

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define addPizza

(lambda()

(let ([pizza-id ""] [pizza-name ""] [pizza-price 0] [pizza-status #t] [pizza-count 0])

(begin

(display "input pizza id::")

(set! pizza-id (read))

(display "input pizza name::")

(set! pizza-name (read))

(display "input pizza price::")

(set! pizza-price (read))

(display "input pizza status::")

(set! pizza-status (read))

(display "input pizza count::")

(set! pizza-count (read))

(set! temp-list (make-pizzaDetails pizza-id pizza-name pizza-price pizza-status pizza-count))

(set! pizza-list (append pizza-list (list temp-list)))

(showStruct "addPizza success-->" temp-list)

))))

;selectPizzaByName

;;contract: selectPizzaByName(array string) -->struct--(changePizza (struct))to change the details

;;purpose: in order to input the pizza name then to select struct to change the details.

;;example: (selectPizzaByName List name)----to O/P the message

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define selectPizzaByName

(lambda(aList name)

(if (> (length aList) 0)

(if(equal? (changeTypeOfRead (pizzaDetails-name (car aList))) name)

(begin

(showStruct "selectPizzaByName-->" (car aList));view

(changePizza (car aList));to update

)

(selectPizzaByName (cdr aList) name)

)

)

))

;testCase;

;(selectPizzaByName pizza-list "extraPizza")

;updatePizza

;;contract: updatePizza(input) -->selectPizzaByName(list input).

;;purpose: in order to input the pizza name then to select struct by this input name ,it is before the change.

;;example: (updatePizza)

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define updatePizza

(lambda()

(let ([pizza-name ""])

(display "input update pizza name::")

(set! pizza-name (read))

;(display (symbol? pizza-name))

(set! pizza-name (changeTypeOfRead pizza-name))

;(display (string? pizza-name))

(selectPizzaByName pizza-list pizza-name)

)))

;test Case

;(updatePizza)

;CheckOutUtils

;1;changeTypeOfRead

;;;contract: changeTypeOfRead(input) -->string.

;;;purpose: in order to change the type of input to changed as String.

;;;Example: (changeTypeOfRead 1) Expected O/P:"1"

;;;Algorithms:**********

;;;Dry Run:**********

;;;Implements Program Body:

(define changeTypeOfRead

(lambda(v)

(if (number? v)

(begin

(set! v (number->string v))

v

))

(if(symbol? v)

(begin

(set! v (symbol->string v))

v

))

(if(string? v)

(begin

v

))

))

;2;checkEquals

;;;contract: checkEquals(string string) -->boolean

;;;purpose: in order to Judge the two string equal or not

;;;Example: (checkEquals "ha1" "ha") Expected O/P:#f

;;;Algorithms:**********

;;;Dry Run:**********

;;;Implements Program Body:

(define checkEquals

(lambda(v1 v2)

(if(equal? v1 v2)

#t

#f

)))

;testCase;(checkEquals "ha1" "ha")

;changePizza

;;contract: changePizza(struct)

;;purpose: in order to change the struct's member ,such as update the id,name,price,status,count. flact to struct and List

;;Example: (changePizza aStruct)------> call (showStruct "chanegPizza-->" aStruct) ----show the message you updated.

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define changePizza

(lambda(aStruct)

;(set-pizzaDetails-name! pizza3 "kkk")

;(pizzaDetails-name pizza3)

(let ([pizza-id ""] [pizza-name ""] [pizza-price 0] [pizza-status #t] [pizza-count 0] [tempFlg ""])

(begin

(display "do you wanna change pizza id if not plz input '-1' else input other:")

(set! pizza-id (read))

(set! tempFlg (changeTypeOfRead pizza-id));change the (read) type form number->string & symbol->string!

(if(not(checkEquals tempFlg "-1"));Judge the value weather equal or not

(set-pizzaDetails-id! aStruct tempFlg);to update the id of this struct

)

(display "do you wanna change pizza name if not plz input '-1' else input other:")

(set! pizza-name (read))

(set! tempFlg (changeTypeOfRead pizza-name))

(if(not(checkEquals tempFlg "-1"))

(set-pizzaDetails-name! aStruct tempFlg)

)

(display "do you wanna change pizza price if not plz input '-1' else input other:")

(set! pizza-price (read))

(set! tempFlg (changeTypeOfRead pizza-price))

(if(not(checkEquals tempFlg "-1"))

(set-pizzaDetails-price! aStruct tempFlg)

)

(display "do you wanna change pizza status if not plz input '-1' else input other:")

(set! pizza-status (read))

(set! tempFlg (changeTypeOfRead pizza-status))

(if(not(checkEquals tempFlg "-1"))

(set-pizzaDetails-status! aStruct tempFlg)

)

(display "do you wanna change pizza count if not plz input '-1' else input other:")

(set! pizza-count (read))

(set! tempFlg (changeTypeOfRead pizza-count))

(if(not(checkEquals tempFlg "-1"))

(set-pizzaDetails-count! aStruct tempFlg)

)

(showStruct "chanegPizza-->" aStruct);view

))

))

;viewPizza

;;contract: viewPizza(array)

;;purpose: called by PizzaSystem,to call showStruct method use(string,struct). in order to show every member(struct) of List.

;;Example: (viewPizza pizza-list)----->(showStruct "viewPizza " (car pizza-list))---->experted O/P:viewPizza pizza id:1

pizza name:bigPizza pizza price:16.99 pizza status:#t pizza count:200

;;Algorithms:**********

;;Dry Run:**********

;;Implements Program Body:

(define viewPizza

(lambda(aList)

(if (> (length aList) 0)

(begin

(showStruct "viewPizza " (car aList))

(viewPizza (cdr aList))

)

)))

;test case:-->;(viewPizza pizza-list)

(pizzaSystem)

原创粉丝点击