Hsslive - Computer - Science - Lab - Version 3
Hsslive - Computer - Science - Lab - Version 3
Hsslive - Computer - Science - Lab - Version 3
in ®
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
Preface
1
Document Version : 3.0
iv
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
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
vi
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
Programming in C++
1
1.1 Roots of quadratic equation
PROBLEM
Input the three coefficient of quadratic equation and find the roots
CODE
2 Programming in C++
OUTPUT
PROBLEM
Input a digit and display the same in word. (Zero for 0, One for 1
etc... Nine for 9)
CODE
4 Programming in C++
OUTPUT
PROBLEM
CODE
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 }
OUTPUT
PROBLEM
CODE
6 Programming in C++
OUTPUT
PROBLEM
CODE
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 }
OUTPUT
PROBLEM
Create an array to store the heights of some students and sort the
values
CODE
10 Programming in C++
OUTPUT
PROBLEM
CODE
12 Programming in C++
tion
PROBLEM
CODE
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 }
14 Programming in C++
PROBLEM
CODE
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.
16 Programming in C++
PROBLEM
CODE
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 }
OUTPUT
18 Programming in C++
PROBLEM
CODE
or even
PROBLEM
CODE
20 Programming in C++
13 }
OUTPUT
numbers
PROBLEM
CODE
OUTPUT
22 Programming in C++
PROBLEM
CODE
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
address.html
PROBLEM
CODE
PROBLEM
CODE
PROBLEM
CODE
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 >
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
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.
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
36 SQL
38 SQL
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.
SOLUTION
Listing 3.4: Query :Insert multiple record in to the employee table using a single
query
40 SQL
Figure 3.6: Resultant table of select query from the employee table with
Gross pay <20000
PROBLEM
SOLUTION
42 SQL
Listing 3.6: Query: Multiple queries to insert various records into the stock table.
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 ;
Answer 3:
SELECT MAX ( Unit_price ) AS Highest_price ,
MIN ( Qty ) AS Min_Qty FROM stock ;
Figure 3.8: The quantity of items produced by same manufacturer from the stock
database
Answer 4:
UPDATE stock SET Unit_Price = Unit_Price + Unit_Price *.1;
44 SQL
PROBLEM
Create a table bank with the following fields and insert at least 5
records into the table.
SOLUTION
46 SQL
Listing 3.11: Query: Multiple queries to insert various records into the bank
table.
PROBLEM
Create a table book with the following fields and insert at least 5
records into the table.
SOLUTION
48 SQL
Listing 3.13: Query: Inserting various records into the book table
50 SQL
Environmental Configuration
4
4.1 C++ Programming with 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
3. In the new window, you can begin typing your C++ program. By
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.
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
To create an HTML file using the Geany Editor, follow these steps:
• Start a new document and ensure the file extension is either .html or
.htm.
54 Environmental Configuration
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.
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.
Linux
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:
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:
56 Environmental Configuration
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 ;
Thank You
-Cory House
58 Environmental Configuration