STACK related questions
1. Question:
Write a menu-driven program that uses a dictionary to store StudentName and
Marks as key-value pairs for a group of students. Implement separate user-defined
functions to:
Push the keys (names of students) into a stack if their marks are greater
than or equal to 50.
Pop an element from the stack and display the name along with the
remaining number of elements in the stack.
Display all the elements.
Exit the program.
2. Question:
Create a menu-driven program that uses a dictionary containing ProductName
and Price as key-value pairs for a list of products. Use separate functions to
perform the following:
Push the keys (product names) into a stack if their price is less than 500.
Pop an item from the stack, display the product name, and show the
number of elements left in the stack.
Display all the elements.
Exit the program.
3. Question:
Design a program that manages a dictionary with BookTitle and Number of
Pages as key-value pairs for a library. Write user-defined functions to:
Push the keys (book titles) into a stack if the number of pages is less than
300.
Pop an element from the stack, display the book title, and show the count
of remaining elements in the stack.
Exit the program.
4. Question:
Write a menu-driven program that handles a dictionary storing CityName and
Population as key-value pairs. Implement the following operations:
Push the city names into a stack if the population is less than 1,00,000.
Pop an element from the stack, display the book title, and show the count
of remaining elements in the stack.
Exit the program.
5. Question:
Create a dictionary that stores ItemName and Quantity as key-value pairs for a
grocery inventory. Write a menu-driven program with user-defined functions to:
Push item names into a stack if the quantity is less than or equal to 50.
Pop an item from the stack, display the item name, and show the
remaining count of elements in the stack.
Exit the program.
6. Question:
Design a menu-driven program to manage a dictionary with CourseName and
Fees as key-value pairs. Implement the following operations with user-defined
functions:
Push course names into a stack if their fees are less than 50,000.
Pop a course name from the stack, display it, and show the number of
elements left in the stack.
Exit the program.
7. Question:
Create a program to manage a dictionary containing MovieTitle and Rating as
key-value pairs. Write user-defined functions to:
Push movie titles into a stack where the rating is greater than or equal to
4.0.
Pop a movie title from the stack, display it, and indicate how many titles
remain in the stack.
Exit the program.
8. Question:
Develop a menu-driven program that uses a dictionary to store EmployeeID and
HoursWorked as key-value pairs. Implement the following functionalities:
Push employee IDs into a stack if their hours worked are less than 40.
Pop an employee ID from the stack, display it, and show the remaining
elements in the stack.
Exit the program.
9. Question:
Write a menu-driven program for a dictionary that stores ProjectName and
CompletionTime (in days) as key-value pairs. Use user-defined functions to:
Push project names into a stack if the completion time is less than or equal
to 30 days.
Pop a project name from the stack, display it, and print the count of
remaining elements in the stack.
Exit the program.
10. Question:
Write a menu-driven program using a dictionary that contains CarModel and
Mileage as key-value pairs. Use separate functions to:
Push the keys (car models) into a stack where the mileage is greater than
or equal to 20.
Pop a car model from the stack, display its name, and print the number of
remaining elements in the stack.
Display all the elements present in the stack.
Exit the program.
Text files related questions
1. Question:
Write a menu-driven program to:
Create a text file and write user input into it.
Read the file and display its contents with all vowels replaced by *.
Count and display the number of occurrences of the words "the" and "is"
(ignoring case).
2. Question:
Design a menu-driven program to:
Create a text file and allow the user to input multiple lines of text.
Display the contents of the file in reverse order (line by line).
Count and display the occurrences of the words "on" and "of" (ignoring
case).
For Create a text file and allow the user to input multiple lines of text –
3. Question
Create a menu-driven program to:
Create a text file and accept input from the user to write into the file.
Read the file and display its contents with all spaces replaced by Comma (,).
Count and display the number of occurrences of the word "and" (ignoring
case).
Exit the program.
4. Question:
Create a menu-driven program to:
Create a text file and accept input from the user to write into the file.
Read the file and display its contents with all spaces replaced by comma(,).
Count and display the number of occurrences of the word "and" (ignoring
case).
5. Question:
Write a program with a menu to:
Create a new text file and add data to it.
Display the file's content, converting all alphabetic characters to lowercase.
Count and display the occurrences of the words "in" and "it" in the file
(ignoring case).
6. Question:
Develop a menu-driven program to:
Create a text file and write lines of text as entered by the user.
Read the file and display its contents with each word capitalized.
Count and display the occurrences of the words "for" and "with" in the file
(ignoring case).
7. Question:
Create a program with the following menu options:
Create a text file and store user input in it.
Read the file and display its contents with every alternate character
removed.
Count and display the occurrences of the words "at" and "by" in the file
(ignoring case).
8. Question:
Design a menu-driven program to:
Create and save a text file with user-provided data.
Read the file and display its content while replacing all occurrences of "a"
with "@" and "e" with "3".
Count and display the occurrences of the words "to" and "be" (ignoring
case).
Binary Files related questions
1. Write a menu-driven program to:
o Create a binary file to store customer details (name, ID, email)
where the email must contain '@'.
o Display all valid customer records.
2. Write a program to:
o Create a binary file storing book details (title, author, price), where
price is below $500.
o Count and display the number of books stored in the file.
3. Write a menu-driven program to:
o Create a binary file for storing vehicle details (type, registration
number, owner’s name).
o Provide an option to search for a vehicle by registration number and
display its details.
4. Write a menu-driven program to:
o Store employee details (name, department, salary) in a binary file,
allowing only salaries above Rs 50,000.
o View all employees whose salary exceeds Rs 70,000.
5. Write a program to:
o Create a binary file with student details (name, roll number, and
marks).
o Add an option to delete a student record by roll number.
6. Write a Python program to:
o Create a binary file with items (item name, item ID, price).
o Allow the user to update the price of a specific item by entering its
ID.
7. Write a program to:
o Store train reservation details (train name, train number, and
departure time) in a binary file.
o Add an option to modify the departure time for a specific train
number.
8. Write a menu-driven program to:
o Create a binary file containing product details (product ID, name,
price).
o Search for a product by name and display its details.
o Delete a product record by product ID.
9. Write a program to:
o Create a binary file to store students' names and grades, accepting
only grades 'A', 'B', and 'C'.
o Display all records of students with grade 'A'.
10. Write a menu-driven program to:
o Create a binary file storing mobile phone details (brand, model,
price) where the price must be above $100.
o Search for all phones of a particular brand and display them.
11. Write a Python program to:
o Create a binary file to store transaction details (transaction ID,
amount, transaction type: "debit" or "credit").
o Display all transactions and calculate the net balance.
12. Write a menu-driven program to:
o Create a binary file storing details of sold items (item name, price,
quantity sold).
o Display all records and calculate the total sales value.
13. Write a program to:
o Store customer details (name, customer ID, total purchases) in a
binary file.
o Display all customers whose total purchases exceed Rs 1,000.
14. Write a menu-driven program to:
o Store user details (username, password, and email) in a binary file.
o Allow a user to log in by checking their username and password
against the file data.
15. Write a Python program to:
o Create a binary file with hospital patient details (name, patient ID,
disease, and age).
o Provide options to view all records, search by patient ID, and display
all patients suffering from a specific disease.
CSV file related questions
1. Write a menu-driven program to:
o Create a CSV file to store employee details (ID, name, department,
salary).
o Display all records from the file.
2. Write a program to:
o Create a CSV file storing student details (roll number, name, marks).
o Display all students who scored above 75 marks.
3. Write a menu-driven program to:
o Create a CSV file to store book details (title, author, price).
o Display all records where the price is less than $500.
4. Write a Python program to:
o Store sales data (product ID, product name, price, quantity sold) in a
CSV file.
o Calculate and display the total sales value for each product.
5. Write a menu-driven program to:
o Create a CSV file storing city data (city name, state, population).
o Display cities with a population above 1,000,000.
6. Write a program to:
o Create a CSV file storing vehicle details (vehicle number, owner,
type, price).
o Search and display details of a vehicle by its number.
7. Write a menu-driven program to:
o Store movie details (title, director, release year, rating) in a CSV file.
o Display all movies released after a given year.
8. Write a Python program to:
o Create a CSV file storing employee details (ID, name, age,
department).
o Display all employees from a specific department.
9. Write a program to:
o Store order details (order ID, customer name, amount, order status)
in a CSV file.
o Display all orders with status "Delivered."
10. Write a Python program to:
Store e-commerce order details (order ID, product name, price, quantity,
status) in a CSV file.
Calculate and display the total revenue generated from completed orders.
11. Write a menu-driven program to:
Store event details (event ID, name, date, location) in a CSV file.
Allow the user to search for events by location and display them.
12. Write a program to:
Store student exam scores (roll number, name, subject, score) in a CSV file.
Display the average score of students for input subject.
SQL Related Questions
(Below you can find 4 different set of tables and questions for practise)
Consider the following tables:
CUSTOMER
CustomerID FirstName LastName PhoneNumber City
New
1 John Doe 555-123-4567
York
2 Jane Smith 555-987-6543 Texas
3 Emily Davis 555-456-7890 Chicago
4 Michael Brown 555-321-4321 Houston
ORDERS
OrderID CustomerID OrderDate OrderAmount Status
101 1 20-12-2023 250 Delivered
102 2 21-12-2023 150.5 Shipped
103 3 22-12-2023 300.75 Shipped
104 1 23-12-2023 175.2 Delivered
105 2 24-12-2023 400 Cancelled
Write the SQL command and its output for the following questions using the tables
defined above:
a) To display all the details in the descending order of city of those customers whose
Firstname contains the letter “A”.
b) To display Firstname and respective status for OrderAmount 250 and above.
c) To display Status wise maximum OrderAmount from Orders table.
d) Add a new field to store email id of customers. (Field - Email, Datatype – String)
Consider the following tables:
AUTHORS
AuthorID FirstName LastName Country
1 George Orwell UK
2 J.K. Rowling UK
3 Mark Twain USA
4 Jane Austen UK
BOOK
BookID AuthorID Title Genre Price
101 1 1984 NULL 12000
102 1 Animal Farm Satire 5700
103 2 Harry Potter Fantasy 1300
Adventures of Huckleberry
104 3 Fantasy 11000
Finn
Write the SQL command and its output for the following questions using the tables
defined above:
a. To display Title, Genre and Price in the descending order of Price, of those Books
where Genre is not null.
b. To display Genre wise count of Books.
c. To display all the contents from Books table along with Firstname of Authors table
where the Firstname ends with letter ‘E’.
d. Change the Genre to Adventure for BookId 104.
Consider the following tables:
DEPARTMENT
DepartmentID DepartmentName Location
Human New
1
Resources York
San
2 IT
Francisco
3 Finance NULL
Los
4 Marketing
Angeles
EMPLOYEE
EmployeeID DepartmentID EName HireDate Salary
15-06-
101 1 Sarah 100000
2018
22-07-
102 2 John 200000
2020
22-07-
103 1 Sharol 175000
2020
05-09-
104 2 Emily 135000
2019
01-01-
105 4 James 90000
2022
Write the SQL command and its output for the following questions using the tables
defined above:
a. To display Ename, Hiredate and salary of Employees with Hiredate between 05-09-
2019 and 22-07-2020.
b. To display DepartmentID wise average Salary having average of salary below
100000.
c. To display all the contents from Employee table along with DepartmentName of
Department table whose Ename begins with letter ‘S’.
d. Delete the records from Department Table where Location is NULL.
Consider the following tables:
PRODUCT
ID PNAME MANUFACTURER MFGDATE PRICE
PC01 Personal ABC 11-JAN- 35000
Computer 2016
LC01 Laptop ABC 19-DEC- 55000
2016
PC02 Personal ABCQ 15-FEB- 32000
Computer 2017
PC03 Personal COMP 21-JAN- 37000
Computer 2017
LC02 Laptop PQR 10-JAN- 57000
2018
CUSTOMER
CID CNAME CITY ID
01 N Roy Delhi LC02
02 H Singh Mumbai PC02
03 R Pandey Delhi PC03
04 C Sharma Delhi LC02
05 Abhijith Bangalore PC01
Write the SQL command and its output for the following questions using the tables
defined above:
i) To display Pname and manufacturer of those items, whose id is either PC01 or
LC02 in descending order of Pname.
ii) To display citywise count of Customers.
iii) To display all the contents from customer table along with Pname of Product table
where the Pname contains letter ‘C’.
iv) Increase the Price by 5% for the records with manufacturer ABC