0% found this document useful (0 votes)
4 views

Set - 3

The document outlines two practical exercises for a Computer Science class. Practical 1 involves creating a menu-driven program to manage book details using a stack, allowing users to add, delete, and display book information. Practical 2 includes SQL commands for displaying average sales, modifying a database table, updating records, and sorting data in descending order of sales.

Uploaded by

www.suraj3000
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Set - 3

The document outlines two practical exercises for a Computer Science class. Practical 1 involves creating a menu-driven program to manage book details using a stack, allowing users to add, delete, and display book information. Practical 2 includes SQL commands for displaying average sales, modifying a database table, updating records, and sorting data in descending order of sales.

Uploaded by

www.suraj3000
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Roll Number:

Name:

Date:

Class: 12

Section:

Subject: Computer Science Practical (083)

School Name: GSBV, Burari, Delhi – 84

SET – 03

Practical - 1:
Write a menu driven program which insert, delete and display the details of a book such as

book_id, book_name and price using Stack.

#Initiliaze an empty stack Book.

Book=[]

c='y'

while(c=='y' or c=='Y'):

#Create the menu for the different types of options

1 SET - 3
print("1: Add Book Details: ")

print("2: Delete Book Details: ")

print("3: Display Book Details: ")

choice=int(input("Enter Your Choice: "))

if(choice==1):

#Input the details of books from user using input()

book_id=int(input("Enter Book Id: "))

book_name=input("Enter Book Name: ")

price=float(input("Enter Book Price: "))

#Create a tuple to combine all details of a Book

B=(book_id,book_name,price)

#Append the book records into the stack

Book.append(B)

elif(choice==2):

if(Book==[]):

print("Stack Empty")

else:

2 SET - 3
print("Deleted element is: ",Book.pop())

#pop() method is used to delete the topmost element from the stack

elif(choice==3):

L=len(Book)

while(L>0):

#Display the book details one by one from stack

print(Book [L-1])

L=L-1

else:

print("Wrong/Invalid Choice")

c=input("Do you want to continue? press 'y' to continue: ")

Output:
1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

3 SET - 3
Enter Book Id: 101

Enter Book Name: CS Cracker

Enter Book Price: 410

Do you want to continue? press 'y' to continue: y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

Enter Book Id: 102

Enter Book Name: CS by NCERT

Enter Book Price: 240

Do you want to continue? press 'y' to continue: y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

Enter Book Id: 103

4 SET - 3
Enter Book Name: Maths by R D SHARMA

Enter Book Price: 720

Do you want to continue? press 'y' to continue: y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 3

(103, 'Maths by R D SHARMA', 720.0)

(102, 'CS by NCERT', 240.0)

(101, 'CS Cracker', 410.0)

Do you want to continue? press 'y' to continue: y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 2

Deleted element is: (103, 'Maths by R D SHARMA', 720.0)

Do you want to continue? press 'y' to continue: y

5 SET - 3
1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 3

(102, 'CS by NCERT', 240.0)

(101, 'CS Cracker', 410.0)

Do you want to continue? press 'y' to continue: n

Practical - 2:
(a) Display the average sale of all categories

Select avg(Sale) 'Average Sale' from SALES;

(b) Add a new column named “Brand” of varchar (20) type.

Alter Table SALES Add Column Brand Varchar(20);

(c) Update the profit 4000 of category which profit is NULL

Update SALES Set Profit = 4000 where Profit is NULL;

(d) Display all the details in descending order of Sale.

Select * from SALES Order by Sale Desc;

6 SET - 3

You might also like