Tuesday, March 12, 2024

EMPLOYEE TABLE in ORACLE (RDBMS)

Q.EMPLOYEE TABLE


create table EMP(eid number, ename varchar2(20),age number,salary number,company varchar2(60));

insert into EMP values (1,'raju',30,30000,'TCS');

insert into EMP values (2,'indu',35,40000,'IBM');

insert into EMP values (3,'kalia',40,50000,'CTS');

select *

from EMP;

drop table EMP;


select * 

from EMP

where company='TCS';


select ename 

from EMP

where salary>=40000;


select ename 

from EMP

where age<=35 and salary>=40000;


select ename 

from EMP

where age<=35 or salary>=40000;


select min(salary)

from EMP;


select min(salary) as minimum_salary

from EMP;


select max(salary)

from EMP;


select max(salary) as maximum_salary

from EMP;


select avg(salary)

from EMP;


select avg(salary) as average_salary

from EMP;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

create table EMP(eid number, ename varchar2(20),age number,salary number,company varchar2(60));

insert into EMP values (1,'raju',30,30000,'TCS');

insert into EMP values (2,'indu',35,40000,'IBM');

insert into EMP values (3,'kalia',40,50000,'CTS');

select *

from EMP;

drop table EMP;


select * 

from EMP

where company='TCS';


select ename 

from EMP

where salary>=40000;


select ename 

from EMP

where age<=35 and salary>=40000;


select ename 

from EMP

where age<=35 or salary>=40000;


select min(salary)

from EMP;


select min(salary) as minimum_salary

from EMP;


select max(salary)

from EMP;


select max(salary) as maximum_salary

from EMP;


select avg(salary)

from EMP;


select avg(salary) as average_salary

from EMP;


select ename

from EMP

where salary=(select max(salary)

                from EMP);


select ename

from EMP

where salary=(select min(salary)

                from EMP);


select ename

from EMP

where salary>=(select avg(salary)

                from EMP);


select ename

from EMP

where age=(select max(age)

                from EMP);


select ename

from EMP

where salary>(select salary

                from EMP

                where ename='raju');

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

update EMP set company='TCS'

where eid=1;

select * from EMP;

update EMP set company='IBM'

where eid=2;

select * from EMP;

update EMP set company='CTS'

where eid=3;

select * from EMP;


update EMP set age=age+1;

select * from EMP;

Friday, December 22, 2023

OS-Shortest Job First-SJF Scheduling

 #include<stdio.h>

int main()

{

    int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,totalT=0,pos,temp;

    float avg_wt,avg_tat;

    printf("Enter number of process:");

    scanf("%d",&n);

 

    printf("\nEnter Burst Time:\n");

    for(i=0;i<n;i++)

    {

        printf("p%d:",i+1);

        scanf("%d",&bt[i]);

        p[i]=i+1;

    }

 

    //sorting of burst times

    for(i=0;i<n;i++)

    {

        pos=i;

        for(j=i+1;j<n;j++)

        {

            if(bt[j]<bt[pos])

                pos=j;

        }

 

        temp=bt[i];

        bt[i]=bt[pos];

        bt[pos]=temp;

 

        temp=p[i];

        p[i]=p[pos];

        p[pos]=temp;

    }

 

    wt[0]=0;

 

    //finding the waiting time of all the processes

    for(i=1;i<n;i++)

    {

        wt[i]=0;

        for(j=0;j<i;j++)

             //individual WT by adding BT of all previous completed processes

            wt[i]+=bt[j];

 

        //total waiting time

        total+=wt[i];   

    }

 

    //average waiting time

    avg_wt=(float)total/n;  

 

    printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");

    for(i=0;i<n;i++)

    {

        //turnaround time of individual processes

        tat[i]=bt[i]+wt[i]; 

 

        //total turnaround time

        totalT+=tat[i];      

        printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);

    }

 

    //average turnaround time

    avg_tat=(float)totalT/n;     

    printf("\n\nAverage Waiting Time=%f",avg_wt);

    printf("\nAverage Turnaround Time=%f",avg_tat);

}

OS- First Come First Serve - FCFS Scheduling

 #include <stdio.h>

int main()

{

    int pid[15];

    int bt[15];

    int n,i;

    printf("Enter the number of processes: ");

    scanf("%d",&n);

 

    printf("Enter process id of all the processes: ");

    for(i=0;i<n;i++)

    {

        scanf("%d",&pid[i]);

    }

 

    printf("Enter burst time of all the processes: ");

    for( i=0;i<n;i++)

    {

        scanf("%d",&bt[i]);

    }

 

    int wt[n];

    wt[0]=0;

 

    //for calculating waiting time of each process

    for(i=1; i<n; i++)

    {

        wt[i]= bt[i-1]+ wt[i-1];

    }

 

    printf("Process ID     Burst Time     Waiting Time     TurnAround Time\n");

    float twt=0.0;

    float tat= 0.0;

    for(i=0; i<n; i++)

    {

        printf("%d\t\t", pid[i]);

        printf("%d\t\t", bt[i]);

        printf("%d\t\t", wt[i]);

 

        //calculating and printing turnaround time of each process

        printf("%d\t\t", bt[i]+wt[i]);

        printf("\n");

 

        //for calculating total waiting time

        twt += wt[i];

 

        //for calculating total turnaround time

        tat += (wt[i]+bt[i]);

    }

    float att,awt;

 

    //for calculating average waiting time

    awt = twt/n;

 

    //for calculating average turnaround time

    att = tat/n;

    printf("Avg. waiting time= %f\n",awt);

    printf("Avg. turnaround time= %f",att);

}

Sunday, December 17, 2023

Program run command in Linux(Ubuntu)

 For Cpp

Create- gedit filename.cpp

Compile- g++ filename.cpp

Run- ./a.out


For C

Create- gedit filename.c

Compile- gcc filename.c

Run- ./a.out



For Java

Create- gedit filename.java

Compile- javac filename.java

Run- java filename



For python

Create- gedit filename.py

python3 filename.py  //only interpreter is used in python

Infix to prefix conversion

 ALGORITHM:

STEP 1:

Add " ( " at the beginning of the infix expression and then reverse.

STEP 2:

Push " ) " on to the stack.

STEP 3:

Scan every character and repeat step 4 to step 7 until " ( " is encountered.

STEP 4:

If input is operand add in the output.

STEP 5:

If input is " ) " push into the stack.

STEP 6:

If input is "(" pop all the operators from the stack and add in the output one by one until ")" is popped.

STEP 7:

If input is operator pop all the stack which is higher precedence than input operator .Push input operator into the stack.

STEP 8:

Reverse the output


EXAMPLE:



Infix to postfix conversion

 Step 1: Add " ) " to the end of the infix expression 

Step 2: Push " ( " on to the stack 

Step 3: Repeat until each character in the infix notation is scanned 

            - IF a " ( " is encountered, push it on the stack IF an operand (whether a digit or a character) is                      encountered, add it postfix expression. 

            - IF a " ) " is encountered, then 

                       a. Repeatedly pop from stack and add it to the postfix expression until a " ( " is                                             encountered. 

                       b. Discard the " ( " . That is, remove the " ( " from stack and do not add it to the postfix                              expression. 

           - IF an operator is encountered, then 

                      a. Repeatedly pop from stack and add each operator (popped from the stack) to the postfix expression which has the same precedence or a higher precedence than  0 .

                      b. Push the operator to the stack [END OF IF] 

Step 4: Repeatedly pop from the stack and add it to the postfix expression until the stack is empty 

Step 5: EXIT

Linked list push-pop

 #include<stdio.h>

#include<stdlib.h>


struct node {

    int data;

    struct node* link;

};


struct node* top = NULL;


void push() {

    struct node* temp = (struct node*) malloc(sizeof(struct node));

    printf("Enter a value: ");

    scanf("%d", &temp->data);

    temp->link = top;

    top = temp;

}


void pop() {

    if (top == NULL) {

        printf("Stack underflow\n");

    } else {

        struct node* temp = top;

        top = top->link;

        printf("Popped value = %d\n", temp->data);

        free(temp);

    }

}


void display() {

    if (top == NULL) {

        printf("Empty stack\n");

    } else {

        struct node* temp = top;

        while (temp != NULL) {

            printf("%d ", temp->data);

            temp = temp->link;

        }

        printf("\n");

    }

}


int main() {

    int choice;

    while (1) {

        printf("Enter 1 for push\n");

        printf("Enter 2 for pop\n");

        printf("Enter 3 for display\n");

        printf("Enter 4 for exit\n");

        printf("Enter your choice: ");

        scanf("%d", &choice);

        switch (choice) {

            case 1:

                push();

                break;

            case 2:

                pop();

                break;

            case 3:

                display();

                break;

            case 4:

                printf("Exiting the program\n");

                exit(0);

            default:

                printf("Wrong choice\n");

        }

    }

    return 0;

}

A physicist confesses that the electron is round and that Jesus rose from the dead. (Bengali)

একজন পদার্থবিজ্ঞানী স্বীকার করেন যে ইলেকট্রন গোলাকার এবং যিশু মৃতদের মধ্য থেকে পুনরুত্থিত হয়েছিলেন। আমার নিজের বিশ্বাস প্রমাণ দ্বারা প্রভাব...