Custom Search

Tuesday 17 January 2012

SQL Drop, Update & Delete statement with Syntax & Example


SQL Drop, Update & Delete statement with Syntax & Example 


The Syntax of a SQL DELETE statement is:
DELETE FROM table_name [WHERE condition];
table_name -- the table name which has to be updated.


Example: 
To delete an employee with id 100 from the employee table, the sql delete
query would be like,
DELETE FROM employee WHERE id = 100;
To delete all the rows from the employee table, the query would be like,
DELETE FROM employee;




The Syntax of a SQL UPDATE statement is


UPDATE table_name
SET column_name1 = value1,
column_name2 = value2, ...
[WHERE condition]


Description
table_name - the table name which has to be updated.
column_name1, column_name2.. - the columns that gets changed.
value1, value2... - are the new values.


Example: 
To update the location of an employee, the sql update query would be
like,
UPDATE employee
SET location ='Mysore'
WHERE id = 101;



Syntax to drop a sql table structure:
DROP TABLE table_name;


Example: 
To drop the table employee, the query would be like
DROP TABLE employee;


Write a PL/SQL Block that uses implicit cursor attributes with Discription


Write a PL/SQL Block that uses implicit cursor attributes with Discription




DECLARE var_rows number(5);
BEGIN
UPDATE employee
SET salary = salary + 1000;
IF SQL%NOTFOUND THEN
dbms_output.put_line('None of the salaries where updated');
ELSIF SQL%FOUND THEN
var_rows := SQL%ROWCOUNT;
dbms_output.put_line('Salaries for ' || var_rows || 'employees are
updated');
END IF;
END;


Description 

In the above PL/SQL Block, the salaries of all the employees in the ‘employee’ table are updated. If none of the employee’s salary are updated we get a message 'None of the salaries where updated'. Else we get a message like for example, 'Salaries for 1000 employees are updated' if there are 1000 rows in ‘employee’ table.

Sunday 15 January 2012

WAP, Write a C or C++ Program to compute real roots of quadratic equation with output

WAP, Write a C or C++ Program to compute real roots of quadratic equation with output


Program
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,c,d,r1, r2;
clrscr();
printf("Enter the value of a,b,c:\n");
scanf("%f %f %f ", &a, &b, %c);
d= b*b -4*a*c;
printf ("discriminant is %f", d);
if(d<0)
{
printf("\n Roots are imaginary");
}
else
{
r1= (-b+ sqrt(d))/(2*a);
r2= (-b- sqrt(d))/2*a);
printf ("\n %f  %f ", r1, r2);
}
getch();
}


Output
Enter the values of a,b,c:
2
5
2
discrimant is: 9.0
-0.50 -2.0



Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

WAP, Write a Program to find number of & sum of all integers greater than 100 & less than 200 that are divisible by 7 with output

WAP, Write a Program  to find number of & sum of all integers greater than 100 & less than 200 that are divisible by 7 with output

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i, count=0, sum=0;
clrscr();
for (i=101;  i<200; i++)
{
if (i%7 = =0)
{
count = count + 1;
sum=sum + i;
}
}
printf("Sum is:%d\n", sum);
scanf("Count is:%d", count);
getch();
}


Output
Sum is:  2107
count is: 14



Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


WAP, Write a C or C++ Program to read a four digit integer & print sum of the digit with output

WAP, Write a C or C++ Program to read a four digit integer & print sum of the digit with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum=0;
clrscr();
printf("Enter the number");
scanf ("%d", &a);
while(a>0)
(
b=a%10;
a=a%10;
sum=sum + b;
}
printf("sum is: %d", sum);
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

WAP, Write a program to calculate the total marks & percentage of given five subject & find whether he/she is pass or not with output

WAP, Write a program to calculate the total marks & percentage of given five subject & find whether he/she is pass or not with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,m,f;
clrscr();
printf ("Enter the marks:");
scanf ("\n %d %d %d %d %d ", &a, &b, &c, &d, &e);
f=(a+b+c+d+e)/5;
printf("Avg. is :%d", f);
printf ("\n Percentage is:%d\n", f);
if(f>=66)
{
printf("Distinction");
}
else if (f<=66 && f>60)
{
printf("First Class");
}
else if(f<=60 && f>50)
{
printf("Second Class");
}
else if(f<=50 && f>40)
{
printf("Pass");
}
else
{
printf("Fail");
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

Click here to check the output

WAP, Write a C or C++ Program that reads a floating point number and displays the right most digit of integral part of the number with output

WAP, Write a C or C++ Program that reads a floating point number and displays the right most digit of integral part of the number with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a;
int ans,b;
printf("Enter the value:");
scanf("%f", &a);
b=a;
ans=b%10;
printf("ans is %d", ans);
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

Friday 13 January 2012

WAP, Write a C or C++ Program to swap the value of two variables using temporary variable with output using temporary variable

WAP, Write a C or C++ Program to swap the value of two variables using temporary variable with output using temporary variable 


Program
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr()
{
int a,b, temp;
printf("Enter the value of a:");
scanf("%d", &a);
printf("Enter the value of b:");
scanf("%d", &b);
temp=a;
a=b;
b=temp;
printf("\n Value of a after swap is :%d, a");
printf("\n Value of b after swap is: %d, b");
getch();

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

WAP, Write a C or C++ program to find biggest number from the entered 3 numbers with output using else if statement

WAP, Write a C or C++ program to find biggest number from the entered 3 numbers with output using else if statement


Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the three values");
scanf("%d %d %d, &a, &b, &c);
if(a>b && a>c)
{
printf ("%d", a);
}
else if (b>c && b>a)
{
printf("%d", b);
}
else if (c>a && c>b)
{
printf("%d", c);
}
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

Click here to check the output

WAP, Write a C or C++ Program to convert the given temperature in Fahrenheit to Celsius using the conversion formula with output, WAP for temperature converter

WAP, Write a C or C++ Program to convert the given temperature in Fahrenheit to Celsius using the conversion formula with output, WAP for temperature converter 


Program
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
clrscr();
printf("Enter the temperature in Fahrenheit");
scanf ("%d", &f)
c= (f-32)*1.8
printf ("The temperature in Celsius is:");
printf ("%f", c);
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement. 


Click here to check the output

Write a program in C or C++ to perform all arithmetic operation (Using two variables) that is subtraction(-), addition(+), division(/), multiplication(*) & modulus(%) with Output

Write a program in C or C++ to perform all arithmetic operation (Using two variables) that is subtraction(-), addition(+), division(/), multiplication(*) & modulus(%) with Output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g
clrscr();
printf ("Enter first number\n");
scanf ("%d", &a);
printf("Enter second number");
scanf ("%d", &b);
c=a+b;
printf("Addition is :%d", c);
d=a-b;
printf("Subtraction is :%d", d);
e=a*b;
printf("Multiplication is :%d", e);
f=a/b;
printf("Division is:%d ", f);
g=a%b;
printf("/n"Mod is : %d ", g);
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

WAP to find square of a given number, Write a C or C++ Program to find the square of a given number

WAP to find square of a given number, Write a C or C++ Program to find the square of a given number with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
clrscr();
printf("enter the number");
scanf("%f", &a);
b=a*a;
printf ("\n value is :");
printf ("%f", b);
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

WAP program to find area of the circle, Write a C or C++ program to find area of the circle using math.h function & defining constant

WAP program to find area of the circle,  Write a C or C++ program to find area of the circle using math.h function & defining constant with output


Program
#include<math.h>
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
float a,b;
clrscr();
printf("enter the radius of the circle");
scanf ("%f", &a);
b=pi*a*a;
printf("area is");
printf("%f", b);
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

Write a C or C++ Programme to display your full name, forst name, middle name & Last name

Write a C or C++ Programme to display your full name, first name, middle name & Last name with output


Program
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("First Name, Middle Name,  Last Name\n");
getch();
}


Output
John Lory Clinton 


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

WAP a program to count the number of words present in a text file named“PARA.TXT”. Assume that each word is separated by a single blank/space character and no blanks/spaces in the beginning and end of the file.

WAP a program to count the number of words present in a text file named“PARA.TXT”. Assume that each word is separated by a single blank/space character and no blanks/spaces in the beginning and end of the file.


#include<iostream.h>
#include<conio.h>
void main()
{
int total;
total=WordsCount( );
Cout<<"Total number of words are:"<<total;
getch();
}

int WordsCount( )
{ clrscr( );
ifstream fin("PARA.TXT",ios::in);
char ch;
int Words=1;
if(!fin)
{ cout<<”No words at all in the file”;
exit(0);
}
while(fin)
{fin.get(ch);
if(ch= =’ ‘)
Words++;
}
return words;
}

Monday 9 January 2012

Types of Errors in C or C++, Runtime Error, Logical Error, Syntax Error, Explain type of Errors in C or C++ with Example

Types of Errors in C or C++, Runtime Error, Logical Error, Syntax Error, Explain type of Errors in C or C++ with Example


Errors in C are catagorised in 3 Parts i.e Syntax error, Logical Error & Runtime Error. I willl explain you all of these in detail

1.Syntax Error
This type of error occurs basically due to incorrect statement formation, which are not according to the format or rules of the c programming language.

For eq.

Incorrect
#include<iostream.h>
#include<conio.h>
void main()
(
int number,
char name,
getch();
)

Correct
#include<iostream.h>
#include<conio.h>
void main()
{
int number;
char name;
getch();
}

2.Logical Errors:-
This type of error occurs basically when there is error in the concept or logic of the program written.
For eg if i am making a c program to form of calculator and in the place of adding number i have use "+" instead of "-".
i such a error occurs than the whole program produces wrong result.

3.Runtime error:-
Runtime error occurs basically during the runtime in this case case our program is compiled with no errors but when start executing it it shows errors.
For eg.
#include<iostream.h>
#include<conio.h>
void main()
{
int n,m,d;
printf("Enter the value of m & n", &m &n);
d=m/n
printf("answer is", d)
getch();
}

in the above program if i enter the value of n as 0 than the output produced will be wrong.

Runtime error may also occur due to logarithm of a negative number or find the square root of a negative integer.

Laptops