Hsslive - Computer - Science - Lab - Version 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.

in ®

Higher Secondary Lab Manual


Modified for the Academic Year 2023 Onwards

Solved Problems of Practical


Evaluation Questions -
Computer Science

Programming in C++, Web development Using HTML


and SQL

Detailed procedure for program execution and debugging.

Prepared By:
Dr. Nishad Abdulkareem
HSST Computer Science
Govt. Tribal HSS, Sholayoor, Palakkad
Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

ii

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Preface

The programs showcased in this book align with the Guidelines


for laboratory work and the Practical Evaluation of Computer
Science - 2023 (Kerala Higher Secondary Education). At the
end of each section, you’ll find comprehensive instructions for
coding and executing C++, HTML, and SQL codes.
Since the programs created here are intended for educational
purposes, we use straightforward logical constructs, and certain
necessary data validations are intentionally omitted for the sake
of simplicity.
The document is formatted using LATEX, the de facto standard
for creating and publishing scientific documents.

Please share any comments with the author at [email protected].


1
You can access the detailed demonstrations for all the
listed codes in the playlist Lab program illustration

1
Document Version : 3.0

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

iv

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Contents

1 Programming in C++ 1
1.1 Roots of quadratic equation . . . . . . . . . . . . . . . . . . . 1
1.2 Display word corresponding to a digit . . . . . . . . . . . . . . 3
1.3 Sum of n natural numbers . . . . . . . . . . . . . . . . . . . . 4
1.4 Check integer for palindrome . . . . . . . . . . . . . . . . . . . 5
1.5 Check integer for prime . . . . . . . . . . . . . . . . . . . . . . 7
1.6 Sorting of array . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Compute length of a string . . . . . . . . . . . . . . . . . . . . 11
1.8 Compute nCr using a user-defined function . . . . . . . . . . 12
1.9 Student record management using structure . . . . . . . . . . 14
1.10 Integer swap operation using a user-defined function with pointer
arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.11 Check whether the given number is positive, negative, or zero 18
1.12 Check whether the given number is odd or even . . . . . . . . 19
1.13 Sum of the squares of the first N natural numbers . . . . . . . 20

2 Developing HTML documents 23


2.1 Kerala tourism web page . . . . . . . . . . . . . . . . . . . . . 23
2.2 Hyperlinking to Various Web Pages . . . . . . . . . . . . . . . 24
2.3 Unordered List Tags . . . . . . . . . . . . . . . . . . . . . . . 27
2.4 Table of terrestrial planets . . . . . . . . . . . . . . . . . . . . 29
2.5 Client login page . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.6 Case converter using JavaScript . . . . . . . . . . . . . . . . . 32

3 SQL 35
3.1 Operations on student table . . . . . . . . . . . . . . . . . . . 35
3.2 Creating an employee table and perform fundamental operations 38
3.3 Create a stock table and perform fundamental database oper-
ations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

vi

3.4 Create a bank table and perform fundamental database oper-


ations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.5 Basic database operations on book table . . . . . . . . . . . . 47

4 Environmental Configuration 51
4.1 C++ Programming with Geany IDE on Ubuntu Linux . . . . 51
4.2 HTML Tips - Creation and rendering . . . . . . . . . . . . . . 53
4.3 Getting Started with MySQL on Ubuntu Linux . . . . . . . . 55

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Programming in C++
1
1.1 Roots of quadratic equation

PROBLEM

Input the three coefficient of quadratic equation and find the roots

CODE

1 # include < iostream >


2 # include < cmath >
3 using namespace std ;
4 int main () {
5 double a , b , c ;
6 double root1 , root2 , realPart , imgPart ;
7 cout <<" Enter the coefficients of the quadratic equation
(a , b , c ) : " ;
8 cin >> a >> b >> c ;
9 double disc = b * b - 4 * a * c ;
10 if ( disc > 0) {
11 root1 = ( - b + sqrt ( disc ) ) / (2 * a ) ;
12 root2 = ( - b - sqrt ( disc ) ) / (2 * a ) ;
13 cout << " Real and Imaginary roots \ n " ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2 Programming in C++

14 cout << " Root 1: " << root1 <<" \ n " ;


15 cout << " Root 2: " << root2 <<" \ n " ;
16 } else if ( disc == 0) {
17 root1 = -b / (2 * a ) ;
18 cout << " Two Roots are equal .\ n " ;
19 cout << " Root : " << root1 ;
20 } else {
21 realPart = -b / (2 * a ) ;
22 imgPart = sqrt ( - disc ) / (2 * a ) ;
23 cout < < " Complex Roots \ n " ;
24 cout << " Root 1: " << realPart << " + " << imgPart << "
i\n";
25 cout << " Root 2: " << realPart << " - " << imgPart << "
i\n";
26 }
27 return 0;
28 }

Listing 1.1: quadratic.cpp

OUTPUT

Figure 1.1: Roots of quadratic equation

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.2 Display word corresponding to a digit 3

1.2 Display word corresponding to a digit

PROBLEM

Input a digit and display the same in word. (Zero for 0, One for 1
etc... Nine for 9)

CODE

1 # include < iostream >


2 using namespace std ;
3 int main () {
4 int num ;
5 cout < < " Input the digit to display in words : " ;
6 cin > > num ;
7 switch ( num )
8 {
9 case 0:
10 cout < < " Zero " ; break ;
11 case 1:
12 cout < < " One " ; break ;
13 case 2:
14 cout < < " Two " ; break ;
15 case 3:
16 cout < < " Three " ; break ;
17 case 4:
18 cout < < " Four " ; break ;
19 case 5:
20 cout < < " Five " ; break ;
21 case 6:
22 cout < < " Six " ; break ;
23 case 7:

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

4 Programming in C++

24 cout < < " Seven " ; break ;


25 case 8:
26 cout < < " Eight " ; break ;
27 case 9:
28 cout < < " Nine " ; break ;
29 default :
30 cout < < " Invalid input " ;
31 }
32 return 0;
33 }

Listing 1.2: numtoword.cpp

OUTPUT

Figure 1.2: Display word corresponding to a digit

1.3 Sum of n natural numbers

PROBLEM

Find the sum of n natural numbers without using a formula

CODE

1 # include < iostream >


2 using namespace std ;
3 int main () {

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.4 Check integer for palindrome 5

4 int n ;
5 cout < < " Enter a positive integer ( n ) : " ;
6 cin >> n ;
7 int sum = 0;
8 for ( int i = 1; i <= n ; i ++) {
9 sum += i ;
10 }
11 cout <<" The sum of the first " <<n < < " natural numbers is
: " << sum ;
12 return 0;
13 }

Listing 1.3: sumofnatural.cpp

OUTPUT

Figure 1.3: Sum of n natural numbers

1.4 Check integer for palindrome

PROBLEM

Input an integer number and check whether it is a palindrome or


not

CODE

1 # include < iostream >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

6 Programming in C++

2 using namespace std ;


3 int main ()
4 {
5 int n , num , digit , rev = 0;
6 cout << " Enter a positive number : " ;
7 cin >> num ;
8 n = num ;
9 while ( num > 0)
10 {
11 digit = num % 10;
12 rev = ( rev * 10) + digit ;
13 num = num / 10;
14 }
15 cout << " The reverse of the number is : " << rev ;
16 if ( n == rev )
17 cout << " \ n The number is a palindrome . " ;
18 else
19 cout << " \ n The number is not a palindrome . " ;
20 return 0;
21 }

Listing 1.4: ispalindrome.cpp

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.5 Check integer for prime 7

Figure 1.4: Check if the given integer is Palindrome or not

OUTPUT

1.5 Check integer for prime

PROBLEM

Input an integer number and check whether it is a prime or not

CODE

1 # include < iostream >


2 using namespace std ;
3 int main () {
4 int num ;
5 bool isPrime = true ;
6 cout <<" Provide a positive number : " ;
7 cin >> num ;
8 if ( num <=1)
9 isPrime = false ;
10 else {
11 for ( int i = 2; i <= num /2; i ++) {
12 if ( num % i == 0) {
13 isPrime = false ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

8 Programming in C++

14 }
15 }}
16 if ( isPrime )
17 cout < < " Number is prime " ;
18 else
19 cout < < " Number is not prime " ;
20 return 0;
21 }

Listing 1.5: isprime.cpp

OUTPUT

Figure 1.5: Check if the given integer is Prime or not

1.6 Sorting of array

PROBLEM

Create an array to store the heights of some students and sort the
values

CODE

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.6 Sorting of array 9

1 # include < iostream >


2 using namespace std ;
3 int main () {
4 int heights [20] , i , j ,n , temp ;
5 cout < < " Enter the number of students :\ n " ;
6 cin > > n ;
7 cout < < " Enter the heights of students :\ n " ;
8 for ( i = 0; i < n ; i ++) {
9 cout << " Student " << ( i + 1) << " : " ;
10 cin >> heights [ i ];
11 }
12 for ( i =0; i < n ; i ++)
13 {
14 for ( j = i +1; j < n ; j ++) {
15 if ( heights [ i ] > heights [ j ])
16 {
17 temp = heights [ i ];
18 heights [ i ] = heights [ j ];
19 heights [ j ] = temp ;
20 }
21 }
22 }
23 cout << " The Sorted Heights \ n " ;
24 for ( i = 0; i < n ; i ++) {
25 cout << heights [ i ] < < " \ n " ;
26 }
27 return 0;
28 }

Listing 1.6: arraysort.cpp

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

10 Programming in C++

OUTPUT

Figure 1.6: Array sorting using bubble sort

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.7 Compute length of a string 11

1.7 Compute length of a string

PROBLEM

Find the length of a string without using strlen() function

CODE

1 # include < iostream >


2 # include < cstdio >
3 using namespace std ;
4 int main ()
5 {
6 char str [50];
7 int i , length =0;
8 cout < < " Enter the string : " ;
9 gets ( str ) ;
10 for ( i =0; str [ i ]!= ’ \0 ’ ;++ i )
11 length ++;
12 cout < < " Length of the string is : " << length ;
13 return 0;
14 }

Listing 1.7: stringlength.cpp

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

12 Programming in C++

Figure 1.7: Counting the length of a given string

1.8 Compute nCr using a user-defined func-

tion

PROBLEM

Define a function to find the factorial of a number. Using this


function find the value of nCr

CODE

1 # include < iostream >


2 using namespace std ;
3 long fact ( int n ) {
4 long result = 1;
5 for ( int i = 1; i <= n ; ++ i ) {
6 result = result * i ;
7 }
8 return result ;
9 }
10 int main () {

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.8 Compute nCr using a user-defined function 13

11 int n , r , ncr ;
12 cout < < " Enter the value of n and r ( positive integer ) " ;
13 cin >>n > > r ;
14 if (( n >= r ) && (r >=0) ) {
15 ncr = fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ;
16 cout < < " nCr is : " << ncr ;
17 }
18 else
19 cout < < " n and r must be non - negative integers and n > r .
" ;
20 return 0;
21 }

Listing 1.8: ncr.cpp

Figure 1.8: nCr for different n and r

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

14 Programming in C++

1.9 Student record management using structure

PROBLEM

Create a structure to represent admission number, name and marks


given for CE, PE of a subject. Input the details of student and
display admission number, name and total marks obtained

CODE

1 # include < iostream >


2 # include < cstdio >
3 using namespace std ;
4 struct student {
5 int admNo ;
6 char name [25];
7 int ceMark ;
8 int peMark ;
9 int totalMark ;
10 };
11 int main () {
12 student s ;
13 cout < < " Enter the student details :\ n " ;
14 cout < < " \ n Admission Number : " ;
15 cin > > s . admNo ;
16 cout < < " \ n Name : " ;
17 cin > > ws ; //
18 gets ( s . name ) ;
19 cout < < " \ n CE Mark : " ;
20 cin > > s . ceMark ;
21 cout < < " \ n PE Mark : " ;
22 cin > > s . peMark ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.9 Student record management using structure 15

23 s . totalMark = s . peMark + s . ceMark ;


24 cout < < " \ n The Student Details \ n " ;
25 cout < < " \ nName : " <<s . name ;
26 cout < < " \ nAdmission No . : " <<s . admNo ;
27 cout < < " \ nCE Mark : " <<s . ceMark ;
28 cout < < " \ nPE Mark : " <<s . peMark ;
29 cout < < " \ nTotal Mark : " <<s . totalMark ;
30 return 0;
31 }

Listing 1.9: studentstruct.cpp

1 2

OUTPUT

1
cin >> ws tells the compiler to ignore buffer and also to discard all the white spaces
before the actual content of string or character array
2
To resolve the issue where some IDEs may ignore the gets command, follow these steps.
Click on ”Build Commands” in the ”Set Build Commands” section. In the ’Compile’ box
and ’Build’ box, append the command -std=c++11.

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

16 Programming in C++

Figure 1.9: Data populated from the student structure

1.10 Integer swap operation using a user-defined

function with pointer arguments

PROBLEM

Input two numbers swap them by defining a function with pointer


arguments

CODE

1 # include < iostream >


2 using namespace std ;
3 void swap ( int *x , int * y )
4 {
5 int t ;
6 t =* x ;
7 * x =* y ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.10 Integer swap operation using a user-defined function with


pointer arguments 17

8 *y=t;
9 }
10 int main ( )
11 {
12 int a , b ;
13 cout < < " Enter the values of a and b " ;
14 cin > >a > > b ;
15 cout < < " \ nBefore Swap \ n " ;
16 cout < < " a = " <<a < < " \ t b = " <<b ;
17 swap (& a ,& b ) ;
18 cout < < " \ nAfter Swap \ n " ;
19 cout < < " a = " <<a < < " \ t b = " <<b ;
20 }

Listing 1.10: swappointer.cpp

OUTPUT

Figure 1.10: Swapping of two numbers

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

18 Programming in C++

1.11 Check whether the given number is pos-

itive, negative, or zero

PROBLEM

Input a number and check if it is positive negative or zero

CODE

1 # include < iostream >


2 using namespace std ;
3 int main () {
4 int num ;
5 cout < < " Enter the integer to check : " ;
6 cin > > num ;
7 if ( num >0)
8 cout < < " \ n The given number is Positive " ;
9 else if ( num <0)
10 cout < < " \ n The given number is Negative " ;
11 else
12 cout < < " \ n The given number is Zero " ;
13 return 0; }

Listing 1.11: numcheck.cpp

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.12 Check whether the given number is odd or even 19

Figure 1.11: number check

1.12 Check whether the given number is odd

or even

PROBLEM

Input a number and check if it is odd or even

CODE

1 # include < iostream >


2 using namespace std ;
3 int main ()
4 {
5 int num ;
6 cout < < " Enter a number to check - odd or even : " ;
7 cin > > num ;
8 if ( num %2==0)
9 cout < < " The given number is even " ;
10 else
11 cout < < " The Given number is odd " ;
12 return 0;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

20 Programming in C++

13 }

Listing 1.12: oddeven.cpp

OUTPUT

Figure 1.12: odd even

1.13 Sum of the squares of the first N natural

numbers

PROBLEM

Find the sum of squares of integers up to a specified limit by in-


putting a number.

CODE

1 # include < iostream >


2 using namespace std ;
3 int main ()
4 {
5 int num , sum =0 , i ;
6 cout < < " Enter the limit : " ;
7 cin > > num ;
8 for ( i =1; i <= num ; i ++)
9 sum = sum + i * i ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

1.13 Sum of the squares of the first N natural numbers 21

10 cout < < " Sum of square : " << sum ;


11 return 0;
12 }

Listing 1.13: sumsquare.cpp

OUTPUT

Figure 1.13: Sum of Squares of integer

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

22 Programming in C++

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Developing HTML documents


2
2.1 Kerala tourism web page

PROBLEM

Design a simple and attractive web page for Kerala Tourism. It


should contain features like back ground colour / image headings,
text formatting and font tags, images etc.

CODE

1 < html >


2 < head >
3 < head >
4 < title > Kerala Tourism </ title >
5 </ head >
6 < body background = " mountains . jpeg " bgcolor = " Green " >
7 < h1 align = " center " > DEPARTMENT OF TOURISM </ h1 >
8 < h2 align = " center " > Kerala State </ h2 >
9 <b > Kerala </ b > , in the south - western part of India ,
10 is a highly desirable tourist destination in Asia ,
11 often called
12 < font size = " 10 " color = " blue " face = " Cambria " >
13 God ’ s Own Country . </ font > </ br >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

24 Developing HTML documents

14 It was recognized by National Geographic


15 Traveller as one of the world ’ s 50 lifetime destinations
16 and one of the thirteen < em > paradises on Earth . </ em >
17 </ body >
18 </ html >

Listing 2.1: tourism.html

Figure 2.1: Screenshot of website

2.2 Hyperlinking to Various Web Pages

PROBLEM

Design a simple web page about your school. Create another web
page named address.html containing the school address. Give links
from school page to address.html and reverse

CODE

school.html

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2.2 Hyperlinking to Various Web Pages 25

1 < html >


2 < head >
3 < title > My School </ title >
4 </ head >
5 < body background = " school . jpeg " >
6 < h1 align = " CENTER " color = " blue " > Got . Tribal HSS Sholayoor
</ h1 >
7 < br > Our school , located in the picturesque hilly
8 region of Sholayoor within Palakkad District , is nestled
9 in the captivating
10 Attappadi mountain a r e a a renowned hill station in Kerala
.
11 The school proudly offers four distinct batches of
12 Higher Secondary Courses , namely Biology Science ,
13 Home Science , Commerce , and Sociology .
14 < br >
15 From first standard to twelve about 800 students
16 are studying here .
17 < BR > With a student body ranging from the first standard
18 to the twelfth , we currently educate approximately 800
students .
19 Furthermore , our school is supported by a dedicated team
of
20 about 35 staff members who work diligently
21 to provide quality education .
22 < br >
23 <a href = " address . html " > Click here for our school address <
/a>
24 </ body >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

26 Developing HTML documents

25 </ html >

Listing 2.2: school.html

address.html

1 < html >


2 < head >
3 < title > Address </ title >
4 </ head >
5 < body >
6 < h2 align = " center " > Govt Tribal HSS </ h2 >
7 < address >
8 Govt Tribal HSS Sholayoor < BR >
9 Sholayoor Post < BR >
10 Attappadi , Mannarkkad < br >
11 Palakkad Dist < br >
12 </ address >
13 <a href = " school . html " > back to school </ a >
14 </ body >
15 </ html >

Listing 2.3: address.html

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2.3 Unordered List Tags 27

(a) Screenshot of school homepage

(b) Screenshot of school address page

2.3 Unordered List Tags

PROBLEM

Design a Web page as shown in 2.3 using appropriate List Tags

CODE

1 < html >


2 < head >
3 < title > Higher Education Instituitions </ title >
4 </ head >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

28 Developing HTML documents

Figure 2.3: Unordered list

5 < body bgcolor = " Cyan " >


6 < h2 > Leading Institutions in Kerala for Higher Education </
h2 >
7 < ul >
8 < li > Indian Institute of Technology , Palakkad </ li >
9 < li > National Institute of Technology , Calicut </ li >
10 < li > Indian Institute of Science Education and Research ,
Th ir uv an an th ap ur am </ li >
11 < li > National University of Advanced Legal Studies ,
Cochin </ li >
12 < li > Indian Institute of Space science and Technology </
li >
13 </ ul >
14 </ body >
15 </ html >

Listing 2.4: highereducate.html

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2.4 Table of terrestrial planets 29

Figure 2.4: Terrestrial Planets listed in a Table

2.4 Table of terrestrial planets

PROBLEM

Design a Web page containing a table as shown in Figure 2.4

CODE

1 < html >


2 < head >
3 < title > Terrestrial Planets </ title >
4 </ head >
5 < body >
6 < table border = " 1 " >
7 < caption > <b > Terrestrial Planets </ b >( Source NASA ) </ caption >
8 < tr >
9 < th > Planet </ th >
10 < th > Day Length < br > ( In Earth hour ) </ th >
11 < th > Year Length < br > ( In Earth days ) </ th >
12 </ tr >
13 < tr >
14 < td > Mercury </ td >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

30 Developing HTML documents

15 < td > 1408 </ td >


16 < td > 88 </ td >
17 </ tr >
18 < tr >
19 < td > Venus </ td >
20 < td > 5832 </ td >
21 < td > 224.7 </ td >
22 </ tr >
23 < tr >
24 < td > Earth </ td >
25 < td > 24 </ td >
26 < td > 365.26 </ td >
27 </ tr >
28 </ table >
29 </ body >
30 </ html >

Listing 2.5: terrestrial.html

2.5 Client login page

PROBLEM

Design a web page as shown in Figure 2.5

CODE

1 < HTML >


2 < HEAD > < TITLE > LOGIN </ TITLE > </ HEAD >
3 < BODY >
4 < FORM >
5 < TABLE >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2.5 Client login page 31

Figure 2.5: Client login page

6 < TR > < TH > Client Login </ TH > </ TR >
7 < TR > < TD > User Name </ TD > < TD > < INPUT Type = " Text " > </ TD > </ TR
>
8 < TR > < TD > Password </ TD > < TD > < INPUT Type = " Password " > </ TD > </
TR >
9 < TR >
10 < TD > < INPUT Type = " Submit " value = " Submit " > </ TD >
11 < TD > < INPUT Type = " Reset " value = " Clear " > </ TD >
12 </ TR >
13 </ TABLE >
14 </ FORM >
15 </ BODY >
16 </ HTML >

Listing 2.6: login.html

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

32 Developing HTML documents

2.6 Case converter using JavaScript

PROBLEM

A web page should contain one text box for entering a text. There
should be two buttons labelled to Upper Case and To Lower Case.
on clicking each button, the content in the text box should be
converted to upper case or lower case accordingly . Write required
java script for this operations

CODE

1 < html >


2 < head >
3 < title > Case Converter </ title >
4 < script language = " javascript " >
5 // Function to convert text to uppercase
6 function c on ve rtT oU pp er Ca se () {
7 var textInput = document . myForm . textInput . value ;
8 document . myForm . textInput . value = textInput . toUpperCase ()
;
9 }
10 // Function to convert text to lowercase
11 function c on ve rt ToL ow er Ca se () {
12 var textInput = document . myForm . textInput . value ;
13 document . myForm . textInput . value = textInput . toLowerCase ()
;
14 }
15 </ script >
16 </ head >
17 < body bgcolor = " green " >

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

2.6 Case converter using JavaScript 33

18 < h2 > lower case : the celebration of equality and simplicity


in language and design </ h2 >
19 < form name = " myForm " >
20 < table >
21 < tr > < td > Provide a text </ td >
22 < td > < input type = " text " name = " textInput " > </ td >
23 </ tr >
24 < tr >
25 < td > < input type = " button " onclick = " con ve rt To Up pe rC as e
() " value = " To Upper Case " > </ td >
26 < td > < input type = " button " onclick = " con ve rt To Lo we rC as e
() " value = " To Lower Case " > </ td >
27 </ tr >
28 </ table >
29 </ form >
30 </ body >
31 </ html >

Listing 2.7: casechangescript.html

Figure 2.6: Case converter

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

34 Developing HTML documents

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

SQL
3
3.1 Creating a student table and perform fun-

damental operations

PROBLEM

Create a table Student with the following fields and insert at least
5 records into the table except for the column Total.

Roll Number Integer Primary key,Name Varchar (25),


Batch Varchar (15), Mark1 Integer, Mark2 Integer,
Mark3 Integer,Total Integer

1. Update the column Total with the sum of Mark1, Mark2 and Mark3.
2. List the details of students in Commerce batch.
3. Display the name and total marks of students who are failed (Total less
than 90).
4. Display the name of students in alphabetical order and in batch based

SOLUTION

Creation of student table

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

36 SQL

CREATE TABLE student (


roll_number INT NOT NULL PRIMARY KEY ,
stud_name VARCHAR (25) , batch VARCHAR (25) ,
mark1 INT , mark2 INT , mark3 INT , total INT
);

Listing 3.1: Query: Create student table

Inserting values into the student table

insert into student values


(1 , ’ Alan Turing ’ , ’ Science ’ ,80 , 70 , 55 , null ) ;
insert into student values
(2 , ’ Ada Lovelace ’ , ’ Science ’ ,30 , 40 , 15 , null ) ;
insert into student values
(3 , ’ Adam Smith ’ , ’ Commerce ’ , 70 , 60 , 40 , null ) ;
insert into student values
(4 , ’ Amartya Sen ’ , ’ Commerce ’ ,40 , 80 , 50 , null ) ;
insert into student values
(5 , ’ Ibn Rushd ’ , ’ Science ’ , 90 , 94 , 35 , null ) ;
insert into student values
(6 , ’ Irfan Habeeb ’ , ’ Humanities ’ , 80 , 76 , 69 , null ) ;
insert into student values
(7 , ’ Friedman ’ , ’ Commerce ’ , 60 , 60 , 50 , null ) ;
insert into student values
(8 , ’ Robinson ’ , ’ Commerce ’ , 50 , 70 , 50 , null ) ;

Listing 3.2: Query:Multiple queries to insert records in to the student table.

Fetching complete records from the student table

SELECT * FROM student ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.1 Operations on student table 37

Figure 3.1: Retrieving all records from the table

Answer 1: UPDATE student SET total = mark1 + mark2 + mark3 ;


Answer 2: SELECT * FROM student WHERE batch = ’ Commerce ’;

Figure 3.2: Complete student details of Commerce batch

Answer 3. select stud_name , total from student where total <90;

Refer Figure 3.3 for the result

Figure 3.3: Result of select query total <90

Answer 4: select stud_name , batch from student order by batch


, stud_name ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

38 SQL

Figure 3.4: Result of select - order by query

3.2 Creating an employee table and perform

fundamental operations

PROBLEM

Create a table employee with the following fields and insert at least
5 records into the table except the column Gross pay and DA.

Emp code Integer Primary key, Emp name Varchar (20),


Designation Varchar (25), Department Varchar (25), Basic Decimal (10,2)
DA Decimal (10,2), Gross pay Decimal (10,2)

1. Update DA with 75% of Basic.


2. Display the details of employees in Purchase, Sales and HR depart-
ments.
3. Update the Gross pay with the sum of Basic and DA.
4. Display the details of employee with gross pay below 20000

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.2 Creating an employee table and perform fundamental


operations 39

SOLUTION

Creation of employee table

CREATE TABLE employee ( Emp_code Int PRIMARY KEY ,


Emp_name VARCHAR (20) , Designation VARCHAR (25) ,
Department VARCHAR (25) , Basic DEC (10 ,2) ,
DA DEC (10 ,2) , Gross_pay DEC (10 ,2) ) ;

Listing 3.3: Create Query

Inserting Values to the employee table

INSERT INTO employee VALUES


(100 , ’ Arjun ’ , ’ Trainees ’ , ’ Sales ’ ,16000.00 , NULL , NULL ) ,
(101 , ’ Maya ’ , ’ Trainees ’ , ’ Purchase ’ ,9000.00 , NULL , NULL ) ,
(102 , ’ Rahul ’ , ’ Trainees ’ , ’ Purchase ’ ,10000.00 , NULL , NULL ) ,
(103 , ’ Ibrahim ’ , ’ Supervisors ’ , ’ Purchase ’ ,18000.00 , NULL ,
NULL ) ,
(104 , ’ Abdulla ’ , ’ Supervisors ’ , ’ Sales ’ ,21000.00 , NULL , NULL )
,
(105 , ’ Vivek ’ , ’ Managers ’ , ’ HR ’ ,32000.00 , NULL , NULL ) ,
(106 , ’ George ’ , ’ Managers ’ , ’ Sales ’ ,45000.00 , NULL , NULL ) ,
(107 , ’ Meera ’ , ’ Trainees ’ , ’ HR ’ ,11000.00 , NULL , NULL ) ;
(108 , ’ Tiji ’ , ’ Trainees ’ , ’ IT ’ ,12000.00 , NULL , NULL ) ;

Listing 3.4: Query :Insert multiple record in to the employee table using a single
query

Answer 1: UPDATE employee SET DA = Basic *75/100;


Answer 2: SELECT * FROM employee WHERE Department IN ( ’
Purchase ’ , ’ Sales ’ , ’ HR ’) ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

40 SQL

Figure 3.5: Result of select query from employee table

Answer 3: UPDATE employee SET Gross_pay = Basic + DA ;


Answer 4: SELECT * FROM employee WHERE Gross_pay < 20000;

Figure 3.6: Resultant table of select query from the employee table with
Gross pay <20000

3.3 Create a stock table and perform funda-

mental database operations

PROBLEM

Create a table Stock, which stores daily sales of items in a shop,


with the following fields and insert at least 5 records into the table.

Item code Integer Primary key, Item name Varchar (20)


Manufacturer Code Varchar (5), Qty Integer, Unit Price Decimal (10,2)

1. Display the item name with stock zero.


2. Display the number of items manufactured by the same manufacturer.

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.3 Create a stock table and perform fundamental database


operations 41

3. Display the highest price and lowest quantity in the stock


4. Increase the unit price of all items by 10%

SOLUTION

Creation of stock table

CREATE TABLE stock ( Item_code INTEGER PRIMARY KEY ,


Item_name VARCHAR (20) , Manuf acture r_Code VARCHAR (5) ,
Qty INT , Unit_Price DECIMAL (10 ,2) ) ;

Listing 3.5: Query: Creation of stock table

Inserting values to the stock table

INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘


Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘) VALUES ( ’ 1001 ’ , ’ Smart Phone ’ , ’ Samsung ’
, ’ 23 ’ , ’ 36000 ’) ;
INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘
Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1002 ’ , ’ Smart Watch ’ , ’ Samsung ’ , ’ 16 ’ , ’ 19000 ’) ;
INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘
Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1003 ’ , ’ Washing Machine ’ , ’ LG ’ , ’ 21 ’ , ’ 36000 ’) ;
INSERT INTO ‘ stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘
Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1004 ’ , ’ Juicer ’ , ’ Butterfly ’ , ’5 ’ , ’ 7000 ’) ;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

42 SQL

INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘


Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1005 ’ , ’ Toaster ’ , ’ Philips ’ , ’0 ’ , ’ 3000 ’) ;
INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘
Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1006 ’ , ’ Air Purifier ’ , ’ Philips ’ , ’3 ’ , ’ 9500 ’) ;
INSERT INTO stock ( ‘ Item_code ‘ , ‘ Item_name ‘ , ‘
Manufacturer_Code ‘ ,
‘Qty ‘ , ‘ Unit_Price ‘)
VALUES ( ’ 1007 ’ , ’ Coffee Maker ’ , ’ Havels ’ , ’0 ’ , ’ 16000 ’) ;

Listing 3.6: Query: Multiple queries to insert various records into the stock table.

Answer 1: SELECT * FROM stock WHERE Qty =0;

Figure 3.7: Resultant table of select query from the stock table with stock = 0

Answer 2:
SELECT Manufacturer_Code , COUNT ( Item_code ) AS No_Products
FROM stock
GROUP BY Manuf acture r_Code ;

Listing 3.7: Query: Selecting items manufactured by same manufacturer

Answer 3:
SELECT MAX ( Unit_price ) AS Highest_price ,
MIN ( Qty ) AS Min_Qty FROM stock ;

Listing 3.8: Query: Selecting higherst price and lowest stock

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.3 Create a stock table and perform fundamental database


operations 43

Figure 3.8: The quantity of items produced by same manufacturer from the stock
database

Figure 3.9: The table resulting from the SELECT query

Answer 4:
UPDATE stock SET Unit_Price = Unit_Price + Unit_Price *.1;

Listing 3.9: Query: Updating unit price

Figure 3.10: Before executing the Update Query

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

44 SQL

Figure 3.11: After executing the Update Query

3.4 Create a bank table and perform funda-

mental database operations

PROBLEM

Create a table bank with the following fields and insert at least 5
records into the table.

Acc Number Integer Primary key, Acc Name Varchar (20),


Branch Name Varchar (25), Acc Type Varchar (10) , Amount Decimal (10,2)

1. Display the account details account in Kodungallur Branch


2. Change the branch name Trivandrum to Thiruvananthapuram.
3. Display the details of customers in Thiruvananthapuram, Eranakulam
and Kozhikkode
4. List the details of customers in Trissur branch having a minimum bal-
ance of Rs. 5000

SOLUTION

Creation of bank table

CREATE TABLE bank (


Acc_No INT NOT NULL PRIMARY KEY , Acc_Name ‘ VARCHAR (20) ,
Branch_Name VARCHAR (25) , Acc_Type VARCHAR (10) ,

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.4 Create a bank table and perform fundamental database


operations 45

Amount DECIMAL (10 ,2)


) ;

Listing 3.10: Query:Creation of bank table

Inserting values into the bank table

INSERT INTO bank VALUES


( ’ 150001 ’ , ’ Peter ’ , ’ Alappuzha ’ , ’ Current ’ , ’ 65000 ’) ;

INSERT INTO bank VALUES


( ’ 150002 ’ , ’ Hamid ’ , ’ Trivandrum ’ , ’ Savings ’ , ’ 12000 ’) ;

INSERT INTO bank VALUES


( ’ 150003 ’ , ’ Anoop ’ , ’ Malappuram ’ , ’ Savings ’ , ’ 4000 ’) ;

INSERT INTO bank VALUES


( ’ 150004 ’ , ’ Jyothi ’ , ’ Trissur ’ , ’ Current ’ , ’ 75000 ’) ;

INSERT INTO bank VALUES


( ’ 150005 ’ , ’ Azim ’ , ’ Ernakulam ’ , ’ Current ’ , ’ 58600 ’) ;

INSERT INTO bank VALUES


( ’ 150006 ’ , ’ Ayra ’ , ’ Kozhikkod ’ , ’ Savings ’ , ’ 7500 ’) ;

INSERT INTO bank VALUES


( ’ 150007 ’ , ’ Amosh ’ , ’ Trissur ’ , ’ Savings ’ , ’ 3500 ’) ;

INSERT INTO bank VALUES

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

46 SQL

( ’ 150008 ’ , ’ Sidharth ’ , ’ Kodungallore ’ , ’ Savings ’ , ’ 69200 ’) ;

Listing 3.11: Query: Multiple queries to insert various records into the bank
table.

Answer 1: SELECT * FROM bank WHERE Branch_Name = " Kodungallore "


;

Figure 3.12: Account Details of Kodungallore branch

Answer 2: UPDATE bank SET Branch_Name = " Thi ru va na nt ha pu ra m "


WHERE Branch_Name = " Trivandrum " ;
Answer 3: SELECT * FROM bank WHERE Branch_Name IN
( ’ Th ir uv an an th ap ur am ’ , ’ Kozhikkod ’ , ’ Ernakulam ’) ;

Figure 3.13: Account Details of Selected branches using IN clause

Answer 4: SELECT * FROM bank WHERE Branch_Name = ’ Trissur ’


HAVING Amount < 5000;

Figure 3.14: Account details of selected branches using HAVING clause

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.5 Basic database operations on book table 47

3.5 Create a book table and perform funda-

mental database operations

PROBLEM

Create a table book with the following fields and insert at least 5
records into the table.

Book Id Integer Primary key, Book Name Varchar (20),


Author Name Varchar (25), Pub Name Varchar (25), Price Decimal (10,2)

1. Display the details of book with price 100 or more.


2. Display the names of all books published by SCERT.
3. Increase the price of books by 10% which are published by SCERT.
4. List the details of books with the title containing the word “Program-
ming” at the end.

SOLUTION

Creation of book table

CREATE TABLE book (


Book_ID INT NOT NULL PRIMARY KEY ,
Book_Name VARCHAR (20) ,
Author_Name VARCHAR (25) ,
Pub_Name VARCHAR (25) ,
Price DECIMAL (10 ,2) ) ;

Listing 3.12: Create Query

Inserting values to the table

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

48 SQL

INSERT INTO book VALUES ( ’ 1200 ’ , ’ The Kite Runner ’ , ’ Khaled


Husseini ’ , ’ River Head ’ , ’ 450 ’) ;

INSERT INTO book VALUES ( ’ 1201 ’ , ’ Wings of Fire ’ , ’ Dr . APJ


Abdulkalam ’ , ’ Universities Press ’ , ’ 250 ’) ;

INSERT INTO book VALUES ( ’ 1202 ’ , ’ The White Tiger ’ , ’ Aravind


Adiga ’ , ’ Atlantic ’ , ’ 300 ’) ;

INSERT INTO book VALUES ( ’ 1203 ’ , ’ Manju ’ , ’M T Vasudevan Nair


’ , ’ DC Books ’ , ’ 425 ’) ;
INSERT INTO book VALUES ( ’ 1204 ’ , ’ Arachar ’ , ’K R Meera ’ , ’ DC
Books ’ , ’ 225 ’) ;

INSERT INTO book VALUES ( ’ 1205 ’ , ’ When Breath Becomes Air ’ , ’


paul Kalanidhi ’ , ’ Random House ’ , ’ 525 ’) ;

INSERT INTO book VALUES ( ’ 1206 ’ , ’ Forty Rules of Love ’ , ’ Elif


Shefak ’ , ’ Penguine ’ , ’ 700 ’) ;

INSERT INTO book VALUES ( ’ 1207 ’ , ’ Art of Computer Programming


’ , ’ Peter ’ , ’ SCERT ’ , ’ 125 ’) ;

INSERT INTO book VALUES ( ’ 1208 ’ , ’ Madhuram Malayalam ’ , ’ Madhu


Vaduthala ’ , ’ SCERT ’ , ’ 75 ’) ;

INSERT INTO book VALUES ( ’ 1209 ’ , ’ Python Programming ’ , ’


Michael Dawson ’ , ’ Pearson ’ , ’ 3300 ’) ;

Listing 3.13: Query: Inserting various records into the book table

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

3.5 Basic database operations on book table 49

Answer 1: SELECT * FROM book WHERE Price >= 100;

Listing 3.14: Insert Query

Figure 3.15: Books that costs 100 or more

Answer 2: SELECT * FROM book WHERE Pub_Name = ’ SCERT ’;

Figure 3.16: Books that costs 100 or more

Answer 3: UPDATE book SET Price = Price + Price *0.1 WHERE


Pub_Name = ’ SCERT ’;

Answer 4: SELECT * FROM BOOK WHERE Book_Name LIKE ’%


Programming ’;

Figure 3.17: Books that costs 100 or more

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

50 SQL

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Environmental Configuration
4
4.1 C++ Programming with Geany IDE on

Ubuntu Linux

C++ is a compiled language, utilizing a compiler to translate source code into


object code. This object code is then transformed into an executable for end-
users. To develop C++ code, an Integrated Development Environment (IDE)
is necessary. In this guide, we will use Geany as our editor of choice. Several
compilers are available for C++, including GCC, Borland C++, Turbo C++,
Microsoft C++ (Visual C++), and Unix AT T C++. Of these, GCC
is a free software available on Linux and Windows platforms. Geany is a
versatile cross-platform IDE compatible with GCC for writing, compiling,
and executing C++ programs.

Opening Geany IDE on Ubuntu Linux:

1. Access the Geany IDE from the Applications menu on Ubuntu Linux
by following these steps: Applications− > P rogramming− > Geany

2. Create a new file by navigating to F ile− > N ew

3. In the new window, you can begin typing your C++ program. By

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

52 Environmental Configuration

default, the file is named ”untitled.” To open a new file, go to the File
menu, select the New option, or click the New button on the toolbar.
Once you have a file open, enter your C++ program and save it with
a suitable filename, including the .cpp extension.

4. To save your program, select the File menu and then the Save option
or use the keyboard shortcut Ctrl+S.

Compiling and Running the Program:

Once the code is written, it needs to be compiled and executed:

Compile

To compile your program identify and correct errors if any are detected,
follow these steps: Build− > Compile a. If errors are present, they will
be displayed in the compiler status window at the bottom. Otherwise, a
message stating ”Compilation finished successfully” will appear. b. After a
successful compilation, choose the Build menu and select the Build option to
link your program. Build− > Build

Running the Program:

Running a program involves executing the instructions defined in the code.


To run your program:
Select the Build menu and choose the Execute option. Alternatively, you
can execute the program by pressing the function key F5. Build− > Execute
By following these steps, you can create, compile, and run C++ programs

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

4.2 HTML Tips - Creation and rendering 53

Figure 4.1: Steps to execute a C++ Program

using the Geany IDE on Ubuntu Linux.

4.2 HTML Tips - Creation and rendering

Using Geany Editor to create an HTML File:

To create an HTML file using the Geany Editor, follow these steps:

• Open Geany Editor.

• Start a new document and ensure the file extension is either .html or
.htm.

HTML’s Simplicity and Flexibility: HTML is known for its simplicity


and flexibility. Unlike strongly typed languages, HTML is loosely
typed, which means it doesn’t require explicit data type declarations.

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

54 Environmental Configuration

For example, you don’t need to specify whether a value is a string or a


number; HTML handles it based on context.

Tag Case Sensitivity: In HTML, tags are not case sensitive, which means
you can use uppercase or lowercase letters for tags without affecting
how the browser renders the content. However, when working with
XHTML, all tags must be in lowercase. It’s a good practice to use
lowercase tags even when coding in HTML for consistency.

Proper Indentation: Maintaining proper indentation while writing HTML


code is crucial. It helps you identify and locate unclosed or incor-
rectly typed tags more easily. This ensures your HTML code is well-
structured and error-free.

HTML as a Markup Language: HTML is a markup language, which means


it defines how content is displayed in a web browser. It does not sup-
port mathematical operations or scripting. Instead, it’s parsed and
rendered by the web browser to create the visual representation of a
web page.

Viewing the HTML File: After creating the HTML file, you can locate
it on your file system and open it in any web browser to view the web
page you’ve created. Simply double-click on the HTML file, and your
browser will render the content.

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

4.3 Getting Started with MySQL on Ubuntu Linux 55

4.3 Getting Started with MySQL on Ubuntu

Linux

MySQL is a relational database language designed for managing data, not to


be confused with programming languages like C or C++. It provides various
commands to create and manipulate tables, insert data, and perform data
operations within tables.
To start working with MySQL on Ubuntu Linux, follow these steps:

1. Open the Terminal window by navigating through Applications ¿ Ac-


cessories ¿ Terminal.

2. Upon opening MySQL, it may prompt you for a password for verifica-
tion. Use the same password you set during the installation process.

3. Once the password is verified, you will gain access to the MySQL
prompt.

Before working with data, you need to create a database, which serves
as a container for tables. To create a database in MySQL, use the following
syntax:

CREATE DATABASE < database_name >;

Replace < database name > with a meaningful and unique name for your
database. To work with a specific database, you must explicitly open it.
When you open a database, it becomes the active database within the MySQL
server. MySQL provides the USE command for this purpose, with the fol-
lowing syntax:

USE < database_name >;

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

56 Environmental Configuration

For example, to open the ”school” database, use the command:

USE school ;

After executing this command, you will receive the following response:

Database changed

This response indicates that you have successfully switched to the ”school”
database, and you are ready to work with the data within it.
To see the structure of created table use the DESC command. For
example

DESC student ;

Figure 4.2: Schema of the student table

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

Thank You

Code is like humor. When you have to explain

it, it’s bad

-Cory House

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem


Join Now: https://join.hsslive.in Downloaded from https://www.hsslive.in ®

58 Environmental Configuration

Computer Science Lab Manual Prepared by Dr. Nishad Abdulkareem

You might also like