Homework Question

To learn more about computer memory, you have been asked to write a program that simulates memory using what you have learned in chapter 7 and 8(Deitel-deitel how to program). In this program, you will use a character array of size 80. Each element in the array will represent 1 byte of memory. Initialize all elements in the array to ‘0’. When the element is ‘0’, it means that the memory location is empty, when its ‘1’, then that memory location is full.

Memory will be filled by declaring variables using declaration statements entered into the program by the user. (This program simulates what happens when you declare variables in your program and how much space it allocates in memory, without the semicolon). When the user enters a valid variable declaration statement, memory will be allocated automatically at the first available (empty) location. If there is no memory available for this variable (no consectutive elements -based on variable type- with value ‘0’ in the array), then the program should warn the user with an warning message. The table below shows each data type and how many bytes it allocates in memory for its variables.

Data Types
The number of bytes in stores in memory
int
2 byte
float
4 byte
char
1 byte
int [size]
size*2 byte
char [size]
size*1 byte
float [size]
size*4 byte


The program should check that the declaration statements entered by the user are valid (both data types and variable names) as follows. The statements are not case sensitive Example: int x or Int x should both work with no errors
The variable names should follow the below rules, if they do not follow the rules an error message should be shown to the user:The variable name should not be longer than 10 characters The variable names can only contain digits and letters. The variable names cannot start with a digit. The size of arrays should be declared with digits. You cannot declare variables names that have been declared before.
After making sure that the declarion statement is correct, the number of bytes for that data type will be allocated in the first available memory locations by changing the ‘0’ to ‘1’. The variable name and the start and end addresses of this variable are stored in another array of pointers in the format of: variable name – starting adress – ending address. The start and end adresses are integers in decimal format (not hexidecimal).

The program will also allow the user to delete the variable from memory using the word delete. Example: if the user types delete x , the program will search if a variable called x has been declared and stored in memory or not. If it has been, then its locations in memory will be changed from ‘1’ to ‘0’ and its corresponding name, start and end address are deleted from the array of pointers.
When the user types display, the program will show all the elements of the variable array and the elements of the array of pointers as shown in the example below.

To exit the prgram the user must type exit

Your program should consist of function for each major part of the program: check valid variables, print the elements of the array, finding empty memory locations, etc..

The program should be structured in a user-friendly manner with the proper data types, indentation and comments. And the output of your program should be neat, easy to use and clear.



The below example is done for a 20 element array (yours is size 80). Input by the user is in bold

Example output

Welcome to the Memory Simulation Program

>> display

| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:

>> int yy
>>Int Prg
>>display
| 1 || 1 || 1 || 1 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:
yy-1245004-1245005
prg-1245006-1245007

>> delete g
Cannot process variable name

>> delete yy
>> Displayy
Unknown command

>> DISPLAY
| 0 || 0 || 1 || 1 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:
prg-1245006-1245007

>> float prg
Cannot process variable name

>> floar ff
Unknown command

>>float 2num
Cannot proccess variable name

>> float total
>>DIsplay
| 0 || 0 || 1 || 1 |
| 1 || 1 || 1 || 1 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:
prg-1245006-1245007
total-1245008-1245011

>>char S[3]
>>int dd[10]
No space in memory

>>display
| 0 || 0 || 1 || 1 |
| 1 || 1 || 1 || 1 |
| 1 || 1 || 1 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:
prg-1245006-1245007
total-1245008-1245011
s-1245012-1245014

>> delete total
>> display
| 0 || 0 || 1 || 1 |
| 0 || 0 || 0 || 0 |
| 1 || 1 || 1 || 0 |
| 0 || 0 || 0 || 0 |
| 0 || 0 || 0 || 0 |

Variables:
prg-1245006-1245007
s-1245012-1245014

>>exit
End of program

3 gunum kaldı.Ama ben yapamıyorum((.yardım edebilecek varsa cok iyi olur.
__________________