Programming Assigment 3 (Deadline: April 27th Monday 23:59)

Problem

Write a C code that implements a set of functions to do the following task.

Task
Emulate a simple display for a calculator.
To do this you will implement the following functions:
void clear();
This clears the display.
void press(char digit);
This will add the specified digit to the display on the current cursor position.
The parameter `digit` will be between '0' and '9'.
The new cursor position will be to the right of the inserted digit.
void left();
Moves the cursor to the left.
If there is no place for the cursor to move, this does nothing.
void right();
Moves the cursor to the right.
If there is no place for the cursor to move, this does nothing.
void delete();
Deletes the digit to the right of the cursor.
If there is no such digit, this does nothing.
void backspace();
Deletes the digit to the left of the cursor.
If there is no such digit, this does nothing.
int value();
Returns the value of the number shown on the display.
If there is no number on the display yet, returns 0.
At any time, if there are leading zeros in the number, they are deleted.
Also, at the beginning of the emulation the display is empty.

Example:
ActionDisplay
beginning|
press('0')|
press('9')9|
press('4')94|
clear()|
press('2')2|
press('0')20|
press('3')203|
left()20|3
press('6')206|3
delete()206|
left()20|6
left()2|06
backspace()|6
right()6|
right()6|
press('4')64|
left()6|4

At the end of this sample execution the call to value() should return 64.

Your code will be tested by linking your code with different programs.
Thus, your code should not contain a main function.
You can test your code by linking it with your own programs.
(Pass more than one source file to gcc to do this.)

Sample Program

#include<stdio.h>

void clear();
void press(char digit);
void left();
void right();
void delete();
void backspace();
int value();

int main()
{
press('0');
press('9');
press('4');
clear();
press('2');
press('0');
press('3');
left();
press('6');
printf("%d\n",value());
delete();
left();
left();
backspace();
right();
right();
press('4');
left();
printf("%d\n",value());
return 0;
}

Sample Output

2063
64

Assumptions and Constraints

You may assume that during the emulation the number displayed never exceeds 999999999.

Hints

If you think that you won't be able to code all of functionality, try to implement a subset of it.
This may give you partial credit.

Submission

Submit your source file (.c) through the submission system.