Question
TO Convert pseudocode into VB CODE. 1 Module main() 2 // Variable to hold the menu selection. 3 Declare Integer menuSelection 4 5 Do 6
TO Convert pseudocode into VB CODE.
1 Module main()
2 // Variable to hold the menu selection.
3 Declare Integer menuSelection
4
5 Do
6 // Display the menu.
7 Call displayMenu(menuSelection)
8
9 // Perform the selected operation.
10 Select menuSelection
11 Case 1:
12 Call addRecord()
13
14 Case 2:
15 Call searchRecord()
16
17 Case 3:
18 Call modifyRecord()
19
20 Case 4:
21 Call deleteRecord()
22
23 Case 5:
24 Call displayRecords()
25 End Select
26 While menuSelection != 6
27 End Module
28
29 // The displayMenu module displays the menu, gets
30 // the user's selection, and validates it.
31 Module displayMenu(Integer Ref selection)
32 // Display the menu.
33 Display " Inventory Menu"
34 Display "1. Add a record."
35 Display "2. Search for a record."
36 Display "3. Modify a record."
37 Display "4. Delete a record."
38 Display "5. Display all records."
39 Display "6. End the program."
40 Display
41
42 // Get the user's selection.
43 Display "Enter your selection."
44 Input selection
45
46 // Validate the selection.
47 While selection < 1 OR selection > 6
48 Display "That is an invalid selection."
49 Display "Enter 1, 2, 3, 4, 5, or 6."
50 Input selection
51 End While
52 End Module
53
54 // The addRecord module lets the user add a record
55 // to the inventory file.
56 Module addRecord()
57 // Variables for the fields
58 Declare String description
59 Declare Real quantity
60
61 // Variable to control the loop
62 Declare String another = "Y"
63
64 // Declare an output file in append mode. 65 Declare OutputFile AppendMode coffeeFile
66
67 // Open the file.
68 Open coffeeFile "coffee.dat"
69
70 While toUpper(another) == "Y"
71 // Get the description.
72 Display "Enter the description." 73 Input description
74
75 // Get the quantity on hand.
76 Display "Enter the quantity on hand ",
77 "(in pounds)."
78 Input quantity
79
80 // Append the record to the file.
81 Write coffeeFile description, quantity
82
83 // Determine whether the user wants to enter
84 // another record.
85 Display "Do you want to enter another record?"
86 Display "(Enter Y for yes, or anything else for no.)"
87 Input another
88
89 // Display a blank line.
90 Display
91 End While
92
93 // Close the file.
94 Close coffeeFile
95 Display "Data appended to coffee.dat."
96 End Module
97
98 // The searchRecord module allows the user to
99 // search for a record in the inventory file.
100 Module searchRecord()
101 // Variables for the fields 102 Declare String description
103 Declare Real quantity
104
105 // Variable to hold the search value
106 Declare String searchValue
107
108 // Flag to indicate whether the value was found
109 Declare Boolean found = False
110
111 // Declare an input file.
112 Declare InputFile coffeeFile
113
114 // Get the value to search for.
115 Display "Enter a value to search for."
116 Input searchValue
117
118 // Open the file.
119 Open coffeeFile "coffee.dat"
120
121 While NOT eof(coffeeFile)
122 // Read a record from the file.
123 Read coffeeFile description, quantity
124
125 // If the record contains the search value,
126 // then display it.
127 If contains(description, searchValue) Then
128 // Display the record.
129 Display "Description: ", description,
130 "Quantity: ", quantity, " pounds"
131
132 // Set the found flag to true.
133 Set found = True
134 End If
135 End While
136
137 // If the value was not found in the file,
138 // display a message indicating so.
139 If NOT found Then
140 Display searchValue, " was not found."
141 End If
142
143 // Close the file.
144 Close coffeeFile
145 End Module
146
147 // The modifyRecord module allows the user to modify
148 // an existing record in the inventory file.
149 Module modifyRecord()
150 // Variables for the fields
151 Declare String description
152 Declare Real quantity
153
154 // Variable to hold the search value
155 Declare String searchValue
156
157 // Variable to hold the new quantity
158 Declare Real newQuantity
159
160 // Flag to indicate whether the value was found
161 Declare Boolean found = False
162
163 // Declare an input file.
164 Declare InputFile coffeeFile
165
166 // Declare an output file to copy the original
167 // file to.
168 Declare OutputFile tempFile
169
170 // Open the files.
171 Open coffeeFile "coffee.dat"
172 Open tempFile "temp.dat"
173
174 // Get the value to search for.
175 Display "Enter the coffee you wish to update."
176 Input searchValue
177
178 // Get the new quantity.
179 Display "Enter the new quantity."
180 Input newQuantity
181
182 While NOT eof(coffeeFile)
183 // Read a record from the file.
184 Read coffeeFile description, quantity
185
186 // Write either this record to the temporary
187 // file, or the new record if this is the
188 // one that is to be changed.
189 If description == searchValue Then
190 Write tempFile description, newQuantity
191 Set found = True
192 Else
193 Write tempFile description, quantity
194 End If
195 End While
196
197 // Close the two files.
198 Close coffeeFile
199 Close tempFile
200
201 // Delete the original file.
202 Delete "coffee.dat"
203
204 // Rename the temporary file.
205 Rename "temp.dat", "coffee.dat"
206
207 // Indicate whether the operation was successful.
208 If found Then
209 Display "The record was updated."
210 Else
211 Display searchValue, "was not found in the file."
212 End If
213 End Module
214
215 // The deleteRecord module allows the user to delete
216 // a record from the inventory file.
217 Module deleteRecord()
218 // Variables for the fields
219 Declare String description
220 Declare Real quantity
221
222 // Variable to hold the search value
223 Declare String searchValue
224
225 // Declare an input file.
226 Declare InputFile coffeeFile
227
228 // Declare an output file to copy the original
229 // file to.
230 Declare OutputFile tempFile
231
232 // Open the files.
233 Open coffeeFile "coffee.dat"
234 Open tempFile "temp.dat"
235
236 // Get the value to search for.
237 Display "Enter the coffee you wish to delete."
238 Input searchValue
239
240 While NOT eof(coffeeFile)
241 // Read a record from the file.
242 Read coffeeFile description, quantity
243
244 // If this is not the record to delete, then
245 // write it to the temporary file.
246 If description != searchValue Then
247 Write tempFile description, newQuantity
248 End If
249 End While
250
251 // Close the two files.
252 Close coffeeFile
253 Close tempFile
254
255 // Delete the original file.
256 Delete "coffee.dat"
257
258 // Rename the temporary file.
259 Rename "temp.dat", "coffee.dat"
260
261 Display "The file has been updated." 262 End Module
263
264 // The displayRecords module displays all
265 // of the records in the inventory file.
266 Module displayRecords()
267 // Variables for the fields
268 Declare String description
269 Declare Real quantity
270
271 // Declare an input file.
272 Declare InputFile coffeeFile
273
274 // Open the file.
275 Open coffeeFile "coffee.dat"
276
277 While NOT eof(coffeeFile)
278 // Read a record from the file.
279 Read coffeeFile description, quantity
280
281 // Display the record.
282 Display "Description: ", description,
283 "Quantity: ", quantity, " pounds"
284 End While
285
286 // Close the file.
287 Close coffeeFile
288 End Module
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started