Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#C coding only please. Not C++ or Java You are tasked with writing a program tha

ID: 3844860 • Letter: #

Question

#C coding only please. Not C++ or Java

You are tasked with writing a program that will read different parts of a tape. The tape itself is represented as a 1 dimensional byte array of n size.The user will input commands that will allow the tape to move back and forth by k steps. Each step will output to a file the data being read.

Each head is placed at an offset from the base or starting point of the tape (index 0), this offset is specified by the user. You are tasked with writing the command handler that will invoke functions related to tape head creation. Each head will write to its own respective file. If it is thread 1, it will write out to ./head1, thread 2 will write out to ./head2 and so on.

The main thread needs to wait until all threads have finished reading and writing out to a file. If it attempts to run another command while it is still reading/writing, it could compromise this process, therefore the main thread needs to wait until all other threads have completed and all threads will need to wait until the main thread runs a command.

Your program will use a filename from command line arguments and you will need to read in the binary data. You may treat the data as unsigned bytes.

If no filename is specified in the command line arguments the program should output: Tape Not Inserted

If a file does not exist Cannot Read Tape

The output format when a read head is set HEAD: HEAD<id> at <offset>

When a READ command is ran, the program needs to output when it has finished reading.: Finished Reading

Important: The tape file itself a binary file of n bytes. No other information or data is provided with it. The output of the file should just contain a stream of bytes that was read from the tape and should be rereadable as a tape itself. You are recommend to use pthreads and mutex locks for synchronisation between threads on this task. Assumptions/Clarifications: Offset from head can be negative, you will need to use the modulus operator (beware of an overflow). You may assume that a thread will always start and a file will be created for that thread.

Commands: HEAD <id> at <offset>

READ <offset>

QUIT

Examples

Example 1 Invalid File: Tape Not Inserted

Example 2 File Does Not Exist: Cannot Read Tape

Example 3 Head Example: HEAD 50 HEAD 1 at +50 HEAD -20 HEAD 2 at -20 Example 4 Read: READ 4000 Finished Reading READ -2000 Finished Reading

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace One_Dimensional_Array

{

    class Program

    {

        static void Main(string[] args)

        {

            //Declaring single dimensional array

            string[] Books = new string[5];

            Books[0] = "C#";

            Books[1] = "Java";

            Books[2] = "VB.NET";

            Books[3] = "C++";

            Books[4] = "C";

            Console.WriteLine("All the element of Books array is: ");

            int i = 0;

            //Formatting Output

            Console.Write(" 1 2 3 4 5 ");

            for (i = 0; i < 5; i++)

            {

                Console.Write("{0} ", Books[i]);

            }

            Console.ReadLine();

        }

    }

}

int[] arr = new int[10];

double numbers = new double[5];

string[] names = new string[2];

Single dimensional array initialization

int[] numbers = new int[] { 1, 2, 3, 4, 5, 6,7,8,9,10 };

string[] names = new string[] { "Rocky", "Sam", "Tina", "Yoo", "James", "Samantha" };

You can omit the size of the array, like this:

int[] numbers = new int[] {1, 2, 3, 4, 5};

string[] names = new string[] {"Reena", "Prety", "Rocky", "David");

You can also omit the new operator if you initialize array like this:

int[] numbers = {1, 2, 3, 4, 5};

string[] names = {"aanaa", "Prarroy", "Raju", "ramu"};

namespace array_example1

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] arr = new int[10];

            for (int x = 0; x < 10; x++)

            {

                Console.WriteLine("Enter array element : {0}", x + 1);

                arr[x] = Int32.Parse(Console.ReadLine());

            }

            foreach (int i in arr)

            {

                Console.WriteLine(i);

            }

            Console.ReadLine();

        }

    }

}