Sale!

CSE 1325 Homework #8 Generics and Threads solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (5 votes)

In this homework assignment, you will be showing you can create a classes using Generics and use
threads. This is not tied to any of the other programs.
Generics
Part 1: Queue Class
For this part, you must create a Queue Class. A queue is similar to a stack (what the FILO class that we
went over in class). A queue is FIFO (first in first out). You can think of a queue as a checkout line in a
store. When you add to the queue, you add to the end of it. When you remove from the queue, you remove
from the front, and everyone moves up one spot.
The properties that your queue class must have is the following:
int size – how many elements are currently in the queue
int max_size – how many total elements can the queue hold
T* queue – the array representing our queue
void enqueue(T&) – place T at the end of the queue
T& dequeue() – return the element at the front of the queue, remove it from queue, and move all
elements up one spot. (can return T instead of T& if you choose to do that)
T& peek() – return the element at the front of the queue, but don’t update the rest of the queue.
bool isEmpty() – returns true if queue is empty. False otherwise.
int size() – return how many elements are in the queue.
Operator<< – output the entire queue in the following format
1) element1, 2) element2, etc.
Operator<< can be replaced with a print function that prints out the contents of the queue to cout,
or a to_string function that returns a string with the contents of the queue.
Part 2: main
In you main, create 2 queues, each one containing different types. Add several elements to each one. Then
print each queue to terminal. Then remove some elements from each list, printing out each element you
remove. Then print each queue again. Lastly, print out the first element in queue.
Threads
You will be creating a program to simulate depositing and withdrawing money into a bank account. This
homework will not require any objects.
The account balance will be stored in a global variable.
The function account_transaction (double amount) will print out the balance, change the account balance
by the amount (can be positive or negative), then print out the new balance. This function must be able to
handle simultaneous transactions and always give the correct result.
The main function will do the following:
Set the account balance to the beginning balance (You choose the amount)
Print out the beginning balance
Add two amounts to the account balance and remove two amounts from the balance (You choose
the amounts). The transactions must happen simultaneously as threads
Print the final balance after all transactions have finished and joined back to main.
Execution
For this homework, we will not be using a makefile. We will be using regular g++ commands. Your
program must run when the following command is typed in.
For generics, use this command: g++ -std=c++17 abc1234_generics_main.cpp
For threads, use this command: g++ -std=c++17 abc1234_threads_main.cpp -pthread
Deliverables
You will submit your code via Canvas. You will upload a ZIP file, named “abc1234_HW8.zip”,
containing 1 folder named “abc1234” and 3 files. Below is an example of the file structure I’m requesting.
abc1234
abc1234_queue.h
abc1234_generics_main.cpp
abc1234_threads_main.cpp
Full credit files named incorrectly will result in a loss of 5 points each. Failure to follow proper file
structure will result in a loss of 5 points.