0% found this document useful (0 votes)
124 views31 pages

Itc All Asigment

The document shows SQL commands used to create a database and table called exercise_logss. It inserts sample data, performs updates, deletes and selects on the table. It alters the table by adding, dropping and renaming columns. C code snippets are also shown to demonstrate basic C programming concepts like input/output, if-else conditions, loops and functions.

Uploaded by

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

Itc All Asigment

The document shows SQL commands used to create a database and table called exercise_logss. It inserts sample data, performs updates, deletes and selects on the table. It alters the table by adding, dropping and renaming columns. C code snippets are also shown to demonstrate basic C programming concepts like input/output, if-else conditions, loops and functions.

Uploaded by

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

LAB 6

create database exercise

use exercise

create table exercise_logss


(
id int primary key,
type varchar (30),
minutes int,
calories int,
heart_rate int
)
select * from exercise_logss

insert into exercise_logss (id, type, minutes, calories, heart_rate)


values (1, 'swiming', 40, 300, 120),
(2, 'Biking', 30, 200, 110),
(3, 'racing', 50, 500, 100),
(4, 'swiming', 30, 150, 90),
(5, 'racing', 50, 500, 100),
(6, 'racing', 50, 500, 100)
truncate table exercise_logss

alter table exercise_logss add name varchar (50), blood_pressure int

alter table exercise_logss drop column blood_pressure

select * from exercise_logss where minutes=30

Update exercise_logss
set
calories = 190,
heart_rate = 80
where
id = 3

select * from exercise_logss


truncate table exercise_logss

alter table exercise_logss drop column id,


type,
minutes,
calories,
heart_rate,
blood_pressure

alter table exercise_logss drop column name


alter table exercise_logss drop cloumn heart_rate
ITC LAB 7

Lab Task. 7.1) Write a program which prints your bio data and also show it
#include <iostream>

using namespace std;

int main()
{ int
a=0;
std::string b;
cout << "Enter your name" << endl;
getline(cin,b);
cout << "Enter your CMS ID" << endl;
cin >>a;

cout << "Your name is " <<b<< endl;


cout << "Your CMS ID is " <<a<< endl;

return 0;
}

Lab Task. 7.2) Write a program that prints the table of 8. Sample Output

#include <iostream>
using namespace std;

int main()
{
int a;
cout << "Tables" << endl;
cout <<"Enter Number"<< endl;
cin >>a;
cout <<a<<" x 1 = "<<a*1<< endl;
cout <<a<<" x 2 = "<<a*2<< endl; cout
<<a<<" x 3 = "<<a*3<< endl; cout
<<a<<" x 4 = "<<a*4<< endl; cout
<<a<<" x 5 = "<<a*5<< endl; cout
<<a<<" x 6 = "<<a*6<< endl; cout
<<a<<" x 7 = "<<a*7<< endl; cout
<<a<<" x 8 = "<<a*8<< endl; cout
<<a<<" x 9 = "<<a*9<< endl; cout
<<a<<" x 10 = "<<a*10<< endl; cout
<<a<<" x 11 = "<<a*11<< endl; cout
<<a<<" x 12 = "<<a*12<< endl;
return 0;
}

Lab Task. 7.3) Write a program which reads marks for three subjects and then prints total
marks and percentage.

#include <iostream> using


namespace std;
int main()
{
float a,b,c,d,f;
cout <<"Enter Marks for English" << endl;
cin >>a;
cout <<"Enter Marks for Maths" <<endl;
cin >>b;
cout <<"Enter Marks for Physics" << endl;
cin >>c;

cout<<"Enter Marks for English "<<a<< endl;


cout<<"Enter Marks for Maths "<<b<< endl;
cout<<"Enter Marks for Physics "<<c<< endl;
d =a+b+c
cout<<"Total Marks are " <<d<<endl;
f= d%300*100
cout<<"Percentage "<<f<<endl;

return 0;
}
LAB TASK 8:

ITC LAB 8
Lab Task. 8.1) Write a program that inputs, three numbers and find the greatest numbers
among these numbers.
#include <iostream>
using namespace std;

int main()
{ int a,b,c;
cout <<"Enter First number" << endl;
cin >>a;
cout <<"Enter Second number" <<endl;
cin >>b;
cout <<"Enter Third number" << endl;
cin >>c; if ((a>b) && (a>c))
cout<<"The Greatest number is "<<a<< endl;
else if ((b>a) && (b>c))
cout<<"The Greatest number is "<<b<< endl;
else
cout<<"The Greatest number is "<<c<< endl;
return 0;
}
Lab Task. 8.2) Write a program that swaps the value of two variables using a third variable
#include <iostream>
using namespace std;

int main()
{ int a, b, c;
cout<<"enter 1st number; ";
cin>>a;
cout<<"Enter 2nd Number: ";
cin>>b;

cout<<"Before Swapping"<<endl;
cout<<"First Number "<<a<<endl;
cout<<"Second number "<<b<<endl;

c=a;
a=b;
b=c;

cout<<"After Swapping"<<endl;
cout<<"First Number "<<a<<endl;
cout<<"Second number "<<b<<endl;

return 0;
}
Lab Task. 8.3) Write a program that checks whether the entered year is a leap year or not

#include <iostream>
using namespace std;

int main()
{ int a; cout<<:enter a year” << endl ;
cin>>a; if((a%4==0)) cout <<a<<”is a
leap year”<<endl; else cout<<a<<”a is
not a leap year”<<endl; return 0
}
Lab Task. 8.4) Write a program that checks whether the entered number is positive or
negative.

#include <iostream>
using namespace std;

int main()
{ int
a;
cout<<"Enter a Number" <<endl;
cin>>a;
if ((a>=0))
cout <<a<<" is a positive number"<<endl;
else
cout <<a<<" is a negative number"<<endl;
return 0;
}
LAB 9
Lab Task 9.1) Write a program that prints the area and the parameter of the rectangle

#include <iostream>
using namespace std;

int main()
{ int a,b,c,d;
cout << "Enter Hight of Rectangle " << endl; cin >> a;
cout << "Enter width of Rectangle " << endl; cin >>
b; c=a*b;
cout << "Area of Rectangle is "<<c<< endl; d=2*(a+b);
cout << "Parameter of Rectangle is "<<d<< endl; return 0;
}

Lab Task 9.2) Write a program that checks whether the entered alphabet is a vowel or
not.
#include <iostream>
using namespace std;

int main()
{ char c;
int islowercaseVowel, isUppercaseVowel;

cout<<"Enter an alphabet: ";


cin>> c;

islowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); isUppercaseVowel


= (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

if (islowercaseVowel || isUppercaseVowel)
cout << c << " is a Vowel."; else
cout << c << " is not a Vowel.";

return 0;
}

Lab Task 9.3) Write a program that checks whether the number entered as input is
odd or even.

#include <iostream>
using namespace std;

int main()
{ int a;
cout << "Enter a number " << endl;
cin >> a;

if ((a%2==0))
cout <<a<< " is an even number."; else
cout << a << " is an odd number.";

return 0;
}

Lab Task 9.4) Write a program that takes two numbers as input and then calculate
and print the sum, difference, product and quotients of these two numbers

#include <iostream>
using namespace std;

int main()
{
float a,b,c,d,e,f,g,h;
cout << "Enter First number " << endl; cin >> a;
cout << "Enter second number " << endl; cin >>
b; d=a+b;
cout << "Sum: "<< d << endl; f=a-b;
cout << "Difference: "<< f << endl; g=a*b;
cout << "Product: "<< g << endl; h=a/b;
cout << "Quotient: "<< h << endl;
return 0;
}
LAB 10
Lab Task. 10.1) Write a program that inputs, user grade A to F and display its comments
according to grade entered.

#include <iostream> using namespace std; //enum {A,B,C,D,E,F};

int main()
{
char Grade;
cout << "Enter your grade (A-F)" << endl;
cin>> Grade;
// while(Grade>=A&&Grade<=F)
{
switch(Grade)
{ case 'A':
cout<<"Your grade is A.\n";
cout<<"Excellent.\n";break; case 'B':
cout<<"Your grade is B.\n";
cout<<"Very Good.\n";break; case 'C':
cout<<"Your grade is C.\n";
cout<<"Good.\n";break; case 'D':
cout<<"Your grade is D.\n";
cout<<"Satisfactory.\n";break; case 'E':
cout<<"Your grade is E.\n";
cout<<"Unsatisfactory.\n";break; case 'F':
cout<<"Your grade is f.\n";
cout<<"Fail.\n";break; case 'a':
cout<<"Your grade is a.\n";
cout<<"Excellent.\n";break;
case 'b':
cout<<"Your grade is b.\n";
cout<<"Very Good.\n";break; case 'c':
cout<<"Your grade is c.\n";
cout<<"Good.\n";break; case 'd':
cout<<"Your grade is d.\n";
cout<<"Satisfactory.\n";break; case 'e':
cout<<"Your grade is e.\n";
cout<<"Unsatisfactory.\n";break; case 'f':
cout<<"Your grade is f.\n";
cout<<"Fail.\n";break; default:
cout<<"Wrong Grade \n"<<endl;
}
//cout<<"Enter your grade (A-F)";
//cin>>Grade;
} return 0;
}

Lab Task. 10.2) Write a program that ask user for which shape you want to calculate area
(Example Circle, square and triangle) and then take appropriate input from user to
calculate.

#include <iostream> using namespace std;


int main()
{
enum{square, triangle, circle, rectangle}; int
a,b,area,shape,r;
cout << "Enter the code of the shape for which area has to be calculated "
<< endl; cout << "0 for square" << endl;
cout << "1 for triangle" << endl; cout <<
"2 for circle" << endl; cout << "3 for
rectangle" << endl; cin>>shape;

switch (shape)
{
case square: cout << "Enter the length of the side of the square in meters " <<
endl; cin>>a; area=a*a;
cout<<"area of Square is "<<area<<endl;
break; case triangle: cout << "Enter the width of the
triangle" << endl; cin>>a;
cout << "Enter the Height of the triangle " << endl;
cin>>b; area=(a*b)/2;
cout<<"area of Triangle is "<<area<<endl;
break; case circle:
cout << "Enter the radius of the circle " << endl; cin>>r;
area=3.15*(r*r);
cout<<"area of circle is "<<area<<endl;
break; case rectangle: cout << "Enter the height of the
rectangle" << endl; cin>>a;
cout << "Enter the width of the rectangle " << endl;
cin>>b; area=a*b;
cout<<"area of rectangle is "<<area<<endl;
break; default:
cout << "Invalid input" << endl;
return -1;

}
return 0;
}
Lab 11
Lab Task 11.1) Write a program to calculate the factorial of the input number.

#include <iostream> using


namespace std;
int main()
{ int a,b=1;
cout << "Enter a positive integer: "<<endl;
cin >> a;
for(int i = 1; i <=a; ++i)
{
b *= i; //expression is b=a*i
}
cout << "Factorial of " << a << " = " << b;
return 0;
}

Lab Task 11.2) Write a program to check the input is a prime number or not.

#include <iostream>

using namespace std;

int main()
{
int a,b=0,c=0,i;
cout << "Enter a number " << endl;
cin>>a;
c=a/2;
for(i=2; i<=c; i++ )
{
if(a%i==0)
{
cout<<"number is not a prime."<<endl;
b=1;
break;
}
}
if(b==0)
cout<<"number is prime."<<endl;
return 0;
}

Lab Task 11.3) Write a program to generate a Fibonacci Series of given number of terms

#include <iostream>
using namespace std;

int main()
{
int n, t1 = 0, t2 = 1, nextTerm = 0;

cout << "Enter the number of terms: ";


cin >> n;

cout << "Fibonacci Series: ";

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


{
// Prints the first two terms.
if(i == 1) {
cout << " " << t1;
continue; }
if(i == 2) {
cout << t2 << " ";
continue; }
nextTerm = t1 + t2;
t1 = t2; t2 = nextTerm;

cout << nextTerm << " ";


}
return 0;
}

Lab Task 11.4) Write a program to draw the following pattern

#include <iostream>
using namespace std;

int main()
{
int a,b;
for (int a=1; a<=5; a++ ) //for no of rows
{
for (int b=1; b<=a; b++ ) //for number of colunms
{
cout<<b;
}
cout <<"\n"; //to jump to next line after a loop
}

return 0;
}
LAB 12
Lab Task. 12.1) Write a program to generate a number table of the given value. The user
should be asked for RE-RUN or EXIT the program giving up the following massage; “Do
You Want To Continue (Y/N)”.
#include <iostream>
using namespace std;

int main() { char


ans = 'N'; do {
//Calculator start
int n, range;

cout << "Enter the number of the required table: "; cin
>> n;

cout << "Enter range of table: "; cin


>> range;

for (int i = 1; i <= range; ++i) {


cout << n << " * " << i << " = " << n * i << endl;
}
//Calculator end

cout << "Do you want to continue (Y/N)?\n";


cout << "You must type a 'Y' or an 'N' :"; cin
>> ans;
} while ((ans == 'Y') || (ans == 'y'));
}

Lab Task. 12.2) Write a program to find a factorial using while loop.

#include <iostream> using


namespace std;
int main()
{
int number, i = 1, factorial = 1;

cout << "Enter a positive integer: "; cin


>> number;

while ( i <= number) {


factorial *= i; //factorial = factorial * i;
++i;
}

cout<<"Factorial of "<< number <<" = "<< factorial; return


0;
}
LAB 13
Lab Task. 13.1) Write a program to add two arrays.
#include<iostream> using
namespace std;
int main()
{
int first[20], second[20], sum[20], c, n; cout <<
"Enter the number of elements in the array "; cin >>
n;
cout << "Enter elements of first array" << endl;
for (c = 0; c < n; c++)
cin >> first[c];
cout << "Enter elements of second array" << endl;
for (c = 0; c < n; c++)
cin >> second[c];
cout << "Sum of elements of the arrays:" << endl;
for (c = 0; c < n; c++) {
sum[c] = first[c] + second[c];
cout << sum[c] << endl;
}
return 0; }

Lab Task. 13.2) Write a program that input the marks of five students in an array and find
the average

#include <iostream> using


namespace std;
int main()
{ int
i;
float num[100], sum=0, average;

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


{
cout << "Enter marks of student " << i + 1 << ":" ;
cin >> num[i];
sum += num[i];
}
average = sum / 5;
cout << "Average = " << average;
return 0;
}

Lab Task. 13.3) Write a program that creates an array of 8 numbers and perform the
following:
a. Input a number from user and search in array if it is
present or not.
b. Find the highest number present in array.
c. Find the lowest number present in array.
# include <iostream> using
namespace std;
1int main()
{
int a[8],inp;
char opt;

cout << "enter array elements" << endl;


for (int i=0; i<=7; i++)
{
cin >> a[i];
}
cout << "NUMBERS ENTERED......." << endl;
cout << "Which task do you want to perform :" << endl; cout << "a
: Find number in array....." << endl; cout << "b : Find the highest
number present in array....." << endl; cout << "c : Find the lowest
number present in array....." << endl; cin >> opt;

switch(opt)
{
case 'a':
cout << "Enter any number :" << endl;
cin >> inp;
if(inp == a[0] || inp == a[1] || inp == a[2] || inp == a[3] || inp == a[4] || inp == a[5] || inp == a[6]
|| inp == a[7] )
{
cout << "Number is present in array" << endl;
}
else
{
cout << "Number doesn't present in array" << endl;
}
break;

case 'b':
for(int i =0; i <=7 ; i++)
{
if(a[0] < a[i])
{
a[0] = a[i];
}
}
cout << "Highest number is" << a[0] << endl;
break;

case 'c':
for(int i =0; i <=7 ; i++)
{
if(a[0] > a[i])
{
a[0] = a[i];
}
}
cout << "Lowest number is" << a[0] << endl;
break;
}
}

Lab Task. 13.4) Using two-dimensional arrays, write a program which sums two (2x2)
matrices of integers

#include <iostream>
using namespace std;

int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;

cout << "Enter number of rows (between 1 and 100): ";


cin >> r;

cout << "Enter number of columns (between 1 and 100): ";


cin >> c;

cout << endl << "Enter elements of 1st matrix: " << endl;

// Storing elements of first matrix entered by user.


for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter element a" << i + 1 << j + 1 << " : ";
cin >> a[i][j];
}
// Storing elements of second matrix entered by user.
cout << endl << "Enter elements of 2nd matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter element b" << i + 1 << j + 1 << " : ";
cin >> b[i][j];
}

// Adding Two matrices


for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
sum[i][j] = a[i][j] + b[i][j];

// Displaying the resultant sum matrix.


cout << endl << "Sum of two matrix is: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << sum[i][j] << " ";
if(j == c - 1)
cout << endl;
}

return 0;
}
Lab Task. 13.5) Write a program to print the given numbers in ascending order using
arrays.

#include <iostream>
using namespace std;

#define MAX 100

int main()
{
//array declaration
int arr[MAX];
int n,i,j;
int temp;

//read total number of elements to read


cout<<"Enter total number of elements to read: ";
cin>>n;

//check bound
if(n<0 || n>MAX)
{
cout<<"Input valid range!!!"<<endl;
return -1;
}

//read n elements
for(i=0;i<n;i++)
{
cout<<"Enter element ["<<i+1<<"] ";
cin>>arr[i];
}

//print input elements


cout<<"Unsorted Array elements:"<<endl;
for(i=0;i<n;i++) cout<<arr[i]<<"\t";
cout<<endl;
//sorting - ASCENDING ORDER
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
temp =arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}

//print sorted array elements


cout<<"Sorted (Ascending Order) Array elements:"<<endl;
for(i=0;i<n;i++) cout<<arr[i]<<"\t"; cout<<endl;

return 0;

}
LAB 14
Lab Task. 14.1) Write a program in python to add, subtract, multiply and divide 2 input numbers.

x=int(input("enter a number:"))
y=int(input("enter a another
number:")) print("X + Y =",x+y)
print("X - Y =",x-y) print("X * Y
=",x*y) print("X / Y =",x/y)

Lab Task. 14.2) Write a program in python to display a table of input number.

num = int(input("Enter the number:


")) print("Multiplication Table of",
num) for i in range(1, 11):
print(num,"X",i,"=",num * i)
Lab Task. 14.3) Write a program in python to print odd right-angle triangle.
num = int(input("Enter the number of rows ")) k=1
for i in range (1, num+1)
for j in range(1,k+1)
print("1", end = "")
k=k+2
print()

You might also like