Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C/C++ program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print

Write a C/C++ program that performs the tasks described below.

If there is just 1 command-line argument and it is -hw you should simply print hello world and then exit(0).

Otherwise the program should expect 2 cmd-line args.

The first arg will be an integer which will be the number of pages of memory that the program should obtain via mmap.

The second arg will be a filename. The file will contain one cmd per line. Each cmd should be interpreted by the program. L

ines that begin with # are comments and should be skipped; empty/blank lines should also be skipped.

Initialize the mmap'd

space with a set of node structures:

struct node

{ long int val;

struct node *next;

};

where val is initialized to -1, and next to NULL.

The commands to interpet are:

isrt val

place val into the next open node in the mmap'd space and also hook it into the linked list sorted by increasing val's (for duplicate value, silently ignore the cmd) (do NOT print anything if the cmd is successful) (if out of space, give an error msg and exit(-1); )

delt val

remove the item from the linked list and then reset the node's val to -1 and next pointer to NULL (if the val is not in list, silently ignore the cmd) (do NOT print anything if the cmd is successful)

prtt some text prints the text on a single line, e.g.: prtt harry potter would print: harry potter

prtu prints vals sequentially from the beginning of the mmap'd space; they are NOT to printed in sorted order; skip those with val -1 print each val and its next pointer (using %p) on a single line separated by two spaces

prts prints sorted list by following the next pointers; print each val and its next pointer (using %p) on a single line separated by two spaces

blnk prints blank line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions