Example pseudo-code: not sure if correct
Object:
int index
int version
other data
SlotMap:
Object objects[]
int slots[]
int freelist[]
int count
Get(id):
index = indirection[id.index]
if objects[index].version = id.version:
return &objects[index]
else:
return null
CreateObject():
index = freelist.pop()
objects[count].index = id
objects[count].version += 1
indirection[index] = count
Object* object = &objects[count].object
object.initialize()
count += 1
return object
Remove(id):
index = indirection[id.index]
if objects[index].version = id.version:
objects[index].version += 1
objects[count – 1].version += 1
swap(objects[index].data, objects[count – 1].data)
program question:
using c, write a set of functions using dynamic arrays that will represent a video game store inventory.
1. The program should open the first file name given on the command line (NOT stdin). The file will contain a list of the format (name, price, number in stock ). For example:
Call of Duty 16, 9.99, 12
Skyrim Super Amazing Legendary Edition, 19.99, 8
Left for Dead 6, 75.00, 3
A sample program execution is:
a.out inputfile outputfile
There can be any number of games in the file. Make sure your dynamic arrays can shrink and grow to fit the data.
2. In the file, dynamicarray.c, write the code necessary to complete the assignment.
(a) The program should first print the inventory with numbers and a command prompt:
1. Call of Duty 16, 9.99, 12
2. Skyrim Super Amazing Legendary Edition, 19.99, 8
3. Left for Dead 6, 75.00, 3
COMMAND:
(b) When the user types a number, it should subtract 1 from the number in stock for that game. For example:
COMMAND: 2
would result in the following output:
1. Call of Duty 16, 9.99, 12
2. Skyrim Super Amazing Legendary Edition, 19.99, 7
3. Left for Dead 6, 75.00, 3
COMMAND:
The number of in stock for a game cannot go below 0. If the user tries to remove a game that has 0 stock, the program should print an error message. For example if Left for Dead had 0 stock, it would print:
1. Call of Duty 16, 9.99, 12
2. Skyrim Super Amazing Legendary Edition, 19.99, 7
3. Left for Dead 6, 75.00, 0
COMMAND: 3
***ERROR: 3. Left for Dead 6 is OUT OF STOCK
(c) When the user types ’q’, the current inventory should then be printed to the output file (i.e., the second filename given on the command line) in the same format as the input file (name, price, number in stock). Then the program will terminate.
3. The program should free all storage allocated before it terminates. Run your program under valgrind to verify that you have no memory leaks or other errors. For example:
valgrind a.out inputfile outputfile
Your valgrind output should look something like:
==1239==
==1239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 1)
==1239== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1239== malloc/free: 23 allocs, 23 frees, 100,400,748 bytes allocated.
==1239== For counts of detected errors, rerun with: -v
==1239== All heap blocks were freed — no leaks are possible.
The post Computer science C Programming help. I have an example pseudocode: appeared first on Essaysholic.
Would you like to get in touh with us?
Contact Us
Is this question part of your Assignment?
We can help
Our aim is to help you get A+ grades on your Coursework.
We handle assignments in a multiplicity of subject areas including Admission Essays, General Essays, Case Studies, Coursework, Dissertations, Editing, Research Papers, and Research proposals
Header Button Label: Get Started NowGet Started Header Button Label: View writing samplesView writing samples