Programming Homework Help

Loyola University of Chicago Queue Class and C Programming Lab Report

 

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

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