OneCompiler

Aaa

121
  1. Write an HTML code: To Design the Student Registration form for applying MCA CET. Consider all aspects and do the necessary validations for it.
    Ans:-
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Student Registration Form</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; padding: 20px; } form { max-width: 600px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } h2 { text-align: center; } label { display: block; margin-bottom: 5px; } input[type="text"], input[type="email"], input[type="tel"], select { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; } input[type="submit"] { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } input[type="submit"]:hover { background-color: #45a049; } .error { color: red; font-size: 0.8em; margin-top: 5px; } </style> </head> <body> <form id="registrationForm" onsubmit="return validateForm()"> <h2>Student Registration Form</h2> <label for="fullName">Full Name:</label> <input type="text" id="fullName" name="fullName" required> <label for="email">Email:</label> <input type="email" id="email" name="email" required> <label for="phoneNumber">Phone Number:</label> <input type="tel" id="phoneNumber" name="phoneNumber" pattern="[0-9]{10}" required> <label for="address">Address:</label> <input type="text" id="address" name="address" required> <label for="qualification">Qualification:</label> <select id="qualification" name="qualification" required> <option value="">Select</option> <option value="Bachelor's Degree">Bachelor's Degree</option> <option value="Master's Degree">Master's Degree</option> <option value="Diploma">Diploma</option> <option value="Others">Others</option> </select> <label for="percentage">Percentage/CGPA:</label> <input type="text" id="percentage" name="percentage" required> <input type="submit" value="Submit"> </form>
<script>
    function validateForm() {
        var fullName = document.getElementById("fullName").value;
        var email = document.getElementById("email").value;
        var phoneNumber = document.getElementById("phoneNumber").value;
        var address = document.getElementById("address").value;
        var qualification = document.getElementById("qualification").value;
        var percentage = document.getElementById("percentage").value;

        if (fullName.trim() === '' || email.trim() === '' || phoneNumber.trim() === '' || address.trim() === '' || qualification.trim() === '' || percentage.trim() === '') {
            alert("Please fill in all fields.");
            return false;
        }

        if (!validatePhoneNumber(phoneNumber)) {
            alert("Please enter a valid phone number.");
            return false;
        }

        // Additional validation rules can be added here

        return true;
    }

    function validatePhoneNumber(phoneNumber) {
        var phoneRegex = /^[0-9]{10}$/;
        return phoneRegex.test(phoneNumber);
    }
</script>
</body> </html> __________________________________________________________________
  1. Write HTML code for following:
    a) Create Menu for Video Songs by artists category (Any 3
    Artist) and display relevant video of that artist on web page
    b) Create Menu for Audio Songs by artists category (Any 3
    Artist) and display relevant Audio of that artist on web page

Ans:-

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Music Library</title> </head> <body> <h1>Welcome to the Music Library</h1>
<h2>Video Songs</h2>
<ul>
    <li><a href="#" onclick="showVideos('Artist1')">Artist 1</a></li>
    <li><a href="#" onclick="showVideos('Artist2')">Artist 2</a></li>
    <li><a href="#" onclick="showVideos('Artist3')">Artist 3</a></li>
</ul>

<div id="videoContainer">
    <!-- Videos will be displayed here -->
</div>

<h2>Audio Songs</h2>
<ul>
    <li><a href="#" onclick="showAudios('Artist1')">Artist 1</a></li>
    <li><a href="#" onclick="showAudios('Artist2')">Artist 2</a></li>
    <li><a href="#" onclick="showAudios('Artist3')">Artist 3</a></li>
</ul>

<div id="audioContainer">
    <!-- Audios will be displayed here -->
</div>

<script>
    function showVideos(artist) {
        // Clear previous content
        document.getElementById("videoContainer").innerHTML = "";

        // Retrieve and display relevant videos for the selected artist
        if (artist === 'Artist1') {
            document.getElementById("videoContainer").innerHTML = "<iframe width='560' height='315' src='https://www.youtube.com/embed/VIDEO_ID_HERE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
        } else if (artist === 'Artist2') {
            document.getElementById("videoContainer").innerHTML = "<iframe width='560' height='315' src='https://www.youtube.com/embed/VIDEO_ID_HERE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
        } else if (artist === 'Artist3') {
            document.getElementById("videoContainer").innerHTML = "<iframe width='560' height='315' src='https://www.youtube.com/embed/VIDEO_ID_HERE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>";
        }
    }

    function showAudios(artist) {
        // Clear previous content
        document.getElementById("audioContainer").innerHTML = "";

        // Retrieve and display relevant audios for the selected artist
        if (artist === 'Artist1') {
            document.getElementById("audioContainer").innerHTML = "<audio controls><source src='audio/artist1_song.mp3' type='audio/mpeg'>Your browser does not support the audio element.</audio>";
        } else if (artist === 'Artist2') {
            document.getElementById("audioContainer").innerHTML = "<audio controls><source src='audio/artist2_song.mp3' type='audio/mpeg'>Your browser does not support the audio element.</audio>";
        } else if (artist === 'Artist3') {
            document.getElementById("audioContainer").innerHTML = "<audio controls><source src='audio/artist3_song.mp3' type='audio/mpeg'>Your browser does not support the audio element.</audio>";
        }
    }
</script>
</body> </html> ______________________________________________- 3. Create Website Layout in following way: Logo Header Menu1submenu1 Submenu2 Submenu3 Menu2submenu1 Submenu2 Submenu3 Contents IMG IMG IMG IMG IMG IMG
IMG 

IMG
IMG Contents

Section Section
Section Section
Section Section

Section 

Section
Section

Ans:-

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Website Layout</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; } header { background-color: #333; color: #fff; padding: 10px 20px; text-align: center; } #logo { float: left; } nav { float: right; } nav ul { list-style-type: none; margin: 0; padding: 0; } nav ul li { display: inline; margin-right: 20px; } nav ul li ul { display: none; position: absolute; background-color: #f9f9f9; padding: 10px; z-index: 1; } nav ul li:hover ul { display: block; } section { padding: 20px; margin: 20px; border: 1px solid #ccc; float: left; width: 30%; box-sizing: border-box; } .contents { clear: both; padding: 20px; } .contents img { display: block; margin: 10px auto; } </style> </head> <body> <header> <div id="logo">Logo</div> <nav> <ul> <li><a href="#">Menu1</a> <ul> <li><a href="#">Submenu1</a></li> <li><a href="#">Submenu2</a></li> <li><a href="#">Submenu3</a></li> </ul> </li> <li><a href="#">Menu2</a> <ul> <li><a href="#">Submenu1</a></li> <li><a href="#">Submenu2</a></li> <li><a href="#">Submenu3</a></li> </ul> </li> </ul> </nav> </header>
<section>
    <h2>Contents</h2>
    <div class="contents">
        <img src="image1.jpg" alt="Image 1">
        <img src="image2.jpg" alt="Image 2">
        <img src="image3.jpg" alt="Image 3">
    </div>
</section>
<section>
    <h2>Contents</h2>
    <div class="contents">
        <img src="image4.jpg" alt="Image 4">
        <img src="image5.jpg" alt="Image 5">
        <img src="image6.jpg" alt="Image 6">
    </div>
</section>
<section>
    <h2>Contents</h2>
    <div class="contents">
        <img src="image7.jpg" alt="Image 7">
        <img src="image8.jpg" alt="Image 8">
        <img src="image9.jpg" alt="Image 9">
    </div>
</section>

<section>
    <h2>Contents</h2>
    <div class="contents">
        <img src="image10.jpg" alt="Image 10">
        <img src="image11.jpg" alt="Image 11">
        <img src="image12.jpg" alt="Image 12">
    </div>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
<section>
    <h2>Section</h2>
    <p>Some text...</p>
</section>
</body> </html> _________________________________________________________ 4. Write a PHP script to display employees belongs to Sales department and salary is in between 50000 to 90000 and store found records into another table.

Ans:-

<?php // Assuming you have a database connection established $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "your_database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Fetch employees from Sales department with salary between 50000 and 90000 $sql = "SELECT * FROM employees WHERE department = 'Sales' AND salary BETWEEN 50000 AND 90000"; $result = $conn->query($sql); if ($result->num_rows > 0) { // If there are matching records, store them in another table $insert_sql = "INSERT INTO sales_employees (id, name, department, salary) VALUES "; while ($row = $result->fetch_assoc()) { $insert_sql .= "(" . $row['id'] . ", '" . $row['name'] . "', '" . $row['department'] . "', " . $row['salary'] . "),"; } // Remove the trailing comma from the SQL statement $insert_sql = rtrim($insert_sql, ','); if ($conn->query($insert_sql) === TRUE) { echo "Records inserted successfully."; } else { echo "Error: " . $insert_sql . "<br>" . $conn->error; } } else { echo "No matching records found."; } // Close connection $conn->close(); ?>
  1. Write a PHP script to design Employee Registration form. Insert 5 records in database and display all the inserted records on new page.
    Ans:-
    employee_registration.php (Employee Registration Form)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employee Registration Form</title> </head> <body> <h2>Employee Registration Form</h2> <form action="insert_employee.php" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name" required><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email" required><br><br> <label for="department">Department:</label> <input type="text" id="department" name="department" required><br><br> <label for="salary">Salary:</label> <input type="text" id="salary" name="salary" required><br><br> <input type="submit" value="Submit"> </form> </body> </html>

insert_employee.php (Script to Insert Records)

<?php // Assuming you have a database connection established $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "your_database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Insert employee record $name = $_POST['name']; $email = $_POST['email']; $department = $_POST['department']; $salary = $_POST['salary']; $sql = "INSERT INTO employees (name, email, department, salary) VALUES ('$name', '$email', '$department', '$salary')"; if ($conn->query($sql) === TRUE) { echo "Record inserted successfully. <br>"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } // Close connection $conn->close(); ?>

display_employees.php (Display Inserted Records)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employee Records</title> </head> <body> <h2>Employee Records</h2> <table border="1"> <tr> <th>Name</th> <th>Email</th> <th>Department</th> <th>Salary</th> </tr> <?php // Assuming you have a database connection established $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "your_database";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Fetch and display employee records
    $sql = "SELECT * FROM employees";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            echo "<tr>";
            echo "<td>" . $row['name'] . "</td>";
            echo "<td>" . $row['email'] . "</td>";
            echo "<td>" . $row['department'] . "</td>";
            echo "<td>" . $row['salary'] . "</td>";
            echo "</tr>";
        }
    } else {
        echo "No records found.";
    }

    // Close connection
    $conn->close();
    ?>
</table>
</body> </html> ______________________________________________________ 6. Write a program to show current date and time using user defined module in Node JS Ans:- date_time_module.js (User-defined module)

// Define a function to get current date and time
exports.getCurrentDateTime = function() {
const currentDate = new Date();
const dateOptions = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const timeOptions = { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true };
const formattedDate = currentDate.toLocaleDateString('en-US', dateOptions);
const formattedTime = currentDate.toLocaleTimeString('en-US', timeOptions);
return Current Date and Time: ${formattedDate} ${formattedTime};
};

main_script.js (Main script)

// Import the user-defined module
const dateTimeModule = require('./date_time_module');

// Call the function from the imported module to get current date and time
const currentDateTime = dateTimeModule.getCurrentDateTime();

// Display the current date and time
console.log(currentDateTime);


  1. Write a PHP program to store the username in a cookie and check whether the user has successfully logged in or not.
    Ans:-
    index.php (Login Form)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login</title> </head> <body> <h2>Login Form</h2> <form action="login.php" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username" required><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password" required><br><br> <input type="submit" value="Login"> </form> </body> </html>

login.php (Processing Login)

<?php // Check if username and password are correct $username = $_POST['username']; $password = $_POST['password']; // You can replace this with your actual login logic $validUsername = "user"; $validPassword = "password"; if ($username === $validUsername && $password === $validPassword) { // Set cookie if login is successful setcookie("username", $username, time() + 3600, "/"); // Cookie expires in 1 hour echo "Login successful. Welcome, $username!"; } else { echo "Invalid username or password."; } ?>

profile.php (Display Profile)

<?php // Check if the user is logged in if(isset($_COOKIE['username'])) { $username = $_COOKIE['username']; echo "Welcome, $username!"; } else { header("Location: index.php"); // Redirect to login page if not logged in exit; } ?>
  1. Write a program in NodeJS to perform file CRUD operations by using fs module.
    Ans:-
    const fs = require('fs');

// Create a new file
fs.writeFile('example.txt', 'Hello, World!', (err) => {
if (err) throw err;
console.log('File created successfully!');

// Read the contents of the file
fs.readFile('example.txt', 'utf8', (err, data) => {
    if (err) throw err;
    console.log('File content:', data);
    
    // Update the file content
    fs.appendFile('example.txt', '\nThis is a new line.', (err) => {
        if (err) throw err;
        console.log('File updated successfully!');
        
        // Read the updated contents of the file
        fs.readFile('example.txt', 'utf8', (err, newData) => {
            if (err) throw err;
            console.log('Updated file content:', newData);
            
            // Delete the file
            fs.unlink('example.txt', (err) => {
                if (err) throw err;
                console.log('File deleted successfully!');
            });
        });
    });
});

});


8.Create an Angular program which will demonstrate the use of ngswitch directive
Ans:-
app.component.ts:

import { Component } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public selectedOption: string = '';

constructor() { }

setSelectedOption(option: string) {
this.selectedOption = option;
}
}

app.component.html:

<div> <h2>Choose an option:</h2> <select (change)="setSelectedOption($event.target.value)"> <option value="">Select an option</option> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3">Option 3</option> </select> <div [ngSwitch]="selectedOption"> <p *ngSwitchCase="'option1'">Option 1 is selected.</p> <p *ngSwitchCase="'option2'">Option 2 is selected.</p> <p *ngSwitchCase="'option3'">Option 3 is selected.</p> <p *ngSwitchDefault>No option selected.</p> </div> </div>