Dsa Assignment#01
Dsa Assignment#01
02-134241-016
BS(CS)-3A
DATA STRUCTURE AND
ALGORITHM
DATE: 24-MARCH-2025
CODE
#include <iostream>
using namespace std;
struct Share
{
int quantity;
int purchasePrice;
};
bool isEmpty()
{
return queueSize == 0;
}
void dequeue()
{
if (isEmpty())
{
cout << "Queue is empty. No shares to sell." << endl;
return;
}
queueSize--;
}
Share& peekFront()
{
return queue[front];
}
int main()
{
int totalCapitalGain = 0;
int numTransactions;
cout << "Enter number of transactions: ";
cin >> numTransactions;
if (transactionType == "buy")
{
cout << "Enter number of shares to buy: ";
cin >> quantity;
cout << "Enter price per share: $";
cin >> price;
int totalProfit = 0;
while (quantity > 0 && !isEmpty())
{
Share& frontShare = peekFront();
if (frontShare.quantity <= quantity)
{
totalProfit += frontShare.quantity * (price - frontShare.purchasePrice);
quantity -= frontShare.quantity;
dequeue();
}
else
{
totalProfit += quantity * (price - frontShare.purchasePrice);
frontShare.quantity -= quantity;
quantity = 0;
}
}
if (quantity > 0)
{
cout << "Warning: Not enough shares available to complete the sale!" << endl;
}
totalCapitalGain += totalProfit;
cout << "* Sold shares for a profit/loss of: $" << totalProfit << endl;
cout << "--------------------------------------" << endl;
}
}
return 0;
system("pause");
OUTPUT
CODE
#include <iostream>
using namespace std;
struct BasketballDrill
{
int players[7];
int front = -1;
int rear = -1;
int size = 7;
int turns[7][5] = { 0 };
int dequeue()
{
int player = players[front];
if (front == rear)
{
front = -1;
rear = -1;
}
else
{
front++;
if (front >= size)
front = 0;
}
return player;
}
void setup()
{
cout << "\n==================================================" <<
endl;
cout << " Basketball Passing and Shooting Drill " << endl;
cout << "==================================================" <<
endl;
cout << "\nCoach: Let's start the drill with 7 players!" << endl;
void setTurns()
{
for (int i = 0; i < 7; i++)
{
cout << "Enter the points for player " << i + 1 << " (5 turns): ";
for (int j = 0; j < 5; j++)
{
cin >> turns[i][j];
}
}
}
void displayTurns()
{
cout << "\n===== DETAILS OF EACH PLAYER TURN'S =====:\n";
for (int i = 0; i < 7; i++)
{
cout << "Player " << i + 1 << " turns: ";
for (int j = 0; j < 5; j++)
{
cout << turns[i][j] << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
}
}
void start()
{
for (int round = 1; round <= 5; round++)
{
cout << " Round " << round << ":" << endl;
cout << " --------" << endl;
int main()
{
BasketballDrill drill;
drill.setup();
drill.setTurns();
drill.displayTurns();
drill.start();
return 0;
system("pause");
}
OUTPUT