Assignment Chef icon Assignment Chef

Browse assignments

Assignment catalog

33,401 assignments available

[SOLVED] Prog1970 assign-02 : writing a linux utility (encodeinput)

Description This assignment has you writing a different utility for Linux. This utility (officially called a filter in UNIX / Linux) could be used to take an assembled program (e.g. for the Motorola 6808 Microcontroller) and generate something known as an S19 download file in order to download the assembled code to the actual embedded device. This is similar to your ARM development environment in the MES course – you write and compile your code on a host computer and download it to the ARM board … This application will encourage you to learn more about the common application-programming model in UNIX / Linux. The utility (or filter) that you create will take ANY binary input file, and transform it into its equivalent S-Record output file, OR an assembly file for use in an embedded software development environment. The two different output file formats which are generated by this filter will both be ASCII (human readable). Objectives • Reinforce knowledge of binary arithmetic and the hexadecimal numbering system • Reinforce knowledge of File I/O (both ASCII and binary) in programming – using actual files as well as STDIN and STDOUT • Practice writing a utility that can use command-shell redirecting and/or piping • Practice writing a utility that requires and uses command-line arguments Assign-02 : Writing a Linux Utility (encodeInput)Background The S-RECORD Output of your encodeInput Filter S-Records are often used in embedded development environments in terms of transferring data from one system to another. Development tools like EPROM burners for example accept data in this format. As you may recall from DEF, an ASM file (assembly file) is used by embedded development tools to allow you to specify both machine codes and data (like strings) for your target system. The Motorola S-Record File format was developed a number of years ago. It is also known as the SREC or S19 format. It was developed in the 1970’s by Motorola (for the 6800 microprocessor) to allow you to encode your binary files (e.g. your executables) into an ASCII format file for easy downloading to an embedded system. Visit the link above to learn more about the structure of the S-Record. Example: Input data: ABCDEFGHIJKLMNOPQRST SREC Output data: S00700005345414ED1 S11300004142434445464748494A4B4C4D4E4F5064 S1070010515253549E S5030002FA S9030000FC As you can see, the S19 (or SREC) file is made up of a number of “S” type records (S0, S1, S5 and S9 in the above example). The general format of each of these “S” records is: TTCCAAAADDD .. DDMM Where TT – 2 characters indicating the S-Record type CC – 2 characters representing a single hexadecimal byte telling how many hexadecimal coded bytes follow in that line AAAA – 4 characters representing a hexadecimal address where the data on this S-record line needs to be loaded into memory on the embedded device DD..DD – up to 32 characters – representing up to 16 hexadecimal byte values representing the input data MM – 2 characters – representing a single hexadecimal value which acts as the checksum value for that S Record Things to Note • The COUNT field (CC) of the specific S Record contains the number of bytes including the address field (AAAA), the data fields (DD..DD) and the checksum field (MM) • In our filter we will only be using 4 character address fields (representing a 2 hexadecimal byte address) – this means you only need to use the S1 record for your data. o Since each S1 record is limited to containing a maximum of 16 bytes worth of data – this means that the address value contained in this field will always increment by 16 Assign-02 : Writing a Linux Utility (encodeInput)o This means that each S1 record will only represent 16 bytes worth of encode data. So if the assembled program that you are trying to encode for downloading is 40 bytes in length – then your resultant file will contain two S1 records representing 16 bytes of data each and one S1 record containing the remaining 8 bytes of data (16+16+8=40) • The CHECKSUM field (MM) value is calculated by taking the least significant byte of the 1’s Complement value of the sum of the COUNT, ADDRESS and DATA fields of the record o To calculate this value add the COUNT field’s value with the ADDRESS field’s value with each of the DATA field’s values to get a sum value o Then take the 1’s Complement (remember DEF) of this sum o Then strip off the value in the least significant byte of the resultant value and encode it • One thing that will strike you as odd about the above coding and sample is for example how I say that the COUNT field is 2 characters in output, but represents a single hexadecimal byte o For example the above COUNT field is set to “13” which represents the hex number 0x13 (19 decimal) o You will remember from DEF that a value of 0x13 hex could definitely be stored in a single byte of output – so why then does the resultant S Record output use 2 bytes to store it … it stores the character “1” in one output byte and the character “3” in another byte o This is a form of hexadecimal coded values that the S Record file uses … remember that the S Record out is always human readable ▪ If the output actually stored the value 0x13 in a single byte – the file wouldn’t be readable – check out the ASCII table ▪ 19 decimal in the ASCII table is known as a character called “device control 3 (DC3)” which is unprintable / unreadable by a human o So the hexadecimal encoding that is really happening within this utility is: ▪ If the value that needs to be output would end up being 0xA4 as a hexadecimal value then the output will contain “A4” (ASCII code 65 followed by ASCII code 52) instead ▪ if the value 9 hexadecimal needs to be output by the program, then the output will contain “09” (ASCII code 48 followed by ASCII code 57) ▪ as you can see – each single hexadecimal byte value is translated (encoded) as 2 ASCII output characters • The S0 record is known as the header record of the output file o In this utility, I want you to encode your first name in the DATA field of the S0 record ▪ e.g. the data fields in the above example “5345414E” actually spells SEAN – 5316=8310=ASCII code for “S” • The S5 record is found immediately after the last S1 record serves as summation record within the output file o The AAAA (address field) of this record represents the total number of S1 records that preceded this record in the out • The S9 record is the trailer record in the output file o The AAAA (address field) of this record represents the address in memory on the target embedded device where the program actually starts Assign-02 : Writing a Linux Utility (encodeInput)The ASSEMBLY FILE Output of your encodeInput Filter The required Assembly File format that your utility can also produce is much more straightforward in its coding than the S-Record format. Essentially, this format translates each byte of input data into a define constant byte (dc.b) assembly instruction. Each line of the resultant file is allowed to contain a maximum of 16 bytes of input data. Example: Input data: ABCDEFGHIJKLMNOPQRST Assembly File Output data: dc.b $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F, $50 dc.b $51, $52, $53, $54 Your Task Create a C program that has 4 optional switches (in C, you might consider these as command line arguments). With the exception of the help switch, your filter program (called encodeInput) will take and interpret input as binary values, and produce ASCII readable output based on these switches. The data values encoded in the output will always be the hexadecimal representation of the ASCII value of the input byte. The switches that encodeInput must support are: • -iINPUTFILENAME o This option tells your software the name of the input file. o If this file is not specified, your program will obtain input data from the standard input (stdin file handle) o If the file is specified and does not exist, your program will present an error • -oOUTPUTFILENAME o This option tells your software the name of the output file. o If this file is not specified, and an input file is specified ▪ If the –srec option is not present, then the output filename will be the input filename, with “.asm” file extension appended ▪ e.g. encodeInput –iBinary-01.bin will automatically create an output file called Binary-01.bin.asm ▪ If the –srec option is present, then the output filename will be the input filename, with “.srec” appended ▪ e.g. encodeInput –srec –iBinary-01.bin will automatically create an output file called Binary-01.bin.srec ▪ Notice in this assignment, we are not replacing the input file’s extension – we are simply appending the output file’s extension o If this file is not specified and no input file is specified, then all output will be sent to the standard output (stdout file handle) o If this file is specified and for some reason, it cannot be open for writing purposes, the filter will produce an error • -srec o This option tells your software to output in the S-Record format o Without this option specified on the command line, then an Assembly File output will result • -h o This option will cause the program to output help information (or usage statement) and exit o The usage statement is simply the name of the program and its allowable runtime switches Assign-02 : Writing a Linux Utility (encodeInput)If any other (invalid) switches are present on the command line, the filter will display the usage statement and exit. Because encodeInput uses run-time switches, this program does not need to prompt the end user for any other kinds of input. Instead, if written correctly, the end user will be able to redirect or pipe textual data into the application in place of using a file! Although it probably doesn’t need to be said – the only way that encodeInput should allow an input stream to end is when it reaches the end-of-file. That is, if you are running encodeInput and reading from a file, obviously the input ends when it reaches the end-of-file. Similarly when you are running the utility interactively and are entering input via the keyboard, the input ends when it reaches the end-of-file – not an ENTER key, and not any other special character sequence – just an end-of-file. What you need to do is to simulate an end-of-file from the keyboard – this is done by entering a CTRL-D (pressing the CONTROL key and the D key simultaneously). Please note that CTRL-D only works to end the file when entered at the beginning of the input line – if it is not the first character of the input, then CTRLD serves to flush (or push) the data ahead of it into the program. For example, assume the “D” in the following examples represents when I press CTRL-D and “E” is when I hit enter – so if you enter “123D”, the CTRL-D simply causes the program to read “123”. But if my input is “123ED” – then the CTRL-D is the first character of an input line (because it follows an ENTER) – so this will be interpreted as an EOF character in your program. Some examples of valid command lines: encodeInput -imyData.dat -omyData.srec -srec • The above will convert myData.dat to myData.srec as an S-Record file encodeInput -h • The above will output help (usage statement) information and exit encodeInput -omyData.asm • The above will convert standard input into myData.asm as an assembly file encodeInput –srec -imyData.dat • The above will convert data from myData.dat into myData.dat.srec as an S-Record file encodeInput • The above will convert standard input into Assembly formatted standard output ls -l | encodeInput -odirectory.srec -srec • The above will take the piped standard input from ls -l command and format as an S-Record file output in directory.srec NOTE: The runtime switches can appear in any order on the command line Assign-02 : Writing a Linux Utility (encodeInput)OTHER PROGRAMMING NOTES: • It is expected that your final solution and source code for this utility consists of at least 3 source modules and at least one header file o As before – I am asking you to do this to start you thinking about designing your solutions to properly modularize your solution approach into different source code modules (files) o Remember that it is good design practice to not place any problem-domain knowledge in the main() function o Also it is good design practice to not place any of your solution’s functions in the same source module as the main() function • You must comply with SET Coding Standards o Make sure to comment your source code appropriately – this includes file header comments, function header comments as well as inline comments • Your solution structure must include a makefile and also follow the recommended Linux development directory structure as outlined in the LinuxDevelopment-Project-Code-Structure document within eConestoga Hand in • Please clean and hand in your encodeInput solution – tar up your solution directory into a file titled “lastName-firstInitial.tar” (e.g. John Smith would submit smith-j.tar) and submit to the dropbox Sample BINARY Input File • I have included a sample binary input file (found in the A02-Sample-Binary.tar file included with this assignment). The SREC encoded output file is also included with this sample. Just be aware that the name in the S0 (header) record in the SREC output is mine. • If you would like to see the bytes in the sample binary input file – you can use the od command as I have mentioned in class. Specifically you enter the following command: od -x –endian=big binary-input-file.bin o which will dump the contents of the file out in hexadecimal format with no byte-swapping (i.e. no little endian-ness to the output) • Or if you’d prefer to see the binary file as a sequence of single hexadecimal bytes – you can use the following comment (this is my preference) od –t x1 binary-input-file.bin • In Linux you also have the ability to use the hexdump command as follows: hd binary-input-file.bin which shows you the content in both hexadecimal and ASCII format

$25.00 View

[SOLVED] Prog1970 assign-01 : getting to know the linux development environment

Description This assignment has you writing an encrypting / decrypting utility for Linux. This utility will take any ASCII file and encrypt it in such a way that its contents are not readable – until they are decrypted by the utility. Objectives • Practice creating a software project in Linux in the required development directory structure • Practice creating a makefile for a Linux software project • Reinforce C Programming techniques – File I/O using ASCII files, Command-Line Processing Requirements 1. The utility needs to be called cryptoMagic and needs to be written in C a. The utility has 2 command-line switches – they are –encrypt and –decrypt b. If none of these switches is specified, then –encrypt is assumed c. The utility also takes the name of an ASCII input file to encrypt/decrypt as an argument. d. For example: cryptoMagic –encrypt myFile.txt  will encrypt the contents of the myFile.txt file cryptoMagic myFile.txt  will encrypt the contents of the myFile.txt file cryptoMagic –decrypt myFile.crp  will decrypt the contents of the myFile.crp file 2. When the utility is asked to –encrypt an ASCII file, it will take the input filename and produce the encrypted file with the same base filename and an .crp file extension a. For example: cryptoMagic –encrypt myFile.txt  will produce an encrypted file called myFile.crp 3. When the utility is asked to –decrypt an encrypted file, it will take the input filename and produce the decrypted file with the same base filename and an .txt file extension a. For example: cryptoMagic –decrypt myFile.crp  will produce a decrypted file called myFile.txt 4. It should be noted that the input file can have any file extension. When asked to encrypt, you need to replace the existing file extension (if any) with .crp. Similarly when asked to decrypt, you need to replace the existing file extension (if any) with .txt a. Encrypting always produces a file with a .crp extension, decrypting always produces a file with a .txt extension Assign-01 : Getting to Know the Linux Development Environmentb. Also note that you may be asked to encrypt or decrypt a file that has no extension! In this case, you have no existing extension to replace – you only need to append the .txt (if decrypting) and .crp (if encrypting) 5. Each line (up to and including the carriage return (noted as below)) in the unencrypted ASCII file is guaranteed of being 120 characters of less. While processing the input ASCII file you need to process one line at a time. Continue to process the input file until you reach the end of the file. a. Please note that it is not guaranteed that each line actually ends in a carriage return … how will you handle that? 6. The encryption scheme is applied to each character in the line: a. If the character is a (ASCII value 9) then simply transform it into the output character sequence TT. b. The carriage return characters are not to be encrypted – they are left as is in the resultant output file (the in the example below is meant for illustration only – do not output “”) NOTE: The term “carriage return” in this document does not apply to any specific ASCII code. It applies to the typical end-of-line character that exists in TEXT files within the Linux OS. You may want to investigate what constitutes a carriage return (i.e. end-of-line character in a TEXT file) in the Linux OS c. If is not a tab or a carriage return character, then apply the encryption scheme in steps d through f below d. Take the ASCII code for the input character and subtract a value of 16 from it. Let’s call this resultant value “outChar” e. If the resulting outChar value is less than 32, then another step must be taken: outChar = (outChar – 32) + 144 f. You need to write the ASCII value of the new encrypted character (i.e. outChar) to the destination file as a 2 digit hexadecimal value. Note that this will effectively double the length of the input line in terms of size … For example – if the input (unencrypted) file is: Hello There how are you? My name is Sean Clarke.I like software! Then the encrypted file is: 38555C5C5F80445855625580585F678051625580695F652F 3D69805E515D55805963804355515E80335C51625B558ETT39805C595B5580635F56646751625581 7. Each line (up to an including the carriage return (if it exists)) in the encrypted ASCII file is guaranteed of being less 255 characters or less. Remember – while processing the input ASCII file you need to process one line at a time. 8. The decryption scheme is applied to each pair of characters in the input line: a. You need to see if the pair of characters you are processing is the sequence TT – if so, then simply transform this pair of characters into a character (ASCII value 9) in the output file. Assign-01 : Getting to Know the Linux Development Environmentb. If the pair of characters is not the sequence TT, then translate the first character of the pair by multiplying its face value by 16. Remember that hex values of A through F take on the face values of 10 through 15. Then add the face value of the second character in the pair. Let’s call the resulting value “outChar”. For example: • Reading the pair of characters “38” from the encrypted file will translate into an outChar value of 56 decimal. • Reading the pair of characters “5C” from the encrypted file will translate into an outChar value of 92 decimal. c. Now you need to add 16 to outChar. d. If the resulting outChar value is greater than 127, then another step must be taken: outChar = (outChar – 144) + 32 e. The outChar value now contains the decrypted ASCII code for the character that you have just decoded. So take this decrypted character value (i.e. outChar) and write it to the destination file as a character. f. The carriage return characters are not to be decrypted – they are left as is in the resultant file. For example – if the input (encrypted) file is: 4458596380555E5362696064595F5E80635358555D55805963806062556464698067555962548E 39635E87648059642F812F Then the decrypted file is: This encryption scheme is pretty weird. Isn’t it?!? 9. It is expected that your cryptoMagic utility has been tested (perhaps by using the above examples) as well as with any other encrypted / decrypted examples you can think of. Don’t forget about the extreme / boundary test cases! 10. It is expected that your cryptoMagic utility has been designed using modular techniques (i.e. the program has been written using functions that you’ve created). a. The solution must have at least 2 source files and 1 include file b. There should be no debugging messages present in your final submitted utility 11. Your solution structure must include a makefile and also follow the recommended Linux development directory structure as outlined in the Linux-Development-Project-Code-Structure document within eConestoga. Hand in 1. Please clean and hand in your cryptoMagic solution (entire development directory structure) – tar’d up into a file titled lastNamefirstInitial.tar (e.g. John Smith would submit smith-j.tar) • Ensure that you follow the recommended Linux Development Directory Structure guidelines 2. Make sure you comment your source appropriately, especially the file and function header comments

$25.00 View

[SOLVED] Prog1970 assign-05: the histogram

Background Think of this assignment as a puzzle that you need to solve – and in terms of designing your software there is no single right answer – there are many potential correct solutions. Where requirements have not been stated – you need to figure out a way to do what you need to do in order to (1) satisfy the requirements and (2) get the overall job done. This means that a lot of the design choices in this application are left up to you … Create an application suite (called HISTO-SYSTEM) that consists of three distinct processing components: • a “data consumer” (called DC) application • and two different “data producer” (called DP-1 and DP-2) applications You will need to write the data consumer, and each of the data producer programs in ANSI C under Linux. The purpose of this assignment is to get you to see how / why and when certain IPC mechanisms are used within UNIX / Linux System Application programming. This program will use semaphores, shared memory and signals. The nice thing about this assignment is that for the most part, it can be built upon the sample code that has been demonstrated and provided in class. Overall Considerations Here are a couple of other things to consider: • all applications should have modular design • all applications should have module and function comment blocks • as always – don’t forget to comment your code • also remember to hand in your code in the required directory structure with makefiles for your components • your submitted code should have no debugging “print” statements (or any other print statements in any of the applications) – the only output from this system of three applications is the histogram data being output every 10 seconds from the DC process. Assign-05: The HistogramData Consumer Purpose : The data consumer (DC) program’s job is to read data out of the shared memory’s circular buffer. The data will be populated in this shared memory space by the 2 data producers. Details : • As noted in the Data Producer section below, the circular buffer will be large enough to hold 256 random letters (chosen by the producers). These letters will take on the values ‘A’ to ‘T’ o Make sure that your DC program follows best practices and checks for the existence of the shared memory before attempting to read data out of the buffer o If the shared memory doesn’t exist, then the DC application will sleep for 10 seconds and try again to see if the shared memory has been established and created o Only then can the DC application enter its main processing loop • The DC application will be launched from the DP-2 application. o DP-2 will pass the sharedMemoryID, the DP-1 processID and the DP-2 processID into the DC application on the command line at the time of launching • The DC application will read the random letters out of the circular buffer using the reading index of the buffer • It is the job of the DC application to keep track of (keep a count of) the number of each letter that it reads out of the buffer. The DC process will display a histogram of its current counts. o It will wake-up every 2 seconds (use a wake-up call (SIGALRM) to remind yourself) and read data out of the buffer ▪ The DC application will guard itself from reading the buffer beyond the current write index (Note: this means that the DC application’s access to the buffer must also use the semaphore) ▪ Once the end of the buffer has been reached (i.e. read index 255), the DC application will wrap the read index back to zero and continue reading o Once every 10 seconds, the DC process will display the histogram of its counts ▪ The DC process will clear the screen before displaying the histogram ▪ Use special symbols in your histogram to signify letter count units of “ones” (-), “tens” (+) and “hundreds” (*) ▪ Here are some examples of sample histograms • Assume for the purposes of these examples, that I am tracking the count of only the letters ‘A’ through ‘E’ • If there are 3 A’s, 4 B’s, 4 C’s 5 D’s and 3 E’s – the histogram will look like this A-003 — B-004 —- C-004 —- D-005 —– E-003 — • If there are 8 A’s, 12 B’s, 16 C’s 13 D’s and 9 E’s – the histogram will look like this A-008 ——– B-012 +– C-016 +—— D-013 +— E-009 ——— Assign-05: The Histogram• If there are 58 A’s, 62 B’s, 66 C’s 53 D’s and 49 E’s – the histogram will look like this A-058 +++++——– B-062 ++++++– C-066 ++++++—— D-053 +++++— E-049 ++++——— • If there are 108 A’s, 112 B’s, 121 C’s 109 D’s and 99 E’s – the histogram will look like this A-108 *——– B-112 *+– C-121 *++- D-109 *——— E-099 +++++++++——— • If the DC process receives a SIGINT signal – it will send a SIGINT signal to each of the producers o Question: Think of the launching order of the DC/DP-1/DP-2 applications and ask yourself – which process is in the foreground? How will you send a SIGINT signal to the DC application? o Once the SIGINT signal is received by the DC process, it will set a state within its processing loop such that it will continue to read the data out of the buffer until it catches up (i.e. until the reading index catches up to writing index) o When the DC process has read all of the data out of the buffer, it will ▪ Clear the screen and display the histogram one final time ▪ Clean up its IPC usage and ▪ Exit with the statement “Shazam !!” • Please note that in these requirements, I have not told you exactly how many values to read out of the circular buffer when the Data Consumer is signaled to do so o This is left up to you to experiment with and determine how many the DC should read every 2 seconds knowing that ▪ one of the DPs is blasting 20 values into the buffer every 2 seconds ▪ the other DP is writing 1 value into the buffer every 1/20 of a second o things to consider about how many to read might be ▪ there are only 256 elements in the buffer ▪ remember that the DPs when writing their data are not allowed to overrun (or pass) the point in the buffer where the DC is reading from – so if a DP has to write some data and can’t because writing it would surpass the DC – then that data doesn’t get written ▪ in 2 seconds of running there will be 60 elements written to the circular buffer from the 2 DCs (20 from DP-1 and 40 from DP-2) ▪ so your experimentation range is between 1 and 60 values … • Also don’t forget that this is a circular buffer and the read and write indices wrap around back to the beginning once they’ve reached the end – you will need to do some funny accounting to determine if a DP has enough room to write its data when the indices wrap around Assign-05: The HistogramData Producer(s) Purpose : The data producer (DP) program’s purpose is to setup some shared memory for use as a circular buffer (with a read and write index), to randomly generate some letters (between ‘A’ and ‘T’) and populate the buffer with their choices. For the purposes of the detail write-up, I have identified the 2 producers as DP-1 and DP-2. Details : • DP-1 when launched will allocate enough shared memory to hold a circular buffer of 256 characters, plus enough space for the 2 read/write indices o It will follow best practices and check for the existence of the shared memory, and if not found, will create it o After the shared memory has been created, DP-1 will launch DP-2 and will only pass the sharedMemoryID (shmID) value into DP-2 as a command line argument ▪ DP-2 will need to get its processID (PID), and the processID of DP-1 (it’s parent) and will need to launch the DC application and pass the required information on the command line (as noted in the DC section above) ▪ After launching the DC application, DP-2 will immediately attach to the block of shared memory ▪ At this point, both producers are ready to being populating the buffer with their data • Both DP-1 and DP-2 will guard their writing into the circular buffer through the use of a semaphore • DP-1 will generate 20 random letters one at a time and write all 20 into the buffer in one shot, then it will sleep for 2 seconds o Consider this letter generation and burst-mode write to be an atomic operation • DP-2 will generate one random letter, write it into the buffer and sleep for 1/20 of a second o Consider this single letter generation and single write to be an atomic operation • Both DP-1 and DP-2 will be capable of o Listening for and handling a SIGINT signal ▪ When caught, the DP process will programmatically release the shared memory and exit with no statement to the world. o Once either the DP-1 or DP-2 process writes the 256 element of the buffer, it will wrap the index of the buffer back to zero and continue writing ▪ Both the DP-1 and DP-2 processes will ensure that they never write past the read index ▪ If the case of the DP processes ever catching up / overtaking to the read-index of the buffer happens, the DP process will stop writing and enter its sleep mode – hoping that the DC process catches up and reads more

$25.00 View

[SOLVED] Prog1970 assign-04 : the “can we talk” system

Who This assignment is best completed with a partner (but can be completed individually if you like). Before you begin on the assignment, please use the A-04 Group sign-up (under the Groups option in Course Tools) to organize yourselves into partnerships. Remember that both members of the partnership need to sign-up and enroll in the same group. Description TCP/IP is the most heavily used communications protocol for inter-process communication. It is broadly supported by the socket programming paradigm across multiple platforms. In this assignment, you will write a chat program to demonstrate the basics of socket-based TCP/IP communications. Objectives • Practice C Programming techniques for socket-level programming as well as multi-threaded solutions • Practice the integration and use of a 3rd party library (NCURSES) Requirements 1. In this assignment – you are creating a system called CHAT-SYSTEM. This system is comprised of 2 applications – the server (called chat-server) and the client (called chat-client). These names must be used and reflected in your system development structure. (Please refer to the “Linux Development Project Code Structure” document in the course content) 2. Your solution architecture must be a central server model written in ANSI C. • The server must be multi-threaded. A new thread will be created each time a new user joins the conversation. This thread will be responsible for accepting incoming messages from that user and broadcasting them to the other chat users. Call the server “chat-server”. • QUESTION: How will each of the threads learn about all of the other threads and their IP addresses in order to send the message? Think of a data structure that might be used to hold all client information (IP Address, the user name, etc.) within the server and will be visible and shared among all the communication threads. • Your client application will be written to make use of the ncurses library in order to facilitate the multiple windows. Call the client program “chat-client”. • I have provided some sample ncurses programs in the ncurses-samples.tar archive • You may also want to experiment with threading the client program – one thread to handle the outgoing message window and one thread to handle the incoming messages window. • The chat functionality must operate across computers that are in the same subnet 3. Your chat solution must be able to support at least 2 users being able to chat with each other. • This means that each person can see the messages in the conversation as it goes back and forth – so each user’s message must be tagged with their name (or userID) • Your server design must be able to support a maximum of 10 clients. 4. While running the CHAT-SYSTEM the minimum configuration must be: • The chat-server application must run on a Linux VM (MACHINE-A) • One of the chat-client applications must run on a different Linux VM (MACHINE-B) Assign-04 : The “Can We Talk” System• The second chat-client application can run on the same Linux VM as the server (MACHINE-A) • It is recommended that your chat-client application take at least 2 command-line switches as follows: chat-client –user Assign-04 : The “Can We Talk” System• The server can end the thread that is connected to this client and as well clean up any information dealing with the client. • When the number of threads reaches zero in the server, it may shutdown properly 11. There should be no debugging messages being printed to the screen in your final client and server programs. 12. Your solution must be programmed to handle any and all errors gracefully. 13. Your solution must be programmed to handle any and all shutdowns gracefully. 14. If there are command line parameters available in either your client or server programs then make sure that a usage message appears if the parameters are incorrect or missing. 15. Include the completed A-04: Test Report in your submission • This document does not have to be part of your cleaned, submitted TAR file 16. Make sure to submit your commented, cleaned TAR file to the appropriate drop-box by the due date and time What About the Message? You need to think about what needs to be sent in the message and how it will be formatted. When you are using sockets (or any low-level communication mechanism) one of the most exciting things is that you are in control of the messaging protocol! You get to create the format of, program and enforce your own communication scheme. So let’s consider what needs to be placed in the actual message – what pieces of information need to be sent between the chatting parties? • The IP address of the incoming message can be gotten through the accept() function call– or you could include it in your message • What about the name (5 characters) of the person sending the message? • What about the actual message contents? Should it be parceled on the client before the original send? Or on the server before broadcasting? Please document your messaging scheme and data structure used to manage the multiple client connections in your server code file header comments. • Make sure to include where/how the server will gain knowledge of the client IP and client’s user name • Be sure to include documentation on how the server will handle the bye

$25.00 View

[SOLVED] Csci 463 assignment 3 memory simulator

Abstract In this assignment, you will write a C++ program to simulate a computer system memory. This is the first of a multi-part assignment concluding with a simple computing machine capable of executing real programs compiled with g++. The purpose is to gain an understanding of a machine, its instruction set and how its features are used by realistic programs written in C/C++.1 Problem Description To simulate a computer system’s memory, create a class to represent a memory whose size is defined at run-time via command-line argument. Your memory class will include utility member functions to load it by reading a binary file, print its contents with a hex dump, a method to determine if a given address is legal, and methods that allow a caller to read or write 8, 16 and 32-bit values from (or to) any legal address.Your program will accept parameters from the command line, read data from a file and print all of its non-error output to standard out (aka stdout) via std::cout and usage or file loading error messages to standard error (aka stderr) via std::cerr. (No other output may be printed to stderr. Note that check_illegal() warnings are neither simulator nor user errors and therefore they must be written to stdout.) 2 Files You Must Write You will write a C++ program suitable for execution on hopper.cs.niu.edu (or turing.cs.niu.edu.)Your source files MUST be named exactly as shown below or they will fail to compile and you will receive zero points for this assignment. Create a project directory for this assignment and place within it the source files defined below. main.cpp Your main() and usage() function definitions will go here. hex.h The declarations of your hex formatting class will go here. hex.cpp The definitions of your hex class member functions will go here. memory.h The definition of your memory class will go here. memory.cpp The memory class member function definitions will go here. 2.1 main.cpp You will be provided the code for a suitable main() function for this assignment.Do not alter the code it as its output must match the reference key or else your output will be graded as wrong. You must add Doxygen comments where appropriate. The provided usage() function prints an appropriate “Usage” error message and “Pattern” to stderr and terminates the program in the traditional manner as discussed here: https://en.wikipedia.org/wiki/Usage_message usage() Function 1 static void usage () 2 { 3 cerr memory_limit ; 14 } 15 break ; 16 default : 17 usage (); 18 } 19 } 20 21 if ( optind >= argc ) 22 usage (); // missing filename 23 24 memory mem ( memory_limit ); 25 mem . dump (); 26 27 if (! mem . load_file ( argv [ optind ])) 28 usage (); 29 30 mem . dump (); 31 32 cout

$25.00 View

[SOLVED] Csci 463 assignment 7 ipc

In this assignment, you will implement client and server applications that use a TCP stream socket to communicate with each other.Create client and server applications that use a TCP socket to execute a transaction by sending data from the client to the server for processing and return a result that the client will display.2 Files You Must Write You will write two C++ programs suitable for execution on hopper.cs.niu.edu (and/or turing.cs.niu.edu.) Your source files MUST be named exactly as shown below or they will fail to compile and you will receive zero points for this assignment. Create a directory named a7 and place within it the following files: • client.cpp The client application is implemented in this file. • server.cpp The server application is implemented in this file.2.1 client.cpp Implement a transactional TCP client program: • Usage: client [-s server-ip] server-port – server-ip: Specify the server’s IPv4 number in dotted-quad format. (By default, use 127.0.0.1) Use inet_pton() to parse the IPv4 address as part to build the sockaddr_in of the server to which to connect.– server-port: The server port number to which the client must connect. Don’t forget to use htons() on the integer port number from the command line! • Read (possibly binary) input from stdin and send it to the server by copying it to the socket to send it to the server. Since the input is binary you must not treat it like a null-terminated C string!• After sending the input data, use the shutdown() system library call to let the server know that the request phase of the transaction has completed. • Read any response data from the server and copy it to stdout until the server closes the socket. Make no assumptions as to the nature of the response data from the server and simply copy the raw bytes to stdout.Note: Unless there is an error, the only output that will be written to stdout by the client application will be the response message bytes from the server. If any command-line arguments are invalid then print appropriate error and/or Usage messages and terminate the program in the traditional manner. (See https://en.wikipedia.org/wiki/Usage_message.)Input During the request phase of the transaction the client application will read binary input data from stdin and send it to the server using a TCP socket connection until it encounters EOF on stdin. The client must make no assumptions about the input data, its format, or where it will come from (keyboard, redirected from a file,. . . )During the response-phase of the transaction the client application will read data bytes from the server using the TCP socket connection.Output The client application will write its transaction response data to stdout. Any error messages must be written/printed to stderr by using std::cerr or by calling the standard library perror() function.Do not use printf() or fprintf() in this application. Your program will be tested with a combination of the command-line arguments and will be diff’d against the output from a reference implementation.Here are some test-cases run with the reference implementation (assuming that the server application has already been started and is listening on port 9965) submitting the test files that you already have from prior assignments: winans@hopper:~/a7$ ./client 9965 < ~/a5/sieve.bin | hexdump -C 00000000 53 75 6d 3a 20 36 32 37 32 38 20 4c 65 6e 3a 20 |Sum: 62728 Len: | 00000010 32 31 30 31 39 32 0a |210192.| 00000017 winans@hopper:~/a7$ ./client 9965 < ~/a5/torture5.bin | hexdump -C 00000000 53 75 6d 3a 20 32 31 34 34 32 20 4c 65 6e 3a 20 |Sum: 21442 Len: | 00000010 31 32 37 36 0a |1276.| 00000015 winans@hopper:~/a7$ ./client 9965 < ~/a3/testsx.in | hexdump -C 00000000 53 75 6d 3a 20 33 32 36 34 30 20 4c 65 6e 3a 20 |Sum: 32640 Len: | 00000010 32 35 36 0a |256.| 00000014 winans@hopper:~/a7$ ./client -s 127.9.9.9 200 < ~/a5/torture5.bin | hexdump -C connecting stream socket: Connection refused winans@hopper:~/a7$ ./client 5 < ~/a5/torture5.bin | hexdump -C connecting stream socket: Connection refused2.2 server.cpp Implement a transactional TCP server program: • Usage: server [-l listener-port] – listener-port: The port number to which the server must listen. By default, the port number should be zero (wildcard/ephemeral.) Don’t forget to use htons() on the integer port number from the command line when building the sockaddr_in used by bind! • Enter an infinite loop that will:– accept() a connection from a client. – Print an “Accepted connection” message displaying the IPv4 address and port of the peer client socket. Use inet_ntop() to format the client’s IPv4 address from the sockaddr_in that is filled in by accept().Don’t forget to use ntohs() on the port number before printing it out! – Read all the bytes sent from the client while adding them to a uint16_t variable to accumulate the checksum of each byte that is received.– When an EOF is encountered from the client socket, write the response message formatted like this: Sum: 123 Len: 456n. Note that the message from the server includes the carriage return (shown as n above) that the client will ultimately write to its stdout. The server application must be serially reusable such that after a connection has been closed, regardless of reason, the server will accept another TCP connection for another transaction. Unless there is an error during initialization, the only way the server should terminate is if a user presses ^C to kill the process from the command-line terminal from which it was started. Input The server application will read its input from the socket.The individual bytes in the input byte-stream will be counted and summed. The byte count must be stored in a uint32_t variable and the sum into a uint16_t. The individual bytes that are received by the server must each be saved/treated as uint8_t in order for the compiler to properly zero-extend them while summing them. This is necessary so that any overflows involved with the summing and/or counting will match that of the reference implementation!Observe that if one were to create a file containing exactly 256 bytes containing the values from 0x00 through 0xff then the unsigned decimal sum would be 128*255 = 32640. Consider creating such a test file (or use the testsx.in file from Assignment 3) as a development/debugging test case. Output The server application will display the IP number and port that it is listening on on stdout.The response message from the server must not include a trailing null-terminating character. (See the hexdump -C client sample output above.) Any error messages must be written/printed to stderr by using std::cerr or by calling the standard library perror() function. Do not use printf() or fprintf() in this application.Your program will be tested with a combination of the command-line arguments and will be diff’d against the output from a reference implementation. Here are some example test-run cases: winans@hopper:~$ ./server -l 9965 Socket has port #9965 Accepted connection from ’127.0.0.1’, port 38998 Ending connection Accepted connection from ’127.0.0.1’, port 39002 Ending connection Accepted connection from ’127.0.0.1’, port 39004Ending connection ^C winans@hopper:~$ ./server -l 6 binding stream socket: Permission denied winans@hopper:~$ Note: Since the client uses an ephemeral port, the port numbers printed above that the client uses will vary.3 How To Hand In Your Program When you are ready to turn in your assignment, make sure that the only files in your a7 directory is/are the source files defined and discussed above. Then, in the parent of your a7 directory, use the mailprog.463 command to send the contents of the files in your a7 project directory in the same manner as we have used in the past.4 Grading The grade you receive on this programming assignment will be scored according to the syllabus and its ability to compile and execute on the Computer Science Department’s computer. It is your responsibility to test your program thoroughly. When we grade your assignment, we will compile it on hopper.cs.niu.edu using these exact commands: g++ -g -Wall -Werror -std=c++14 client.cpp -o client g++ -g -Wall -Werror -std=c++14 server.cpp -o serverTo receive full credit the hexdump -C output from your client app showing the length and checksum values must exactly match that of the reference implementation. The examples above were executed using some of the binary files from assignment 5.5 Hints • Watch the course lectures on IPC using TCP. • You can read raw bytes into a character array buffer from stdin in a manner very much like you read from a socket’s file-descriptor, like this: char buf[2048]; ssize_t len = read(fileno(stdin), buf, sizeof(buf)); • You can write raw bytes to stdout from a character array buffer in a manner very much like you write to a socket’s file-descriptor, like this: ssize_t len = write(fileno(stdout), buf, buf_len); Keep in mind that the number of bytes written may be less than the number requested in the buf_len argument above. • Implement and use a safe_write() function, as discussed in lecture, in both your client and server applications.• Don’t forget to ignore broken pipes in your server so that a rogue client won’t crash it. (See lecture for details.) • Note that one can format a printable string using a std::ostringstream (as seen in Assignments 4 and 5) and then extract a C string from it like this: std::ostringstream os; os

$25.00 View

[SOLVED] Csci 463 assignment 5 risc-v simulator

In this assignment, you will extend the functionality of your RISC-V disassembler to also simulate the execution of RV32I instructions. This is the third of a multi-part assignment creating computing machine capable of executing real programs compiled with gcc.The purpose is to gain an understanding of a machine and its instruction set while exercising your programming skills.1 Problem Description Load a binary file into a simulated memory of sufficient size and then decode and execute each 32-bit instruction one-at-a-time starting from address zero and continuing until an ebreak instruction is encountered, an instruction-count limit is reached, or an illegal instruction has been encountered.2 Files You Must Write You will write a C++ program suitable for execution on hopper.cs.niu.edu (or turing.cs.niu.edu.) Your source files MUST be named exactly as shown below or they will fail to compile and you will receive zero points for this assignment.Create a directory named a5 and place within it a copy of all the the source files from assignment 4 and add the additional files discussed below. • hex.h (see assignment 4.) • hex.cpp (see assignment 4.) • memory.h (see assignment 4.) • memory.cpp (see assignment 4.) • rv32i_decode.h (see assignment 4.) • rv32i_decode.cpp (see assignment 4.) • rv32i_hart.cpp The definition of the class rv32i_hart. • rv32i_hart.h The definitions of member functions of class rv32i_hart. • registerfile.h The definition of the registerfile class will go here. • registerfile.cppThe registerfile class member function definitions. • cpu_single_hart.h The definition of the class cpu_single_hart. • cpu_single_hart.cpp The cpu_single_hart class member function definitions. • main.cpp Your main() and usage() function definitions.Provided that no mistakes are present in the files for Assignment 4 then no changes to those files are necessary.2.1 registerfile.h and registerfile.cpp The purpose of this class is to store the state of the general-purpose registers of one RISC-V hart. 1 Recall that a RISC-V hart has 32 registers and that every one is identical except for register x0.Register x0 will always contain the value zero when ever it is read and it will never store anything that is written into it (such data is simply ignored/discarded.) Implement registerfile with a private vector of int32_t elements (one for each register) and a constructor that uses the reset() method to initialize register x0 to zero, and all other registers to 0xf0f0f0f0.It must provide the following member functions: • void reset(); Initialize register x0 to zero, and all other registers to 0xf0f0f0f0. • void set(uint32_t r, int32_t val); Assign register r the given val. If r is zero then do nothing. • int32_t get(uint32_t r) const; Return the value of register r. If r is zero then return zero. • void dump(const std::string &hdr) const; Implement a dump of the registers.The hdr parameter is a string that must be printed at the begining of the output lines. For example, if called as dump(“”) then the output must be formatted precisely as: x0 00000000 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 if called as dump(“HEADER-“) then the output must be formatted precisely as: HEADER- x0 00000000 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 HEADER- x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 HEADER-x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 HEADER-x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 Note the space-gap on the first two lines.Inherit the hex class and use its hex32() utility function to simplify printing the register values! 2.2 rv32i hart.h and rv32i hart.cpp Define rv32i_hart as a subclass of rv32i_decode to represent the execution unit of a RV32I hart as seen in Figure 1 Implement a member function named exec (using a similar design as that used in rv32i_decode::decode) to simulate the execution of RV32I instructions and helper methods for each instruction with names like exec_lui and exec_jalr to perform the simulated execution.1The term hart means “hardware thread.” As part of the simple CPU you are creating for this assignment, this term is the same as what is often referred to as a core.class rv32i_hart : public rv32i_decode 2 { 3 public : 4 rv32i_hart ( memory &m) : mem ( m) { } 5 void set_show_instructions ( bool b) { show_instructions = b ; } 6 void set_show_registers ( bool b) { show_registers = b; } 7 bool is_halted () const { return halt ; } 8 const std :: string & get_halt_reason () const { return halt_reason ; } 9 uint64_t get_insn_counter () const { return insn_counter ; } 10 void set_mhartid ( int i ) { mhartid = i; } 11 12 void tick ( const std :: string & hdr =””) ; 13 void dump ( const std :: string & hdr =””) const ; 14 void reset () ; 15 16 private : 17 static constexpr int instruction_width = 35; 18 void exec ( uint32_t insn , std :: ostream *) ; 19 void exec_illegal_insn ( uint32_t insn , std :: ostream *) ; 20 … 21 22 bool halt = { false }; 23 std :: string halt_reason = { ” none ” }; 24 … 25 uint64_t insn_counter = { 0 }; 26 uint32_t pc = { 0 }; 27 uint32_t mhartid = { 0 }; 28 29 protected : 30 registerfile regs ; 31 memory & mem ; 32 }; Figure 1: rv32i hart() 2.2.1 rv32i hart Public Member Functions • rv32i_hart(memory &m); The constructor must initialize mem as shown in Figure 1 (because the mem member variable is a reference.) • void set_show_instructions(bool b); Mutator for show_instructions.When true, show each instruction that is executed with a comment displaying the register values used (as seen in Figure 8.) • void set_show_registers(bool b); Mutator for show_registers. When true, dump the registers before instruction is executed. • bool is_halted() const; Accessor for halt.Return true if the hart has been halted for any reason. • const std::string &get_halt_reason() const; Return a string indicating the reason the hart has been halted. Values returned are one of the following: – “none” – “EBREAK instruction” – “ECALL instruction” – “Illegal CSR in CSRRS instruction”– “Illegal instruction” – “PC alignment error” • void reset(); Reset the rv32i object and the registerfile. To reset a hart: – Set the pc register to zero. – Call regs.reset() to reset the register values. – Set the insn_counter to zero. – Set the the halt flag to false. – Set the the halt_reason to “none”. • void dump(const std::string &hdr=””) const; Dump the entire state of the hart.Prefix each line printed by the given hdr string (the default being to not print any prefix.) It will dump the GP-regs (making use of the regs member variable by calling regs.dump(hdr)) and then add a dump of the PC register in the following format: x0 00000000 f0f0f0f0 00001000 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 pc 00000000 If the hdr string is set to “[XYZ] ” then the output would look like: [XYZ] x0 00000000 f0f0f0f0 00001000 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 [XYZ] x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 [XYZ] x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 [XYZ] x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0 [XYZ] pc 00000000 • uint64_t get_insn_counter() const; Accessor for insn_counter. Return the number of instructions that have been executed by the simulator since the last reset(). • void set_mhartid(int i); Mutator for mhartid.This is used to set the ID value to be returned by the csrrs instruction for CSR register number 0xf14. (This will always be zero on processors that only have a single-hart.) • void tick(const std::string &hdr=””); The tick() method function is how to tell the simulator to execute and instruction. The hdr parameter is required to be printed on the left of any and all output that is displayed as a result of calling this method.If the hart is halted then return immediately without doing anything. Otherwise, simulate the execution of one single instruction: – If show_registers is true then dump the state of the hart with the given hdr. – If the pc register is not a multiple of 4 then set the halt flag to true, the halt_reason to “PC alignment error”, and return without further processing. – Increment the insn_counter variable (not the pc register.)Fetch an instruction from the memory at the address in the pc register. – If show_instructions is true then ∗ Print the hdr, the pc register (in hex), and the 32-bit fetched instruction (in hex). ∗ Call exec(insn, &std::cout) to execute the instruction and render the instruction and simulation details. – else ∗ Call exec(insn, nullptr) to execute the instruction without rendering anything.Note that the reset() and tick() methods are the only way to change the state of the simulated hart hardware. (Which is similar to but not to be confused with changing the state of the C++ rv32i_hart object! For example, the notion of calling set_show_instructions() can change the state of the rv32i_hart object.But it does not change the state of the simulated hart hardware.) 2.2.2 rv32i hart Private Member Functions • void exec(uint32_t insn, std::ostream*); This function will execute the given RV32I instruction by making use of the get_xxx() methods to extract the needed instruction fields to decode the instruction and invoke the associated exec_xxx() helper function by using the same sort of switch-logic from assignment 4. See Figure 2. This function must be capable of handling any 32-bit insn value.If an illegal instruction is encountered then call an exec_illegal_insn() method to take care of the situation. 1 void rv32i_hart :: exec ( uint32_t insn , std :: ostream * pos ) 2 { 3 … 4 5 switch ( opcode ) 6 { 7 default : exec_illegal_insn ( insn , pos ); return ; 8 case opcode_lui : exec_lui ( insn , pos ) ; return ; 9 case opcode_auipc : exec_auipc ( insn , pos ); return ; 10 11 … 12 } 13 } Figure 2: Implementing exec() • void exec_illegal_insn(uint32_t insn, std::ostream* pos); Set the halt flag and, if the ostream* parameter is not nullptr then use render_illegal_insn() to render the proper error message by writing it to the pos output stream.See Figure 3. 1 void rv32i_hart :: exec_illegal_insn ( uint32_t insn , std :: ostream * pos ) 2 { 3 if ( pos ) 4 * pos

$25.00 View

[SOLVED] Csci 463 assignment 6 c++ multithreading

In this assignment, you will implement a C++ multithreaded application that will sum the elements of a 2-dimensional matrix using either static or dynamic load balancing. Dynamic load balancing will demonstrate the use of a mutex lock in the critical section of code that selects the next row (work) for each thread to process.Static load balancing will demonstrate that when a workload only contains items requiring uniform time to process, some advance planning can, in the best of cases, eliminate the need to create critical sections of code in the first place (thus simplifying a solution.) 1 Problem Description Sum the contents of a 2D matrix in a multithreaded application that uses static or dynamic load balancing based on a command-line argument.2 Files You Must Write You will write a C++ program suitable for execution on hopper.cs.niu.edu (or turing.cs.niu.edu.) Your source file MUST be named exactly as shown below or it will fail to compile and you will receive zero points for this assignment.Create a directory named a6 and place within it the following file: • reduce.cpp Your entire application is implemented in this file.2.1 reduce.cpp • To keep this assignment simple, create these (and only these) global variables for use by the threads in the application: 1 constexpr int rows = 1000; /// < the number of rows in the work matrix 2 constexpr int cols = 100; /// < the number of cols in the work matrix 3 4 std :: mutex stdout_lock ; /// < for serializing access to stdout 5 6 std :: mutex counter_lock ; /// < for dynamic balancing only 7 volatile int counter = rows ; /// < for dynamic balancing only 8 9 std :: vector < int > tcount ; /// < count of rows summed for each thread 10 std :: vector < uint64_t > sum ; /// < the calculated sum from each thread 11 12 int work [ rows ][ cols ]; /// < the matrix to be summed • void sum_static(int tid, int num_threads) Implement the logic needed to sum the rows of the matrix using static load balancing to determine which rows will be processed by each thread. Use the thread ID (passed in from main()) to determine the first row for each thread and then advance the row number by num_threads to determine the next row to process.• void sum_dynamic(int tid) Implement the logic needed to sum the rows of the matrix using dynamic load balancing to determine which rows will be processed by each thread.Each thread must use a mutex lock to access the global (and volatile) counter variable in the critical section to determine the next row to process. Do not hold the lock for any more of the thread logic than is absolutely necessary! • int main(int argc, char **argv) Provide a main() function so that it accepts the command-line parameters (and reflect them in a proper Usage statement) as discussed below. See the on-line manual for getopt(3) for details on how to use it to parse command-line arguments.The command-line arguments you must provide are: – [-d] Use dynamic load-balancing. (By default, use static load balancing.) – [-t num] Specifies the number of threads to use. (By default, start two threads.) Use: std::thread::hardware_concurrency() to determine the number of cores in the system. DO NOT start more threads than the system has cores! If any command-line arguments are invalid then print appropriate error and/or Usage messages and terminate the program in the traditional manner. (See https://en.wikipedia.org/wiki/Usage_ message.)3 Input This program has no input. Initialize the data in the global work matrix using the rand() function from the standard C library. See rand(3) for more information. Note that rand() will always generate the same values, in the same order, if it is seeded to the same initial value. (Note that it is possible that rand() could work differently on different systems. The numbers shown below are those you will see when running on hopper.)Seed your random number generator like this: srand(0x1234); You must initialize work matrix in the same order as the reference key to get the same output! Specifically, you must initialize your matrix from left to right, top-down, starting from the top. That is, set all the columns for row 0, then row 1,. . .4 Output Your program will be tested with a combination of the command-line arguments and will be diff’d against the output from a reference implementation. Note that due to the varying load on the machine, your threads may start and complete in a different order than the reference output below. Your dynamic load balancing may differ in the number of rows summed by each thread between runs of your program as shown below. However, the sums of your static threads and the gross sum value in all cases must match the reference output to be considered correct.1 winans@hopper :~$ ./ reduce 2 8 concurrent threads supported . 3 Thread 0 starting 4 Thread 1 starting 5 Thread 1 ending tcount =500 sum =53670497890830 6 Thread 0 ending tcount =500 sum =53678649666216 7 main () exiting , total_work =1000 gross_sum =107349147557046 8 winans@hopper :~$ ./ reduce -d 9 8 concurrent threads supported .10 Thread 0 starting 11 Thread 1 starting 12 Thread 1 ending tcount =528 sum =56512359755886 13 Thread 0 ending tcount =472 sum =50836787801160 14 main () exiting , total_work =1000 gross_sum =107349147557046 15 winans@hopper :~$ ./ reduce -d 16 8 concurrent threads supported . 17 Thread 0 starting 18 Thread 1 starting 19 Thread 1 ending tcount =545 sum =58565707641474 20 Thread 0 ending tcount =455 sum =48783439915572 21 main () exiting , total_work =1000 gross_sum =107349147557046 22 winans@hopper :~$ ./ reduce -d – t942 23 8 concurrent threads supported . 24 Thread 0 starting 25 Thread 1 starting 26 Thread 2 starting 27 Thread 3 starting 28 Thread 5 starting 29 Thread 7 starting 30 Thread 4 starting 31 Thread 6 starting32 Thread 4 ending tcount =88 sum =9457033734061 33 Thread 1 ending tcount =175 sum =18832858281021 34 Thread 6 ending tcount =54 sum =5779547738442 35 Thread 2 ending tcount =125 sum =13292384416291 36 Thread 0 ending tcount =224 sum =24120680043779 37 Thread 3 ending tcount =109 sum =11701029247359 38 Thread 7 ending tcount =110 sum =11811841106533 39 Thread 5 ending tcount =115 sum =12353772989560 40 main () exiting , total_work =1000 gross_sum =107349147557046 41 winans@hopper :~$ ./ reduce -t3 42 8 concurrent threads supported .43 Thread 0 starting 44 Thread 1 starting 45 Thread 2 starting 46 Thread 1 ending tcount =333 sum =35774388649170 47 Thread 0 ending tcount =334 sum =35960930241047 48 Thread 2 ending tcount =333 sum =35613828666829 49 main () exiting , total_work =1000 gross_sum =107349147557046 5 How To Hand In Your ProgramWhen you are ready to turn in your assignment, make sure that the only files in your a6 directory is/are the source files defined and discussed above. Then, in the parent of your a6 directory, use the mailprog.463 command to send the contents of the files in your a6 project directory in the same manner as we have used in the past. 6 Grading The grade you receive on this programming assignment will be scored according to the syllabus and its ability to compile and execute on the Computer Science Department’s computer.It is your responsibility to test your program thoroughly. When we grade your assignment, we will compile it on hopper.cs.niu.edu using these exact commands: g++ -g -ansi -pedantic -Wall -Werror -std=c++14 reduce.cpp -pthread -o reduce

$25.00 View

[SOLVED] Csci 330 database systems: homework 4

Goal To design databases (E-R diagram and schemas) discussed in chapter 7.Q1 (10 points) Suppose an automobile company (e.g., Toyota) hired you to design a database to assist • Its dealers for maintaining customer records and dealer inventory • Sales staff in ordering cars. The database needs to store information about • Brands (e.g., Toyota, Lexus)• Models (e.g., Camry, Rav4) • Options (e.g., Basic, premium, Prestige) • Individual dealers (e.g., Wilson Motors) • Customers • Vehicles/CarsYou need to remember the following information: • Each brand is identified by brand name (e.g., Toyota, Lexus). • Each model has model_id and name. Each model is identified by the model_id. • Each model must be associated with a brand. i.e., there is no model without a brand.• Each vehicle is identified by VIN (vehicle identification number). • Each vehicle must be associated with a model, i.e., there is no vehicle without a model. • Each model may have many options. For instance, the Rav4 model has three options (e.g., LE, XLE, LE Hybrid).• Each option can have option_id and specification. Each option is identified by option_id. • Each dealer has dealer_id, name, and address. Each dealer is identified by dealer_id. • Each customer has customer_id, name, and address. Each customer is identified by customer_id.• Each vehicle may be associated with a dealer. • Each vehicle may be associated with a customer.(7 points) Draw an E-R diagram to represent the database mentioned above. You must keep the following in mind. • There are 6 strong entity sets and NO weak entity sets. Some entity sets might have a single attribute.• There are 12 attributes and all of them are simple and single-valued attributes. • There are 5 binary relationship sets. There are no other types of relationship sets (e.g., ternary).• NO relationship set has any descriptive attributes. • There are 2 total participation.• In your ER diagram, you will also have to do the following: o Identify the attributes for each entity set. Please underline the primary key. o Specify the cardinality (one to one, one to many, many to one, or many-many) of the diagram.(3 points) Determine the Relation Schemas from the E-R diagram. No optimization is required.Q2 (10 points) Suppose a worldwide packet delivery company (e.g., FedEx) hired you to design their database. The database needs to store information about • customer • packet • placeYou need to remember the following information: • Each customer has a unique customer_id. Each customer also contains their name and address.• Each packet has packet_id and weight. Each packet is identified by its packet_id. • Each place or location has place_id, city, country, and address. Each place can be identified by place_id.• Each packet must be associated with a place, i.e., there is no packet without a place. • Each packet must be associated with a customer, i.e., there is no packet without a customer.The association between customers and packets can be in one of the following ways: o Customer who sends packets. In this case, the customer provides the time_sent information, i.e., when the packet was sent.o Customer who receives packets. In this case, the customer provides the time_recieved information, i.e., when the packet was received). o Some customers may play the role of both sender and receiver.(7 points) Draw an E-R diagram to represent the database mentioned above. You must keep the following in mind: • There are 3 strong entity sets and NO weak entity sets. • There are 9 attributes for the entity sets and all of them are simple and singlevalued attributes.• There are 3 binary relationship sets. There are no other types of relationship sets (e.g., ternary). • Two relationship has two descriptive attributes • Two entity sets may be related by two separate relationship sets. • There are 3 total participation.• In your ER diagram, you will also have to do the following: o Identify the attributes for each entity set. Please underline the primary key. o Specify the cardinality (one to one, one to many, many to one, or many-many) of the diagram.(3 points) Determine the Relation Schemas from the E-R diagram. No optimization is required.What to submit All E-R diagrams and Relation schemas. Submission Instructions • Put all E-R diagrams and Relation schemas in one single doc/docx file. • Convert the file to a pdf file. The file name should be YourLastName-330-HW4.pdf. • Upload the pdf file on canvas. Late Policy • No late work will be accepted

$25.00 View

[SOLVED] Csci 330 database systems: homework 3

Goal The goal of this homework is to learn and practice more SQL commands (both basic and intermediate) for MySQL.1. We will use a publically available database named Chinook https://github.com/lerocha/chinook-database Below is the schema of this database:2. Download the SQL script (Chinook_MySql.sql) available on canvas. We collected this SQL script from the website. Execute this script to create the Chinook database and insert values for the tables. It might take several minutes to finish executing the entire script (~16K lines of SQL code).3. Write SQL queries for the following. a. Find distinct track names that start with “Z.” Sort the output alphabetically. (3 points) b. Find the first names of the employees who are older than their supervisor. Hint: ReportsTo attribute in Employee table stores the EmployeeId of the supervisor. Sort the output alphabetically. (3 points)c. Find the name of the highest-priced track. If more than one track has the highest price, return the names of all such tracks. Sort the output alphabetically based on the track name. (3 points)d. Find a list containing the total amount spent by a customer. Include the customer’s id and the last names along with the total amount. For customers who did not make any purchase, make sure to include them as well. (3 points) e. Find the title of the highest-priced album. (3 points)f. Find a distinct list containing the titles of albums that are never sold. Consider an album never sold if none of its tracks are sold. Sort the output alphabetically. (3 points)g. Create a view that returns customers’ first and last names along with corresponding sums of all their invoice totals. Name the view as “CustomerInvoices.” (2 points)What to submit You have to submit all the SQL queries and the output of the query. If the output contains more than six tuples, then give the top six tuples.Submission Instructions  Put all SQL queries and output in one single doc/docx file.  Convert the file to a pdf file. The file name should be YourLastName-330-HW3.pdf.  Upload the pdf file on canvas. Late Policy:  No late work will be accepted. Questions? If you have any questions, please first check the FAQ page on canvas to see if the question is already answered.

$25.00 View

[SOLVED] Csci 330 assignment 9  tcp programming with sockets – simplified http server

Purpose The purpose of this assignment is to practice programming TCP/IP programs using sockets, and bring together the other programming skills learned throughout the course. The Task Write a C++ program that implements a basic HTTP server. If this is done properly, you should be able to connect to it through a web browser, but this feature will not be part of the criteria for grading The program will essentially consist of a loop that goes on forever (until the program is killed), waiting for a client to connect to it. When a client does connect, the server accepts that connection, then calls fork to make a child process, where it handles communication with the newly-connected client. The parent process should continue to wait for more connections, accepting them and forking as necessary (avoiding fork-bombs). The program will accept two mandatory command line parameters: 1 The port number for the server to listen on. 2 The path to a directory that will serve as the root directory of the web server (the web root) For example, if your zid were z123456, you wanted to run your server on port 9001, and the files to be served were in the ~/www directory, you’d run the program as seen below: ./z123456 9001 ~/www For the purposes of this assignment, the requests sent by the client to your program will be all be of the form: GET /path Where /path is the path, relative to the directory specified as the second command line parameter (the web root), of the file that the client is requesting. There are several rules on what can form a valid path: 1 It must begin with a “/” 2 It may contain additional “/” separators to access subdirectories 3 A single “/” character refers to the directory specified as argument two on the command line 4 A trailing “/” in the pathname can be ignored if the path refers to a directory that otherwise exists. If it refers to a normal file, or to a directory that doesn’t exist, the response should include an error message. 5 There may be no spaces in the filename. In a real web server there is a way to encode them, but you should just avoid spaces for now. Once a space is found in the request, consider the string specifying the requested path to have been completed just before the space. 6 Any data in the request past the path should be ignored. (It is useful in real HTTP but you won’t be worrying about it for this assignment.) 7 It may not contain the substring “..”, in order to prevent files above the web root path from being accessed. what to do with the request? Once your program receives a request from the client (over the TCP/IP connection), it needs to generate and send a response. The response will depend on what the path requested is referencing. If the path requested by the client refers to a directory, then: ▶ If there is a file named “index.html” in the directory, send the contents of that file to the client, byte for byte. ▶ If not, generate a list of the files in the requested directory and send it to the client. (Do not include any files that start with a “.”. You can use opendir and readdir to accomplish this. If you have knowledge of HTML, feel free to format the output nicely and make the filenames work as links, but this is not required. If the path refers to a file, then the contents of that file should be sent to the client, byte for byte After finishing the response, your server should disconnect from the client immediately. Error Checking ▶ Both of the command line arguments are mandatory. If they are not supplied, your program should instruct the user on how to run it properly. CSCI 330 Assignment 9 ▶ If the path given in the second argument doesn’t exist or isn’t a directory, print an appropriate error message to the standard error stream and quit with an appropriate return code. ▶ If any system call fails, the program should use perror to report what happened and then exit with an error code. ▶ If the path in the GET request is invalid, or if a file or directory cannot be accessed, then an appropriate error message should be sent to the client to notify them, and then the connection should be terminated. Other Notes ▶ This is a simple TCP server. If you need a tool to test it, you can use the telnet command to connect to your server at the specified port. Type the request and then hit enter to send it. The client will show the response when it arrives. Here are some examples of what that could look like. These examples are running with the assumption that the server was run with the command line above. This may have a different port or root path in practice. # Start the server first (in another terminal, or with & to launch in bg) % ./z123456 9001 ~/www # Client asked for a dir that has no index.html; server lists files in ~/www/ % telnet localhost 9001 Connected to localhost. Escape character is ‘^]’. GET / fileOne.html fileTwo.html Connection closed by foreign host. # Client asked for a specific file, but it doesn’t exist; server sends error message % telnet localhost 9001 Connected to localhost. Escape character is ‘^]’. GET /fileOne Error: fileOne not found Connection closed by foreign host. # Client asked for a specific file that does exist; server sends its contents % telnet localhost 9001 Connected to localhost. Escape character is ‘^]’. GET /fileOne.html [… contents of file ~/www/fileOne.html …] Connection closed by foreign host. ▶ Remember that testing will be done via turing and hopper, so make sure your program compiles, links and runs properly there before submitting it. This will necessitate testing it with telnet or nc like the example above, because of some restrictions on the ports that can be accessed from outside. ▶ Normal web servers usually run on the standard HTTP port, 80, but users on turing and hopper without elevated privileges will not be able to bind to any ports under 9000, so you will need choose a port number higher than that. The machine can only have one socket listening on a given port, so you may have to choose a different port in that range as you test, when a given port is already in use. ▶ As you are debugging, remember that some ASCII characters aren’t printable, so a simple cout of a string you got over the network might not show you what is going on. Having extra, non-printable characters in, say, a filename, would likely cause your program to fail to open files, etc. It is fairly common for characters such as newlines and carriage returns to be present in the requests made over the network (particularly if testing with telnet), and you should make sure that your program cleans them off the ends of your strings before trying to use them. ▶ If you’d like to continue working on this after the requirements listed in this assignment, you can learn more about the rules for how a fully-featured HTTP (web) server should behave at the HTTP RFC: https://tools.ietf.org/html/rfc2616 Specifically, you will need to send the appropriate HTTP header when the connection is established if you want a web browser to work with your server. (This is not required, but it can be cool to see a program that you wrote serving files to a real web browser.) CSCI 330 Assignment 9 What to turn in? Submit, via Blackboard, the following: ▶ The C++ source code file for your program, named as tcp-z123456.cc, but with your zid instead of z123456.

$25.00 View

[SOLVED] Csci 330 assignment 8 generating reports with awk

Overview Write an awk script that computes and displays a summary of the performance of sales associates for a company based on data in the format specified below. If you are lost, remember that awk loads the input file record by record and does the action of any records that match one of the patterns. If you want to put data from multiple records together, you will need to use some sort of variable. The awk script will be invoked from the command line as shown, with an input file that contains data on a company’s sales department: % awk -f zxxxxxx.awk inputfile Format Specification The records in the input file will use the semicolon,“:”, as their field separator, and the newline character as their record separator. The records will all be contained in the same file, and will be of one of the following three types: 1 Associates – Each salesperson working with the company will have a record in the following format: # Field Name Field Description 1 associateid An decimal integer, uniquely identifying this salesperson 2 name Alphanumeric text containing the name of the salesperson, first name first. 3 position Alphanumeric text containing the position/rank of this salesperson 2 Products – Every product that is available to be sold will have a record in the following format: # Field Name Field Description 1 productid A decimal integer uniquely identifying this product 2 category A string containing the name or code for the category this item falls into 3 name A string containing the name of the product 4 price A decimal number with two digits after the decimal point containing the price of the product per item in US dollars 3 Transactions – Every time a product is sold, there will be at least one record in the following format. If there are multiple records with the same transactionid, the associateid should be the same and the productid should be different. These records would denote that several products were sold as part of the same order. # Field Name Field Description 1 transactionid An integer number identifying the current transaction 2 productid An integer that will match the productid in the record for the product sold 3 associateid An integer number identifying which associate made the transaction 4 date A date in the form MM/DD/YYYY, so 07/04/1776 would mean July 4, 1776 5 quantity An integer number that will contain the quantity of this product sold in this transaction Requirements Your script should have awk process the input file and print out a report that includes the following: 1 A title, printed before anything else is read in. CSCI 330 Assignment 8 2 Labels for each of the fields of the table that follows, neatly-aligned. 3 A line drawn with “=” separating the labels from the table data. 4 A neatly-formatted table, sorted in order of total sales, highest first, containing ▶ The name of each associate that made any sales during the year 2020, last name first, with a comma and a space between. ▶ The ID number of each of those associates. ▶ The total dollar value of all of the sales that they made in 2020. 5 A line drawn with “=”’s separating the table data from the summary below. 6 A neatly-aligned summary of: ▶ How many Associate records were read in from the input file. ▶ How many Product records were read in from the input file. ▶ How many Transaction records were read in from the input file. Do not assume that the records will come in any particular order. They may be intermixed in any order within the data file. Your script should be able to recognize which type of record based on the number of fields. Example Output An example of what the output should look like with the salesdb example input file that is provided on Blackboard. It will be tested with other data files as well, so make sure your awk script is doing the work. % awk -f zxxxxxx.awk salesdb Summary of Sales for 2020 Name ID Sales =================================== Smith, Matt 4 990999.99 Jones, Davy 1 2659.54 Smith, Samantha 3 1159.81 Davis, Ricky 2 299.98 =================================== 8 Associates 6 Products 23 Transactions Error Checking If any error is encountered, such as incorrect data in the input file, just skip the lines in question. Additional notes ▶ The order in which the associates are listed is not significant. They will be identified by their IDs. ▶ Make sure that your assignment is contained in a single file called zxxxxxx.awk (but based on your zid). ▶ Make sure that your awk script runs properly on the department Linux servers, turing/hopper. ▶ Make sure that your awk file is a regular Unix text file. If you made the file on Windows, you will likely need to use dos2unix to fix the file. Check the manpage if you need it. What to turn in? Submit your assignment as a single file, named as required above, via Blackboard before the deadline.

$25.00 View

[SOLVED] Csci 330 assignment 7 automobile database shell program

Goal Your task for this assignment is to write a shell script that will allow its user to create, view, and modify a simple text-based database for automobiles. The script must be implemented with the Bourne shell syntax (use bash). You may use any features available in the version of bash found on turing/hopper, as well as any Unix command available there. Name your script file z1234567sh. Use your zid instead of z1234567, obviously. Specification Your script should support two ways of being run: 1 When run without any direct command-line options – your program is in interactive mode and should prompt the user to find out what to do. Once you finish one task from the user, you should return to that initial prompt and allow the user to request to do more, until they indicate that they would like to quit. You have some leeway in how you accomplish this, but it must be possible to have it perform any of the functions from below. 2 When run with direct command line options (as below) – do the task requested and exit immediately when done. # dbname – filename of database file to use # command – which of the functions to call: “new”, “insert”, “display”, “delete” # param1 – first non-dbname parameter to whichever command function chosen # … – placeholder for parameters between 1 and N # paramN – Nth parameter to whichever command function chosen % ./z1234567sh dbname command param1 param2 … paramN Implementation You must implement the following as bash functions: ▶ new() – This function is used to create a new database file. It takes up to two parameters: 1 The filename to use for the new database file. This must be specified. 2 The label to put on the first line of the new database file. If not specified, use “Untitled database” instead. ▶ insert() – This function is used to add a record to an existing database file. It will always take five parameters. If any of them are missing, it is an error. 1 The filename of the database to add the record to. 2 The make of the car to be stored in this new record. It is a string that must be longer than zero characters. 3 The model of the car to be stored in this new record. It is a string that must be longer than zero characters. 4 The year of the car to be stored in this new record. It must be a four-digit number, greater than 19 21 and smaller than 2029. 5 The color of the car to be stored in this new record. It is a string that must be longer than zero characters. CSCI 330 Assignment 7 ▶ display() – This function is used to show record(s) found in an existing database. This will take up to four parameters, depending on the value of the second. 1 The filename of the database to show the record(s) from. Must be the filename of a readable file. 2 how many to show (one of all, single, or range) ▶ all – Show all of the records, example follows: Automobile Database Ford, Mustang, 2008, blue with white stripes Mitsubishi, Lancer, 2009, white Toyota, Camry LE, 2004, black Porsche, Cayenne S, 2007, red ▶ single – Shows the single record in the position indicated by the third parameter. Notice that record #1 is on the second line, after the label. ▶ range – Show the records in the range starting at the position indicated by the third parameter, up to and including the record indicated by the fourth. ▶ delete() – This function is used to delete records from an existing database. 1 The filename of the database to delete record(s) from. Must be the filename of file readable and writable by the current user.. 2 how many to show (one of all, single, or range) ▶ all – Delete all of the records, but not the label for the database. ▶ single – Delete the single record in the position indicated by the third parameter. Notice that record #1 is on the second line, after the label. It is an error to try to delete a record number that does not exist. ▶ range – Delete the records in the range starting at the position indicated by the third parameter, up to and including the record indicated by the fourth. ▶ count() – This function is used to count and print the number of rows in an existing database. It has one parameter, which is not optional. 1 The filename of the database to count the records in, which must be readable by the current user. Database Format The format you must use for this database will be a text file, with a label for the database on the first line. This label is what is written by the new() function. After the label, there is line per record that is added to the database. The individual fields in the database records should be separated by commas. (“,”). For example, the database file that produced the example for display() with all as its parameter would have contained the following: Automobile Database Ford, Mustang, 2008, blue with white stripes Mitsubishi, Lancer, 2009, white Toyota, Camry LE, 2004, black Porsche, Cayenne S, 2007, red CSCI 330 Assignment 7 Error Checking If an error occurs, print an error message. If the script was run in interactive mode, return to the top of the loop and allow them to try again. If it was used with directly specified command line arguments, it should exit with a non-successful status code. ▶ Ensure that the command is spelled correctly. ▶ Ensure that all the required parameters to the appropriate command are present. ▶ Ensure that record numbers actually fit within lines present in the database file. ▶ Ensure that the database file exists and is readable (except for new(), where it shouldn’t exist) and, in the case of insert() and delete(), also writable. ▶ If the file is empty (no records present), your script should print out a message that no records are found. Example runs % ./z1234567sh DB new “Example for Assignment” New database created % ./z1234567sh DB insert Ford Mustang 2008 “blue with white stripes” Successfully added a record to the database % ./z1234567sh DB add Mitsubishi Lancer 2009 white Successfully added a record to the database % ./z1234567sh DB add Toyota “Camry LE” 2004 black Successfully added a record to the database % ./z1234567sh DB add Porsche “Cayenne S” 2007 red Successfully added a record to the database % ./z1234567sh DB display all Example for Assignment Ford, Mustang, 2008, blue with white stripes Mitsubishi, Lancer, 2009, white Toyota, Camry LE, 2004, black Porsche, Cayenne S, 2007, red % ./z1234567sh DB delete single 2 1 record deleted % ./z1234567sh DB display all Example for Assignment Ford, Mustang, 2008, blue with white stripes Toyota, Camry LE, 2004, black Porsche, Cayenne S, 2007, red % ./z1234567sh DB count 3 CSCI 330 Assignment 7 % cat DB Example for Assignment Ford, Mustang, 2008, blue with white stripes Toyota, Camry LE, 2004, black Porsche, Cayenne S, 2007, red Additional notes ▶ Be sure to test your script thoroughly. ▶ Your script file must use /bin/bash as the path in its shebang line. ▶ Make sure your script does not create any temporary files that are not removed before it ends. ▶ Make sure that your shell script is a regular Unix text file. (not a compiled program or C++ source code). ▶ This is to be done as a shell script. C++ is not acceptable for this assignment. ▶ All testing during grading will be done on turing and hopper. If the script you submit does not work there, it is a you problem. ▶ Blackboard won’t allow files that end in .sh to be submitted, so make sure you call it z1234567sh (no file extension) and not z1234567.sh. What to turn in? Turn in, via Blackboard, the script file you wrote. Make sure its name is as specified above.

$25.00 View

[SOLVED] Csci 330 assignment 6 pipes

Purpose The purpose of this assignment is to make sure that the students can work effectively with the fork, pipe, and dup, system calls. It should also grant some insight into how the shell enables input and output redirection behind the scenes. Description For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text entered for either of these is done, then the program should immediately exit. If done is not found, then each of these lines of input will be treated as a command line to be executed. These two commands should be executed so they behave as if the user had typed command1 | command2 at the shell prompt. This means that the standard output of the first command will be redirected into the standard output of the second command. It should be noted that using cin >> will not grab a whole line; you will need another function to get the whole line. You will need to be able to split the text entered by the user into the individual command line arguments that comprise it. I do not care how you accomplish this, as long as it’s either part of the standard library or code that you wrote entirely on your own. Possibilities include the C function strtok or the C++ istringstream object. You do not need to worry about escaping special characters while splitting the string for the purposes of this assignment; the split can be performed based on spaces alone. After these commands have both finished executing, your program should prompt for another pair of input commands to run, repeating the procedure over and over again until the program receives done as one of its inputs. Example % ls a b c def example typescript % ls | wc 6 6 29 % ls -a . .. a b c def example typescript % ls -a | wc -w 8 % ./assign6 command 1? ls command 2? wc 6 6 29 command 1? ls -a command 2? wc -w 8 command 1? done % CSCI 330 Assignment 6 Requirements ▶ You may not use the system function to do this. You must make your own child processes with fork, do the appropriate changes to the file descriptors in each of them, and have each of them use one of the exec calls to run the commands given by the user. ▶ Use the pipe system call to create the pipe and supply the file descriptors used to communicate between the two programs that are run. ▶ If an error occurs at any point, there should be an appropriate error message printed to the standard error stream. ▶ Your program must be able to handle user-specified commands that contain up to five command-line arguments past the command. ▶ Your program must be able to handle user-specified commands that are up to 255 characters long. ▶ Make sure to close unused pipe file descriptors in all processes. If you fail to do this, your program will likely stall. (deadlock) ▶ Do not forget that this program involves a loop. After both programs have finished running (but not until), the program should go back to the beginning and prompt for two more commands to run. ▶ Like all other programming assignments, this must be well-documented. ▶ Like all other programming assignments, your submission must compile and run on turing and/or hopper. It doesn’t matter if it ran on your home computer if it won’t compile when the TA tries to grade it on the department UNIX machine.

$25.00 View

[SOLVED] Csci 330 assignment 4 shhhhhhh…. it’s a secret!

Purpose This assignment should give you experience in using file descriptors, open(2), close(2), write(2), stat(2) and chmod(2), perror(3), as well as working with command line arguments. The numbers in parentheses here are section numbers so you can find the right manpage. Program A typical UNIX system will have many files that contain sensitive information. Permissions can keep these files secure. Some files can be publicly read, but can not be altered by a regular user (eg. /etc/passwd). Other files can’t be read at all by a regular user (eg. /etc/shadow). Your task is to write a C++ program that will allow you to add messages to a file that has NO permissions granted for any user. The program you develop will take a message as a command line argument and append that message to the end of a file (which is also specified as a command line argument). It will also support a -c command-line option that, when supplied, will cause your program to clear the file before the message is appended. The file should have all permissions denied for any user, both before and after the message is appended. For this to work, the person running the program needs to be the owner of the file. Algorithm 1 Check to see whether the output file exists. If it doesn’t, create it. It will make things easier for you if any newly created file is closed at the end of this step. 2 Check the output file’s permissions. If any exist, print a useful error message and exit. 3 Change the permissions on the file to allow writing by the user. 4 Open the file for output. If the -c command line option is present, truncate the file contents. 5 Write the message passed in on the command line into the output file. Write an additional newline character so that the output has a nicer format. 6 Clear the permissions and close the file. (These two operations can be performed in either order, but the implementation will be slightly different.) Useful Hints • Don’t use the command line arguments directly. Their position in the argument list may change depending on command line options (like your “-c”). Create meaningful char * variables and fill these with the appropriate entries from the argument list, once you’ve determined their proper positions. I would recommend using getopt(3) to handle the command line options/arguments. • This program will not be reading in any kind of input except for the command line arguments. If you’re trying to use cin or read for something, you’re probably doing something wrong. Error Checking • If the message log file cannot be opened, an appropriate error message should be printed to standard error and the program should exit immediately. If the file has any permissions at all, the file should be rejected as insecure, and the program should exit. CSCI 330 Assignment 4 (Spring 2021) 2 of 2 • Check for error values after every system call that can fail (that’s most of them), and print out what happened when an error did occur. It is more work to set up, but when something goes wrong, you’ll actually have an idea what caused the problem. Example Run # Note: seclog is the compiled program in executable form % rm log % ./seclog Usage: seclog [-c] out_file message_string where the message_string is appended to file out_file. The -c option clears the file before the message is appended % chmod u-w . % ./seclog log “Hello” Permission denied % chmod u+w . % ./seclog log “Hello 1” % ls -l ———- 1 z123456 student 8 Sep 24 18:39 log -rwxr-xr-x 1 z123456 student 26385 Sep 24 18:38 seclog* -rw-r–r– 1 z123456 student 2204 Sep 24 18:36 z123456.cc -rw-r–r– 1 z123456 student 30896 Sep 24 18:38 z123456.o % ./seclog log “Hello 2” % ls -l ———- 1 z123456 student 16 Sep 24 18:40 log -rwxr-xr-x 1 z123456 student 26385 Sep 24 18:38 seclog* -rw-r–r– 1 z123456 student 2204 Sep 24 18:36 z123456.cc -rw-r–r– 1 z123456 student 30896 Sep 24 18:38 z123456.o % chmod 400 log % cat log Hello 1 Hello 2 % ./seclog log “Wait, there’s more” log is not secure. Ignoring. % chmod 000 log % ./seclog log “Wait, there’s more” % ls -l ———- 1 z123456 student 35 Sep 24 18:41 log -rwxr-xr-x 1 z123456 student 26385 Sep 24 18:38 seclog* -rw-r–r– 1 z123456 student 2204 Sep 24 18:36 z123456.cc -rw-r–r– 1 z123456 student 30896 Sep 24 18:38 z123456.o % chmod 400 log % cat log Hello 1 Hello 2 Wait, there’s more % chmod 000 log % seclog -c log “Clean start” % ls -l total 72 ———- 1 z123456 student 12 Sep 24 18:41 log -rwxr-xr-x 1 z123456 student 26385 Sep 24 18:38 seclog* -rw-r–r– 1 z123456 student 2204 Sep 24 18:36 z123456.cc -rw-r–r– 1 z123456 student 30896 Sep 24 18:38 z123456.o % chmod 400 log % cat log Clean start % chmod 000 log What to turn in? Submit, through Blackboard, the following: • A single C++ source file implementing the program. Use the name a4-z123456.cc, but use your Zid in the name instead of the example one. Remember, there is no credit for late work and, as usual, the grading will be performed on turing and/or hopper, so you must ensure that your program compiles and runs properly on them. It does not matter if it was working somewhere else if it doesn’t work on those machines where it is finally tested.

$25.00 View

[SOLVED] Csci 330 assignment 3 implement cat command

Purpose The purpose of this assignment is to provide practice using the system calls for working with files on a UNIX system. You will be writing a basic implementation of the cat command using C++. Description As you should recall, the cat command takes a list of files as command line arguments. It then opens each file in turn, writing each file’s entire contents to standard output in the order they were supplied. You will be responsible for writing a C++ program that implements this behavior. If you are unclear on what your output should look like, compare your program’s output to the output from the actual cat program. As seen in its manpage (man cat), the actual command does have some additional options that can be used, but other than the single dash, “-”, for standard input, you don’t need to implement those. Requirements 1 The user can pass as many filenames as they wish as command line arguments. Your program must be able to handle all of the files, no matter how many are passed. 2 No matter how long each file is, your program must be able to read and output all of the data it contains. This may be tested with a file that is larger than all of the RAM available to you, so you need to find a way to print its contents anyway. 3 All of the data must be displayed, even if the files contents have non-text data. Notice that this means cout

$25.00 View

[SOLVED] Web – exercises on dom manipulation part 1

Getting data from the DOM. In this exercise you will try and get some data from the provided recipe website. Fire up the index.html on your live server. Use the appropriate methods and properties available to you to get the correct data from the “correct” recipe. All answers should be saved in some variable and logged to the console. If you don’t know the right method or property to use, see this link for all available ones: https://www.w3schools.com/jsref/dom_obj_all.asp 1. What is the name of the recipe? 2. What HTML tag is used to display the Recipe name? 3. What is the font size of the paragraph tag with the class “description”. 4. What is the value of the alt atrribute on the image? 5. What is the dimensions and the url of the image? Create an object that looks like this, and log it to the console: js { url: string height: number, width: number, } 1. How many ingredients has the paste? 2. Which is the forth element in the list containing the ingredients for the paste? 3. Create an an array of objects from the instructions. Each element in the array should be an object that looks like this: js { order: number; text: instruction; } Exercises in DOM manipulation Part 2 In this exercise you will be using the same pre-built webside. What’s special about this website is that it comes in two versions. One which is the “correct” one and one that has many “errors” in it. Your task is to correct these errors with the aid of JavaScript. All of the right answers, styling, formatting and texts can be found in the correct version of the site. So there is your reference so to speak. Each question in the following list of questions aims at a specific error on the website, and it goes from top to bottom and left to right on the website. The solution to all these question can be reached by using the different DOM manipulation methods and properties that you might have or might not have learned during the course. Some googling might be required. This link might help you: https://www.w3schools.com/jsref/dom_obj_all.asp 1. The logo text of the site has the wrong color. Change it to the correct one. 2. The alignment of the elements inside the header element are wrong. Change it to the correct one. Hint, check the flex properties for the correct alignment. Here is a link that might help: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 3. The header has a border at the bottom, but it has the wrong color. Change it do the correct one. 4. The recipe name is wrong, change it to the correct one. 5. The clock icon beneath the recipe name has disappeared and been replaced by a text instead. This can be fixed by adding a class to that element. 6. The estimated time of the recipe is also incorrect. Change it to the correct time estimation. 7. The src path to the image is wrong, or atleast it’s showing the wrong image. Change it to the correct one. The available images can be found in the assets folder. 8. The background color of the ingredients list container is wrong. Fix it. 9. The ingredients are divided in to two parts, one for the bottom and one for the paste. In the list of the ingredients to the bottom, there is a text instead of two list items. Remove the text and add those two list items. 10. The third ingredient in the list of ingredients to the paste is wrong. Change that specific ingredient to the correct one. 11. There is also a missing ingredient in the list of ingredients to the paste. Look and see what it is and add that one the the end of the list. 12. The text “Instructions” to the left, beneath the image, has some shadow styling applied to it. Remove that styling. 13. Two list elements of the list of instructions are incorrect. Find them and change them to the correct ones.

$25.00 View

[SOLVED] Web – account registration

In this exercise you will build a form in which you can simulate a creation of an account to some web application. The purpose of this exercise is to practise on using different event listeners ( several are needed ) but also to create a basic application that is comprised of HTML, CSS and JavaScript. You are more then welcome to work together on this one. It’s important that you challenge yourself and try out new things. REMEMBER, events can be a tricky endevour, sometimes it’s easier to have fewer events the more. Lift up the event listeners and rely on DOMmanipulation in order to interact with the different elements. Use event.target in order to get information on which element that triggered the element and so on. Here are some usefull links and tips in order to complete the assignment. List of all the available events in JS List of DOM manipulating methods on elements querySelector classList, and how to use it array methods in JS Events you can or might use: “click”, “submit” “input”, “focus”, “focusin”, “focusout”, “blur” The form should have to following content and functionlity. Five inputs must be included and they should reside within a . nameand username which must be of type text. One input for email that is of type email and two inputs for password and confirm password. They should of course be of type password. One input or button for submitting the form. Every input should be accompanied by a label and they must be connected. That means that if you click on the label, the corresponding input gets selected ( focus ). You are NOT! allowed to use the for attribute on the label in combination with the id attribute on the input in order to solve this. Hint… All of the inputs must be mandatory, meaning that you shouldn’t be able to submit the form if one of the inputs is missing a value. Hint… The password must be atleast 8 characters long. If the password is not of length, the input should receive appropriate styling to visualize this for the user. When the passwords is long enough the styling returns to normal ( or to an affirmative state if you would like ). Hint… The confirm password must be validated to be identical as the password. If that’s not the case, the input should receive appropriate styling to visualize this for the user, much like the previous part. Hint… If the password or the confirm password has not been correctly typed, the submit button should be disabled. There must be a submit event in the application. When the form is submitted all of the data should be presented in an object like this: js const registrationData = { name: “first name last name”, username: “username”, email: “[email protected]”, password: “password”, }; This object is to be written to the console or written in an alert. The values should of course be corresponding to the values that the user have typed. I would like that you also focus on writing clean code and use decent, thought-through, stylings. ( The image below is just AN EXAMPLE on how it CAN look! You have free reins on the design. )Example

$25.00 View