0% found this document useful (0 votes)
10 views8 pages

Prince A

The document contains programming assignments for a BTech CSE student, including Python code for class inheritance, SQL concepts like joins and triggers, JavaScript validation for user input, and a basic calculator program. It also explains the differences between Map and Set data structures. Each question is answered with code examples and explanations.

Uploaded by

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

Prince A

The document contains programming assignments for a BTech CSE student, including Python code for class inheritance, SQL concepts like joins and triggers, JavaScript validation for user input, and a basic calculator program. It also explains the differences between Map and Set data structures. Each question is answered with code examples and explanations.

Uploaded by

seleniumjava63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment

Name :- Prince Kumar Gupta

3rd year , Btech CSE

Q1. Write a program to inherit a superclass into a subclass in Python.

class Vehicle:

def __init__(self, brand, model):

self.brand = brand

self.model = model

def display_info(self):

print(f"Brand: {self.brand}, Model: {self.model}")

class Car(Vehicle):

def __init__(self, brand, model, doors):

super().__init__(brand, model)

self.doors = doors

def display_details(self):

self.display_info()

print(f"Number of doors: {self.doors}")

my_car = Car("Toyota", "Camry", 4)

my_car.display_details()

Q2. Write short notes:


(a) Order Join: Order join is not a standard SQL term but could imply ordered results after a join.
Usually handled with ORDER BY.

(b) Self Join: A self join joins a table with itself, typically using aliases.

(c) Index: An index optimizes data retrieval. Example:

Q3. Difference between GROUP BY and HAVING:

• GROUP BY groups rows to aggregate data.

• HAVING filters aggregated data.

Q4. Write a Nested Query with the Use of EXISTS and NOT EXISTS

Scenario: We have two tables:

• students — containing student IDs and names.

• enrollments — containing student IDs and course IDs, showing which students are enrolled
in which courses.

Table Structures:

Using EXISTS: Find students who are enrolled in any course.

Using NOT EXISTS: Find students who are not enrolled in any course.

Q5. write validation on user id and password in js.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>User ID and Password Validation</title>

</head>

<body>

<h2>Login Form</h2>

<form onsubmit="return validateForm()">

<label for="userId">User ID:</label>

<input type="text" id="userId" name="userId" required><br><br>


<label for="password">Password:</label>

<input type="password" id="password" name="password" required><br><br>

<input type="submit" value="Submit">

</form>

<script>

function validateForm() {

const userId = document.getElementById("userId").value;

const password = document.getElementById("password").value;

const userIdPattern = /^[a-zA-Z0-9]{5,12}$/;

const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-


z\d@$!%*?&]{8,}$/;

if (!userIdPattern.test(userId)) {

alert("User ID must be 5 to 12 characters long and can only contain letters and numbers.");

return false;

if (!passwordPattern.test(password)) {

alert("Password must be at least 8 characters long and include uppercase, lowercase, a


number, and a special character.");

return false;

alert("Validation successful!");

return true;

</script>

</body>
</html>

Q6. write validation on radio button and check box in js.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Radio Button and Checkbox Validation</title>

</head>

<body>

<h2>Form Validation</h2>

<form onsubmit="return validateForm()">

<!-- Radio Button Validation -->

<p>Gender:</p>

<input type="radio" name="gender" value="male"> Male

<input type="radio" name="gender" value="female"> Female

<br><br>

<!-- Checkbox Validation -->

<p>Interests:</p>

<input type="checkbox" name="interest" value="sports"> Sports

<input type="checkbox" name="interest" value="music"> Music

<input type="checkbox" name="interest" value="reading"> Reading

<br><br>

<input type="submit" value="Submit">

</form>

<script>

function validateForm() {
const genderSelected = document.querySelector('input[name="gender"]:checked');

const interestSelected = document.querySelectorAll('input[name="interest"]:checked');

if (!genderSelected) {

alert("Please select a gender.");

return false;

if (interestSelected.length === 0) {

alert("Please select at least one interest.");

return false;

alert("Validation successful!");

return true;

</script>

</body>

</html>

Q7. write a program on triggered.

CREATE TRIGGER trg_AuditSalaryUpdate

ON Employees

AFTER UPDATE

AS

BEGIN

DECLARE @OldSalary DECIMAL(10, 2), @NewSalary DECIMAL(10, 2), @EmpID INT;

SELECT @EmpID = INSERTED.EmpID,

@OldSalary = DELETED.Salary,

@NewSalary = INSERTED.Salary

FROM INSERTED
INNER JOIN DELETED ON INSERTED.EmpID = DELETED.EmpID;

IF @OldSalary <> @NewSalary

BEGIN

INSERT INTO Employee_Audit (EmpID, OldSalary, NewSalary)

VALUES (@EmpID, @OldSalary, @NewSalary);

END

END;

Q8. write a program to assign the property of object in js.

const person = {

name: "John",

age: 30,

city: "New York"

};

const employee = {

position: "Developer",

salary: 80000

};

Object.assign(employee, person);

console.log(employee);

Q9. create calculator in python.

def add(x, y):

return x + y
def subtract(x, y):

return x - y

def multiply(x, y):

return x * y

def divide(x, y):

if y != 0:

return x / y

else:

return "Error! Division by zero."

print("Select an operation:")

print("1. Addition (+)")

print("2. Subtraction (-)")

print("3. Multiplication (*)")

print("4. Division (/)")

choice = input("Enter your choice (1/2/3/4): ")

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

if choice == '1':

print(f"{num1} + {num2} = {add(num1, num2)}")

elif choice == '2':

print(f"{num1} - {num2} = {subtract(num1, num2)}")

elif choice == '3':

print(f"{num1} * {num2} = {multiply(num1, num2)}")

elif choice == '4':

print(f"{num1} / {num2} = {divide(num1, num2)}")


else:

print("Invalid choice! Please select a valid operation.")

Q10. what is diff between map and set illustrate with program.

Map:
A Map stores key-value pairs, where both keys and values can be of any data type. It is similar to an
object but more versatile because keys can be objects, functions, or any primitive type.

Set:
A Set stores a collection of unique values. It automatically removes duplicate values and does not
have key-value pairs. It is similar to an array but guarantees uniqueness.

Eg. const set = new Set();

set.add("Apple");

set.add(42);

set.add("Apple"); // Duplicate - ignored

console.log(set); // Set { 'Apple', 42 }

You might also like