COMP 348: ASSIGNMENT3
Notethatassignmentsmustbesubmittedontimeinordertoreceivedfull
value.Appropriatelatepenalties(<1hour=10%,<24hours=25%)will
beapplied,asappropriate.
DESCRIPTION: It’stimetotryalittlefunctionalprogramming.Inthiscase,
yourjobwillbetodevelopaverysimpleinformationsystemwithClojure.REALLYsimple.Infact,
allitwillreallydoisloaddatafromadiskfile.Thisdatawillthenformagradebookfile(very
similartowhatyouseeonMoodle).Thegradebook containsoneflatfilethatcontainsalistofall
studentsintheclasswiththeirgrades foreveryassignment/examcomponent.
grades.txt:<studentid,firstname,lastname,[component,weight,grade]…>
Thenumberofcomponentsmayvaryfromfiletofile,however,itwouldbethesameforallstudents
inasinglefile.
Asamplefileisgiveninthefollowing:
40543437,John,Doe,A1,10,95.5,A2,10,100,MIDTERM,20,80,FINAL,60,70
40543476,Jane,Doe,A1,10,100,A2,10,100,MIDTERM,20,90,FINAL,60,100
40545276,Michael,J,A1,10,99,A2,10,98,MIDTERM,20,97,FINAL,60,76
40544545,Yo,McLovin,A1,10,70,A2,10,70,MIDTERM,20,60,FINAL,60,60
...
Notethatno[syntax]errorcheckingisrequiredforanyofthedatafiles.Youcanassumethatthey
havebeencreatedproperly, andallfieldsarepresent.Eachfieldisseparatedbya“,”andcontainsa
non-emptystring.
Itissuggestedthatyouuseavectorforeachstudentandincludeallgradecomponentsinamap.
Theclasslististhenstoredinalist.
Seethemapify functionintheattachedcode. Usingthatfunction,youmaystorethegradesforeach
studentinamap.ForexamplethegradeforJohnDoewouldbesomethinglike:
{"A1" {:weight 10, :grade 95.5},
"A2" {:weight 10, :grade 100},
"MIDTERM" {:weight 20, :grade 80},
"FINAL" {:weight 60, :grade 70}}
Sonowyouhavetodosomethingwithyourdata.Youwillprovidethefollowingmenutoallowthe
usertoperformactionsonthedata:
*** Grade Processing Menu ***
-----------------------------
1. List Names
2. Display Student Record by Id
3. Display Student Record by Lastname
4. Display Component
5. Display Total
6. Exit
Enter an option?
Asamplecodetemplateimplementingtheabovemenustructureisprovidedwiththisassignment.
Theoptionswillworkasfollows
1. TheListnamesoptionsimplydisplaysthelistofstudentsfollowedbyalineindicatinghow
manystudentsarethereinthefile. Example:
(40543437 John Doe)
(40543476 Jane Doe)
(40545276 Michael J)
(40544545 Yo McLovin)
4 students in total.
2. DisplayStudentrecordbyId,letstheuseenterthestudentidandthendisplaysthestudent
recordasinthefollowing.Youmayformatthestudentrecordasyouwishorsimplydump
therecordasillustrated inthefollowingexample:
Enter the Student ID: 40543437
Found:
[40543437 John Doe {A1 {:weight 10, :grade 95.5} A2 {:weight 10, :grade
100} MIDTERM {:weight 20, :grade 80} FINAL {:weight 60, :grade 70}}]
Ifthestudentidisnon-existent,anerrormessagewillbedisplayed.Example:
Enter the Student ID: 9999
Invalid student ID or student ID not found.
3. DisplayStudentrecordbylastname,searchesforthelastnameanddisplays thestudent
recordsformatchedstudents.Example:
Enter the Last Name: Doe
Found:
[40543437 John Doe {A1 {:weight 10, :grade 95.5} A2 {:weight 10, :grade
100} MIDTERM {:weight 20, :grade 80} FINAL {:weight 60, :grade 70}}]
[440543476 Jane Doe {A1 {:weight 10, :grade 100} A2 {:weight 10, :grade
100} MIDTERM {:weight 20, :grade 90} FINAL {:weight 60, :grade 100}}]
Total 2 record(s) found.
4. Usingdisplaycomponentmethod,theuserentersthecomponentnameandthesystemwill
displaytheresultandtheclassaverage (roundedto1digit) forthatspecificcomponent.
Example:
Enter Component Name: A1
(40543437 95.5)
(40543476 100)
(40545276 76)
(40544545 60)
Average: 91.1
5. Thedisplaytotalmenuoptionsdisplays theindividualgradesandthecoursetotalforeach
studentfollowedbytheclassaverage,asillustratedinthefollowing example.The‘schema’
ofthedataisdisplayedontop,listedallcoursecomponentinalphabeticalorder. The
studentlistisalsosortedbystudentidinascendingorder,Example:
(STUDID A1 A2 FINAL MIDTERM TOTAL)
(40543437 95.5 100 80 70 77.6)
(40543476 100 100 90 100 98)
(40544545 70 70 60 60 62)
(40545276 99 98 97 76 84.7)
(AVG 91.1 92 81.6 76.5 80.6)
6. Finally,iftheExitoptionisenteredtheprogramwillterminatewitha“GoodBye”message.
Otherwise,themenuwillbedisplayedagain.
Sothat’sthebasicidea.Herearesomeadditionalpointstokeepinmind:
1. Youdonotwanttoloadthedataeachtimearequestismade.So,beforethemenuis
displayedthefirsttime,yourdatashouldbeloadedandstoredinappropriatedata
structures.So,assumingaloadData functioninamodulecalleddb,aninvocationlikethe
followingwouldcreateandloadadatastructurecalledgradesDB
(def gradesDB (db/loadData "grades.txt"))
ThegradesDB datastructurecanthenbepassedasinputtoanyfunctionthatneedstoact
onthedata.Notethat,onceitisloaded,thedataisneverupdated.
Youmayalternativelyuseclojure’sread-csv function.
2. Asafunctionallanguage,Clojureusesrecursion.Ifpossible,usethemap,reduce and
filter functionswheneveryoucan.(Notethatyoumaysometimeshavetowriteyour
ownrecursivefunctionswhensomethinguniqueisrequired).
3. ThisisaClojureassignment,notaJavaassignment.SoJavashouldnotbeusedforanymain
functionality.Thatsaid,itmightbenecessarytouseJavaclassestoconverttexttonumbers
inordertodothecalculations.Anexamplewiththemap functionisshownbelow:
(map #(Integer/parseInt %) ["6" "2" "3"])
4. Itisworthnoting,however,thatthiscanalsobedonewithClojure’sread-string
function.Thiscanbeusedtotranslate“numeric”strings,includingfloatingpointvalues.So
wecoulddosomethinglike:
(* 4 (read-string "4.5")) ; = 18
5. TheI/Ointhisassignmentistrivial.WhileitispossibletousecomplexI/Otechniques,itis
notnecessarytoreadthetextfiles.Instead,youshouldjustuseslurp,aClojurefunction
thatwillreadatextfileintoastring,asin:
(slurp "myFile.txt")
6. Fortheinputfromtheuser,theread-line functioncanbeused.Ifyouprintaprompt
stringtothescreen(e.g.,“pleaseentertheciry”,youmaywanttouse(flush) before
(read-line) sothatthepromptisnotcached(andthereforenotdisplayed).
7. Forstringprocessing,youwillwanttouseclojure.string.Youcanviewtheonline
docsforalistofstringfunctionsandexamples(https://clojuredocs.org/clojure.string)
8. Donotworryaboutefficiency.Therearewaystomakethisprogram(boththedata
managementandthemenu)moreefficient,butthatisnotourfocushere.Wejustwantyou
tousebasicfunctionalitytotrytogeteverythingworking.
DELIVERABLES:Yoursubmissionwillhavejust3sourcefiles.The“main”filewillbecalledapp.clj
andwillbeusedtosimplyloadtheinformationinthetextfilesintoagroupofdatastructuresand
thenpassthisdatatothefunctionthatwillprovidetheinitialfunctionalityfortheapp.Thesecond
file,menu.clj will,asthenameimplies,providetheinterfacetotheuser.Thethirdfilewillbe
calleddb.clj andwillcontainallofthedatamanagementcode(loading,organizing,etc.).Donot
includeanydatafileswithyoursubmission,asthemarkerswillprovidetheirown.
PROJECTENVIRONMENT:ItiseasytorunasingleClojurefilefromthecommandline(i.e.,clojure
myfile.clj).Itbecomesalittlemoretediouswhentheappismadeupofmultiplefiles.In
practice,largeprojectsaretypicallybuiltwithatoolcalledLeinengen.UseofLeiningen,however,is
overkill forthiskindofassignmentandwilllikelymakebuildingandtestingmoreproblematicfor
moststudents.
Wewillthereforekeepthingsassimpleaspossible.Yourfiles,bothsourcecodeanddatawillbe
locatedinthecurrentfolder.Eachofthethreesourcefileslistedabovewilldefineitsown
namespace.Forexample:
(ns app
(:require [db])
(:require [menu]))
IMPORTANT: Thiswillallowthefiles/modulestointeractwithoneanother.However,Clojure
accessesmodulesrelativetothecurrentCLASSPATH.Bydefault,theCLASSPATH willprobablynot
besetonyourmachine,soClojurewillfailtorunyourprogram,witherrorssayingthatitcannot
findyourmodules.ThesimplestthingtodoistosimplysettheCLASSPATH toincludethecurrent
folder(thisiswhatthegraderswilldo).FromtheLinuxcommandline,youcanjustsay
export CLASSPATH=./
Oncethisisdone,youcanrunyourappsimplybytyping
clojure app.clj
NotethatthisCLASSPATH variableistemporaryandwouldhavetobereseteachtimeyoustart
Linux.Ifyouwantittobeautomaticallyconfiguredeverytimeyoulogin,youcouldaddtheexport
linetothe.bashrc fileinyourloginfolder.
SUBMISSION: Onceyouarereadytosubmit,placethe.cljfilesintoazipfile.Thenameofthezipfile
willconsistof"a3"+lastname+firstname+studentID+".zip",usingtheunderscorecharacter"_"
astheseparator.Forexample,ifyournameisJohnSmithandyourIDis"123456",thenyourzipfile
wouldbecombinedintoafilecalleda3_Smith_John_123456.zip".Thefinalzipfilewillbesubmitted
throughthecoursewebsiteonMoodle.Yousimplyuploadthefileusingthelinkontheassignment
webpage.
FINALNOTE:Whileyoumaytalktootherstudentsabouttheassignment,allcodemustbewritten
individually.Anysharingofassignmentcodewilllikelyleadtoanunpleasantoutcome.
Good Luck
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。