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

This is in C#: Create the following two classes: An Order class with a price and

ID: 3806815 • Letter: T

Question

This is in C#:

Create the following two classes:

An Order class with a price and number of shares

A Company class with a name, a priority queue for buy orders, a separate priority queue for sell orders.

In the main method of the sim class, your code must simulate buying and selling stocks. It must match buy and sell orders. For example: a sell order of $50 for 50 shares and a buy order of $55 for 10 shares would result in a sale of 10 shares at $50 with the sale order changing to $50 for 40 shares. A good test case is:

Create one company and, as a test case, add the following:

Add two sell orders: 1) $110 for 5 shares, $100 for 40 shares

Add three buy orders: 1) $5 for 50 shares, $100 for 5 shares, and $110 for 40 shares

Explanation / Answer

Find the below code for the above question

#include <iostream>
using namespace std;

class Order{
  
public:
double price; // price
int number_of_shares;// number_of_shares
  
}

class Company{
  
public:
char name;
std::priority_queue<int> buy_orders;
std::priority_queue<int> sell_orders;


}


#include "Company.h"
class sim{
int main() {

  
   // This function finds the buy sell schedule for maximum profit
void stockBuySell(int price[], int n)
{
// Prices must be given for at least two days
if (n == 1)
return;

int count = 0; // count of solution pairs

// solution vector
Interval sol[n/2 + 1];

// Traverse through given price array
int i = 0;
while (i < n-1)
{
// Find Local Minima. Note that the limit is (n-2) as we are
// comparing present element to the next element.
while ((i < n-1) && (price[i+1] <= price[i]))
i++;

// If we reached the end, break as no further solution possible
if (i == n-1)
break;

// Store the index of minima
sol[count].buy_orders = i++;

// Find Local Maxima. Note that the limit is (n-1) as we are
// comparing to previous element
while ((i < n) && (price[i] >= price[i-1]))
i++;

// Store the index of maxima
sol[count].sell_orders = i-1;

// Increment count of buy/sell pairs
count++;
}

// print solution
if (count == 0)
printf("There is no day when buying the stock will make profit ");
else
{
for (int i = 0; i < count; i++)
printf("Buy on day: %d Sell on day: %d ", sol[i].buy, sol[i].sell);
}

return;
}
  
  
   return 0;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote