;HW3: Interactive Database choice=0 f='' s='' x=0. first=strarr(100) last=strarr(100) points=fltarr(100) year=intarr(100) syr=['Fr.','So.','Jr.','Sr.'] n=0 while choice ne 10 do begin print,"***Interactive Database***" print,'1. Load a file' print,'2. Save to a file' print,'3. Create new database' print,'4. Add a record' print,'5. Delete a record' print,'6. Modify a record' print,'7. Display Records' print,'8. Sort Records' print,'9. Search for a Record' print,'10. Quit' read,'Enter a choice: ',choice print,'' CASE choice OF 1: begin read,'Enter filename: ',f openr,1,f n=0 while NOT EOF(1) do begin readf,1,x,y,s points[n]=x year[n]=y s=strcompress(s,/remove_all) last[n]=strmid(s,0,strpos(s,',')) first[n]=strmid(s,strpos(s,',')+1,strlen(s)) n=n+1 endwhile close,1 print,'Loaded '+strcompress(n)+' records.' end 2: begin read,'Enter filename: ',f openw,1,f for j=0,n-1 do printf,1,points[j],year[j],' '+last[j]+', '+first[j] close,1 print,'Save successful.' end 3: begin first=strarr(100) last=strarr(100) points=fltarr(100) year=intarr(100) n=0 end 4: begin read,'Enter last name: ',s last[n]=s read,'Enter first name: ',s first[n]=s read,'Enter scoring average: ',x points[n]=x read,'Enter year (1-4): ',y year[n]=y n=n+1 print,'There are now '+strcompress(n)+' records.' end 5: begin read,'Enter last name: ',s d=where(last eq s) if d[0] ne -1 then begin first[d[0]:n-1]=first[d[0]+1:n] last[d[0]:n-1]=last[d[0]+1:n] points[d[0]:n-1]=points[d[0]+1:n] year[d[0]:n-1]=year[d[0]+1:n] n=n-1 endif else print,'Record not found.' print,'There are now '+strcompress(n)+' records.' end 6: begin read,'Enter last name: ',s d=where(last eq s) if d[0] ne -1 then begin read,'Enter new last name: ',s last[d[0]]=s read,'Enter new first name: ',s first[d[0]]=s read,'Enter new scoring average: ',x points[d[0]]=x read,'Enter new year (1-4): ',y year[d[0]]=y endif else print,'Record not found.' end 7: begin s=' ' for j=0,n-1 do begin sp=25-strlen(first[j])-strlen(last[j]) print,first[j]+" "+last[j]+strmid(s,0,sp)+syr[year[j]-1],points[j] endfor end 8: begin print,'***Sort Records***' print,'1. Sort by Last Name' print,'2. Sort by Year' print,'3. Sort by Scoring Average' read,'Enter a choice: ',dchoice print,'' CASE dchoice OF 1: begin sname=sort(last[0:n-1]) last[0:n-1]=last[sname] first[0:n-1]=first[sname] points[0:n-1]=points[sname] year[0:n-1]=year[sname] end 2: if n gt 1 then begin for j=0,n-2 do begin for l=j+1,n-1 do begin if year[l] gt year[j] then begin temp=year[j] year[j]=year[l] year[l]=temp temp=points[j] points[j]=points[l] points[l]=temp temp=last[j] last[j]=last[l] last[l]=temp temp=first[j] first[j]=first[l] first[l]=temp endif endfor endfor endif 3: begin spts=reverse(sort(points[0:n-1])) last[0:n-1]=last[spts] first[0:n-1]=first[spts] points[0:n-1]=points[spts] year[0:n-1]=year[spts] end else: print,"Invalid Entry." endcase end 9: begin read,'Enter last name: ',s d=where(last eq s) if d[0] ne -1 then begin print,first[d[0]]+" "+last[d[0]]+" "+syr[year[d[0]]-1],points[d[0]] endif else print,'Record not found.' end 10: print,"Goodbye." else: print,"Invalid entry." endcase endwhile end