0% found this document useful (0 votes)
3 views5 pages

Stack

The document outlines a menu-driven program that performs stack operations including PUSH, POP, and DISPLAY on a list of integers, specifically pushing only even numbers onto the stack. It also includes SQL commands to query employee and salary data from two tables, allowing for various selections such as employees with a BasicPay greater than 30000 and displaying total salaries. The SQL commands are structured to demonstrate basic database operations such as creating tables, inserting data, and retrieving information based on specific conditions.

Uploaded by

dxb5382524
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Stack

The document outlines a menu-driven program that performs stack operations including PUSH, POP, and DISPLAY on a list of integers, specifically pushing only even numbers onto the stack. It also includes SQL commands to query employee and salary data from two tables, allowing for various selections such as employees with a BasicPay greater than 30000 and displaying total salaries. The SQL commands are structured to demonstrate basic database operations such as creating tables, inserting data, and retrieving information based on specific conditions.

Uploaded by

dxb5382524
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Write a menu-driven program to perform the following operations on a stack:

i. PUSH
ii. POP
iii. DISPLAY
iv. EXIT
A list N containing M integers is given.
Input the list and display the list elements before performing the PUSH and POP operations.
 Write a function PUSH() that traverses the list N and pushes only the even numbers
into a stack ST.
 Write a function POP() to pop an element from the stack.
 Write a function DISPLAY() to display all the elements of the stack.
If the list contains the following data: N = [12, 13, 44, 56, 21, 79, 98, 22]
Then the stack ST should contain (TOP → BOTTOM):
22, 98, 56, 44, 12

Answer:

ST = []

def PUSH(N):

for i in N:

if i % 2 == 0:

[Link](i)

print("Even numbers pushed into stack.")

def POP():

if len(ST) == 0:

print("Stack is empty.")

else:

print("Popped element:", [Link]())

def DISPLAY():

if len(ST) == 0:
print("Stack is empty.")

else:

print("Stack elements (TOP to BOTTOM):")

for i in range(len(ST)-1, -1, -1):

print(ST[i])

def menu():

N = [12, 13, 44, 56, 21, 79, 98, 22]

print("Original List:", N)

while True:

print("\nMENU")

print("1. PUSH")

print("2. POP")

print("3. DISPLAY")

print("4. EXIT")

ch = int(input("Enter your choice: "))

if ch == 1:

PUSH(N)

elif ch == 2:

POP()

elif ch == 3:
DISPLAY()

elif ch == 4:

print("Exiting the program...Thank you ")

break

else:

print("Invalid choice.")

menu()

2. Given the table EMPLOYEE and SALARY, Write SQL Commands for (a) to (d)

SALARY TABLE

SalaryID BasicPay Allowance


201 25000 5000
202 40000 8000
203 35000 6000
204 30000 7000

EMPLOYEE TABLE

EmpID EmpName Department SalaryID

1 Arjun HR 201

2 Sneha IT 202

3 Rohan Finance 203

4 Meera IT 202

5 Vikram Marketing 204


(a) Display the names of employees whose BasicPay is greater than 30000.

(b) Display employee names with their total salary.

(c) Display employee names along with BasicPay and Allowance, sorted by BasicPay descending.

(d) Display each department along with the number of employees in it

create database hr;

use hr;

CREATE TABLE SALARY (

SalaryID INT PRIMARY KEY,

BasicPay INT,

Allowance INT,

TotalPay INT

);

CREATE TABLE EMPLOYEE (

EmpID INT PRIMARY KEY,

EmpName VARCHAR(20),

Department VARCHAR(20),

SalaryID INT,

FOREIGN KEY (SalaryID) REFERENCES SALARY(SalaryID)

);

INSERT INTO SALARY VALUES (201, 25000, 5000, 30000), (202, 40000, 8000, 48000), (203, 35000, 6000,
41000), (204, 30000, 7000, 37000);

INSERT INTO EMPLOYEE VALUES (1, 'Arjun', 'HR', 201), (2, 'Sneha', 'IT', 202), (3, 'Rohan', 'Finance', 203),

(4, 'Meera', 'IT', 202), (5, 'Vikram', 'Marketing', 204);


(a) SELECT [Link] FROM EMPLOYEE E, SALARY S WHERE [Link] = [Link] AND
[Link] > 30000;
(b) SELECT [Link], ([Link] + [Link]) AS TotalSalary FROM EMPLOYEE E, SALARY S
WHERE [Link] = [Link];
(c) SELECT [Link], [Link], [Link] FROM EMPLOYEE E, SALARY S WHERE [Link] =
[Link] ORDER BY [Link] DESC;
(d) SELECT Department, COUNT(*) AS TotalEmployees FROM EMPLOYEE GROUP BY Department;

You might also like