Computer Software Application: Trade Practical NSQF Level - 5
Computer Software Application: Trade Practical NSQF Level - 5
APPLICATION
VOLUME - 1
Printed in India at
ii
A Comprehensive Training Program
under Crafts Instructor Training Scheme
(CITS)
for Instructors
HANDBOOK ON
TECHNICAL INSTRUCTOR TRAINING
MODULES
iii
iv
अतुल ितवारी, I.A.S. FOREWORD
सिचव GOVERNMENT OF INDIA
ATUL KUMAR TIWARI, I.A.S. MINISTRY OF SKILL
Secretary DEVELOPMENT AND
ENTREPRENEURSHIP
Foreword
In today’s rapidly evolving world, the role of skilled craftsmen and women is more crucial than
ever. The Craft Instructor Training Scheme (CITS) stands at the forefront of this
transformation, shaping the educators who will train the next generation of artisans and
technicians. This book aims to provide an in-depth understanding of the subject, exploring its
significance, methodologies, and impact on vocational training.
The Craft Instructor Training Scheme was established with the objective of enhancing the
quality of instruction in industrial training institutes and other vocational training institutions.
By equipping instructors with advanced skills and knowledge, the scheme ensures that they
are well-prepared to impart high-quality training to their students. This, in turn, contributes to
the creation of a highly skilled workforce capable of meeting the demands of modern industry.
The initial chapters provide the importance of specialized instructor training. Following this,
detailed chapters delve into the curriculum covering advanced techniques, safety protocols,
and instructional strategies. Each section is designed to offer both theoretical insights and
practical applications, ensuring a well-rounded understanding of the subject.
The book offers recommendations for overcoming obstacles and enhancing the effectiveness
of the program, with the ultimate goal of producing highly skilled instructors capable of
shaping the future workforce.
This book is intended for a diverse audience, including current and aspiring instructors,
vocational training administrators, policymakers, and industry stakeholders. It serves as a
valuable resource for understanding the intricacies of the subject and its pivotal role in
vocational education.
I extend my heartfelt gratitude to all contributors who have shared their experiences and
expertise, enriching this book with their valuable insights. Special thanks to the contribution of
the development team, reviewers and NIMI that have supported this endeavor, providing
essential data and resources.
It is my sincere hope that this book will inspire and guide readers in their efforts to enhance
vocational training, ultimately contributing to the development of a skilled and competent
workforce.
v
v
vi
PREFACE
The Craft Instructor Training Scheme is an indispensable module of the Craftsmen
Training Scheme, which has been an integral part of the Indian skill development
industry since its inception. This program aims to equip instructors with the
necessary skills and teaching methodology to effectively transfer hands-on skills to
trainees and promote a holistic learning experience. The first Craft Instructor Training
Institute was established in 1948, followed by six more institutes across India in
1960. Today, these institutes, including the National Skill Training Institute (formerly
Central Training Institute for Instructors), offer the CITS course, which is mandated
by the Directorate General of Training (DGT).
vii
ACKNOWLEDGEMENT
National Instructional Media Institute (NIMI) sincerely acknowledges with thanks for the
co-operation and contribution extended by the following experts to bring out this Instructional
material (Trade Practical) for CITS Computer Software Application (Volume - I of II)
(NSQF Level - 5) under the IT & ITES Sector for Instructors.
COORDINATORS
NIMI records its appreciation of the Data Entry, CAD, DTP Operators for their excellent and
devoted services in the process of development of this Instructional Material.
NIMI also acknowledges with thanks, the invaluable efforts rendered by all other staff who have
contributed for the development of this Instructional Material.
NIMI is grateful to all others who have directly or indirectly helped in developing this IMP.
viii
ABOUT THE TEXT BOOK
G C Rama Murthy,
Joint Director,
Curriculum Development, DGT,
MSDE, New Delhi.
ix
CONTENT
Ex. No. Table of Contents Page No.
x
Ex. No. Table of Contents Page No.
xi
Ex. No. Table of Contents Page No.
55 Demonstrateon Creating and deleting a file, Reading and writing text
files, working with directories in PHP, checking for existence of file,
determining file size, opening a file for writing, reading, or appending, 269
Writing Data to the file Reading characters
56 Work With Forms - Super global variables the server array A script to
acquire user input, importing user input Accessing user input, Combine
HTML and PHP code., using hidden fields 283
57 Demonstrate redirecting the user, File upload and scripts. 291
58 Demonstrate Regular Expressions - The basic regular expressions, PCRE,
Matching patterns, Finding matches, Replace patterns, Modifiers, Breakup
Strings. 294
59 Demonstrate working with Classes And Objects - Creating an object,
Object properties, Object methods, Object constructors and destructors. 311
60 Perform class constants, Class inheritance Abstract classes and methods,
Object serialization, checking for class and method, existence, Exceptions,
Iterators 315
61 Creating and using Functions
329
62 Using Java Script with Forms
343
Module 5: Advanced Excel
63 Protect sheet using password 345
71 Perform form controls and create simple data entry form with macros 425
xii
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Ethernet cable • Wire stripper/cutter
• RJ 45 connector • LAN Tester
• Crimping tool • PCs/Laptops
Procedure
TASK 1: Crimping a straight through ethernet
cable
Straight through ethernet cables are the standard cable used for almost all purposes, and are often called “patch
cables”. It is highly recommend you duplicate the color order as shown on the below.
1
COMPUTER SOFTWARE APPLICATION - CITS
2
CITS : IT & ITES - Computer Software Application - Exercise 1
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop
• Cisco pocket tracee software
Procedure
TASK 1: Configure the Switch
Step 1: Open the packet tracer desktop and take a switch (PT-Switch) from the devices.
Step 2: Configure the Host name of the swicth0.
• Click on switch0 and go to Command Line Interface.
• Then change the hostname to “sh”
Command:
switch> switch>en
switch#conf t
switch(config)#hostname sh
sh(config)exit
Step 3: Set a message of the day (MOTD) banner for the users.
Command:
sh(config)#banner motd $
• Then, enter MOTD and end it with ‘$’ to exit.
3
COMPUTER SOFTWARE APPLICATION - CITS
4
CITS : IT & ITES - Computer Software Application - Exercise 2
COMPUTER SOFTWARE APPLICATION - CITS
5
CITS : IT & ITES - Computer Software Application - Exercise 2
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• 2 or more PC/Laptop connected to a network
• Printer
• Router
Procedure
Connecting two computers using LAN
TASK 1: Creating a LAN
1 Determine whether or not your computers have Ethernet ports.
2 Check to see if you have a crossover Ethernet cable.
3 Plug one end of the Ethernet cable in to one computer.
4 Plug the other end of the Ethernet cable in to the other computer.
5 Finish.
6
COMPUTER SOFTWARE APPLICATION - CITS
7
CITS : IT & ITES - Computer Software Application - Exercise 3
COMPUTER SOFTWARE APPLICATION - CITS
11 Click network. It‟s is near the bottom of the sidebar that is on the left of the file explorer
window. a You may have to scroll down in the file explorer‟s left-hand sidebar to see this
option.
12 Select a computer. Double-click the name of the computer from which the folder you want to open is being
shared.
13 Select a folder. Double-click the folder you want to open is being shared.
14 Enter a username and password if prompted. This will usually be the username and password used to log
into the computer which is sharing the folder. Doing so correctly will cause the folder to open.
a If a folder isn‟t protected, double clicking it will open it immediately.
15 Finish.
8
CITS : IT & ITES - Computer Software Application - Exercise 3
COMPUTER SOFTWARE APPLICATION - CITS
a) Click the start menu and select Control Panel. Windows 8 users can press Win and type “Control panel”.
b) Select “Devices and Printers” or “View Devices and Printers”.
c) Click Add a printer at the top of the window.
d) Select “Add network, Bluetooth printer”.
e) Select your network printer from the list and click Next.
f) Install the necessary drivers if prompted. Windows should be able to find and install the correct drivers for
most printers.
4 Printer to the network printer. Once you’ve added to the printer to the operating system, you can print it just
as you would a printer connected directly to your computer. Simply select the printer from the “Print” window
of any program.
a) Make sure that the printer is turned and that you are connected to the same network. That will save time
since the drivers won‟t have to be downloaded and installed separately on the other computers.
5 Finish.
9
CITS : IT & ITES - Computer Software Application - Exercise 3
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows PC/Laptop connected to a network
Procedure
1 Select Start, then select Settings > Network & Internet .
10
COMPUTER SOFTWARE APPLICATION - CITS
• When you select Automatic (DHCP), the IP address settings and DNS server address setting are set
automatically by your router or other access point (recommended).
• When you select Manual, you can manually set your IP address settings and DNS server address.
11
CITS : IT & ITES - Computer Software Application - Exercise 4
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows server
• PC/Laptop
• Network connection
Procedure
TASK 1: Install SNMP Agent and configure the community string
1 Open the Control Panel on your Windows machine.
2 Open the Programs and Features.
3 Select Turn Windows features on or off.
4 On Windows workstations (Windows 10) select Simple Network Management Protocol (SNMP) and install it.
5 On Windows Server 2016 and above you’ll have to click Next in the Add Roles and Features Wizard until you
reach the Features sections where you can install the SNMP Service.
12
COMPUTER SOFTWARE APPLICATION - CITS
Note : The system will automatically install SNMP Tools required by the service.
13
CITS : IT & ITES - Computer Software Application - Exercise 5
COMPUTER SOFTWARE APPLICATION - CITS
14
CITS : IT & ITES - Computer Software Application - Exercise 5
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows PC/Laptop
• Wireless router
Procedure
TASK 1: Wireless network design
1 When you power on the router, it will only generate its wi-fi network, and the device will be connected to the
router’s wi-fi connection, not the internet. To connect the router to the internet need a MAC address to the
internet service provider’s website.
2 The MAC address will display already the old one need to Reset the MAC address
15
COMPUTER SOFTWARE APPLICATION - CITS
4 Select the wireless network name and select the enable the wireless router radio and SSID broadcast
16
CITS : IT & ITES - Computer Software Application - Exercise 6
COMPUTER SOFTWARE APPLICATION - CITS
7 Gave old administrator name and password and a new username and password then click on save.
17
CITS : IT & ITES - Computer Software Application - Exercise 6
COMPUTER SOFTWARE APPLICATION - CITS
8 Open the WIFI portal see the name is displaying then click on connect.
9 Enter the password0r security key which was given before and click on next button.
18
CITS : IT & ITES - Computer Software Application - Exercise 6
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows enabled PC/Laptop
• Internet connectivity with VPN
• Skype software setup
Procedure
TASK 1: Planning and preparation
1 Assess your needs:
2 Determine how many users will need VoIP, what features you require (e.g., call forwarding, voicemail), and
your budget.
3 Test your internet connection:
4 Ensure your upload and download speeds are sufficient for VoIP calls (generally, at least 3 Mbps for both). You
can use online speed tests to check.
5 Choose a VoIP provider:
6 Select a provider that meets your needs and budget, offering reliable service and features you need.
7 Decide on hardware:
8 Consider whether you’ll use physical VoIP phones, softphones (software apps on computers), or a combination.
TASK 2: Installation
1 Follow your provider’s instructions:
2 Each provider will have specific setup steps, so refer to their documentation or website for detailed guidance.
3 Configure your network:
4 Depending on your setup, you may need to adjust firewall settings, enable Quality of Service (QoS) for VoIP
traffic prioritization, or configure a Virtual Private Network (VPN) for added security.
5 Set up your devices:
6 Connect your VoIP phones or install the softphone app on your devices. Configure settings like your phone
number, voicemail, and call forwarding.
19
COMPUTER SOFTWARE APPLICATION - CITS
20
CITS : IT & ITES - Computer Software Application - Exercise 7
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop
• Windows server
• Internet connectivity
Procedure
TASK 1: Installing DHCP Server
1 Open Server Manager from task bar and click Add roles and features
2 Before you run the installation wizard, make sure that an administrator account has a strong password, static
IP is configured, and security updates from Windows updates are installed. When you are done, click Next
21
COMPUTER SOFTWARE APPLICATION - CITS
4 Select a destination server on which you want to install the DHCP server. In our case, there is only one server
which is local server and it is selected by default. Click Next
5 Select DHCP server role by checking the appropriate box. As soon as you check the box, a small window
will pop up alerting you that there are some other features which are also required to be installed along with
DHCP server. Click Add Features
22
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
6 Click Next
7 Click Next
23
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
24
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
2 Click Next
3 Choose Skip AD authorization since we do not have any AD configured and click Commit
25
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
5 Open Server Manager and click on Tools. When a small window appear, scroll to DHCP and click it
6 In management console, right click on IPv4 and scroll to New Scope and click it.
7 Click Next
26
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
8 Provide name and meaningful description of this new scope and click Next
9 Provide IP address range along with sub net you need to distribute to client machines and click Next
10 Provide any IP addresses you need to exclude from pool and click Add. I have excluded a first IP address
which is statically assigned to my DHCP server. Click Next
27
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
12 Choose No, I will configure these options later and click Next
28
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
14.Right-click on new scope you just created in above step and click Activate
15 Right-click on your server, scroll to All Tasks and then click Restart to finish with configuration
29
CITS : IT & ITES - Computer Software Application - Exercise 8
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC laptop with network connectivity
• Firewall
• Routers
Procedure
TASK 1: Implement a Firewall
1 Choose a firewall: Select a firewall suitable for your network size and needs. Hardware firewalls offer
robust protection, while software firewalls are more cost-effective for smaller networks.
2 Configure firewall rules: Define rules to allow only authorized traffic and block suspicious connections.
Consider factors like source IP addresses, destination ports, and protocols.
3 Enable logging and monitoring: Regularly review firewall logs to identify potential threats and adjust rules
accordingly.
30
COMPUTER SOFTWARE APPLICATION - CITS
31
CITS : IT&ITES - Computer Software Application - Exercise 9
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC laptop with network connectivity
Procedure
Setting up a password policy in a network is an essential security measure to protect sensitive information and
resources from unauthorized access.
Implement a password policy
1 Assessment: Begin by assessing the current state of password security within your network. Understand
the existing password practices, weaknesses, and areas that need improvement.
2 Define Password Requirements: Determine the password requirements that users must adhere to. These
requirements typically include:
• Minimum password length: Suggest a minimum length of 8-12 characters.
• Complexity: Require a combination of uppercase letters, lowercase letters, numbers, and special
characters.
• Expiry: Set a policy for password expiration, such as every 90 days.
• History: Enforce a rule that prevents users from reusing old passwords.
• Lockout: Establish a threshold for failed login attempts before an account is locked out temporarily.
• Account Inactivity: Consider disabling or prompting for password change after a certain period of inactivity.
• Two-Factor Authentication (2FA): Encourage or mandate the use of 2FA where possible for an added
layer of security.
3 Communicate Policy: Clearly communicate the password policy to all users within the network. Explain the
rationale behind each requirement and the importance of adhering to them.
4 Implement Policy: Utilize the network’s administrative tools or security software to enforce the password
policy. This may involve configuring settings in:
• Active Directory (for Windows networks)
• Group Policy (for Windows networks)
• LDAP (Lightweight Directory Access Protocol)
• RADIUS (Remote Authentication Dial-In User Service)
• IAM (Identity and Access Management) solutions
• Password management tools
5 Enforcement: Regularly monitor adherence to the password policy. Implement mechanisms to enforce the
policy automatically, such as system prompts for password changes when they expire, or locking out
accounts after multiple failed login attempts.
6 Education and Training: Conduct training sessions or provide resources to educate users about the
importance of strong passwords, how to create them securely, and the consequences of weak password
practices.
7 Periodic Review and Update: Regularly review the password policy to ensure it remains effective and up-
to-date with evolving security threats and best practices. Make necessary adjustments based on feedback,
security incidents, or changes in regulations.
8 Testing: Periodically conduct security audits or penetration tests to evaluate the effectiveness of the
password policy and identify any vulnerabilities that need to be addressed.
32
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows PC/Laptop connected to a network
• Wireshark network setup
Procedure
TASK 1: Using Wireshark , a packet-sniffing tool
1 Open Wireshark. If you don’t have the free program for Windows, Mac, and Linux, you can download it from
their website.
2 Navigate to “Edit” and click Preferences. You’ll find “Edit” in the menu bar along the top of the Wireshark
window.
3 Click the Capture tab. It’s in the panel on the left side of the window.
33
COMPUTER SOFTWARE APPLICATION - CITS
6 Click the blue fin icon to start recording. You can also press Ctrl + E. You’ll see a graph that indicates your
network activity.
7 Press the red fin icon to stop recording. You’ll see the previous history in the window at the top of your screen.
8 Click on an instance to see the IP addresses it was going to and coming from as well as additional data.
34
CITS : IT&ITES - Computer Software Application - Exercise 11
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows PC/Laptop connected to internet
Procedure
TASK 1: IP Spoofing using Hide.me
1 Download Hide.me VPN Software and install it.
2 Click “Enable VPN” button to enable the Virtual private network and your ip address will change.
3 Click on “Change” button in the right side of the window to set the country location for the IP Address.
4 Goto Cmd Prompt and type the command “ipconfig” then we will get the latest IP Address.
5 On Click “Details” button in the left side of the window. We are able to see the location is changed to
Netherlands. But our actual location is India.
35
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop
• Kali Linux OS
• Ettercap
Procedure
TASK 1: DNS Spoofing using Ettercap
1 Start by booting up Kali Linux
Note: before you continue and make sure that you are on the same network as your target.
2 Open the file /etc/ettercap/etter.conf with a text editor like gedit and edit the file.
3 Edit the uid and gid values at the top to make them 0.
4 Remove both the # signs below where it says “if you use iptables”.
36
COMPUTER SOFTWARE APPLICATION - CITS
6 Select Sniff > Unified sniffing… > (Select the interface connected to the internet) > OK it automatically starts
sniffing after we press OK
7 To scan for targets on your network go to Hosts > Scan for hosts and wait until it does the scan.
8 Go back to Hosts and select Host list to see all the targets that Ettercap has found.
9 Select IP address from the host list in Ettercap and choose Add to Target 1
10 Now select the gateway IP from the host list and choose Add to Target 2.
37
CITS : IT&ITES - Computer Software Application - Exercise 13
COMPUTER SOFTWARE APPLICATION - CITS
11 Go to the MITM tab and select ARP poisoning, choose Sniff remote connections and press OK.
12 go to Plugins > Manage the plugins and double click dns_spoof to activate that plugin.
13 Edit etter.dns file, This is the hosts file and is responsible for redirecting specific DNS requests.
14 Add another line, use whatever website you would like and change the IP address to your IP address.(Here
example facebook is used).
16 Go to /var/www/html folder and alter index.html page for your needs and save the page.
17 Go back to Ettercap and select Start > Start sniffing and that to start the attack.
38
CITS : IT&ITES - Computer Software Application - Exercise 13
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Linux PC/Laptop with internet connection
• Password cracking tools John the Ripper,
Hashcat, Hydra
Procedure
Password cracking involves attempting to gain unauthorized access to a system or an account by trying to
decipher or guess the password. There are several methods for password cracking, including dictionary
attacks, brute-force attacks, and hybrid attacks. Here are practical steps for each method:
TASK 1: Dictionary Attack
1 Gather Wordlists: Obtain a comprehensive wordlist or dictionary containing commonly used passwords,
phrases, and combinations.
2 Select Tools: Choose a password cracking tool that supports dictionary attacks, such as John the Ripper,
Hashcat, or Hydra.
3 Configure Tool: Set up the password cracking tool to use the selected wordlist as input.
4 Execute Attack: Run the tool against the target system or account, attempting to log in with each password
in the dictionary.
5 Analyze Results: Review the output to identify successful password guesses and gain access to the target
account.
2 Select Tools: Choose a password cracking tool capable of brute-force attacks, such as John the Ripper,
Hashcat, or Hydra.
3 Configure Tool: Set up the password cracking tool to systematically generate and try all possible
combinations of characters within the specified parameters.
4 Execute Attack: Run the tool against the target system or account, attempting to guess the password
through exhaustive trial and error.
5 Monitor Progress: Monitor the progress of the brute-force attack, as it may take significant time and
computational resources.
6 Analyze Results: Review the output to identify successful password guesses and gain access to the target
account.
39
COMPUTER SOFTWARE APPLICATION - CITS
2 Select Tools: Choose a password cracking tool that supports hybrid attacks, such as John the Ripper,
Hashcat, or Hydra.
3 Configure Tool: Set up the password cracking tool to use the hybrid wordlist as input, along with
parameters for brute-force generation.
4 Execute Attack: Run the tool against the target system or account, attempting to guess the password using
both dictionary-based and brute-force methods.
5 Adjust Parameters: Fine-tune the attack parameters based on initial results and feedback to optimize the
cracking process.
6 Analyze Results: Review the output to identify successful password guesses and gain access to the target
account.
7 Additional Considerations:
b Legal and Ethical Considerations: Ensure that password cracking activities comply with applicable
laws, regulations, and ethical guidelines.
c Defensive Measures: Implement strong password policies, multi-factor authentication, and other
security measures to protect against password cracking attempts.
40
CITS : IT&ITES - Computer Software Application - Exercise 14
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with network connectivity
• Firewall & VPN
Procedure
TASK 1: Handling DoS During a Attack
1 Identify the Attack: The first step is to recognize a DoS attack. Signs include unusually slow network
performance, website outages, or specific applications being unavailable.
2 Isolate the Attack: Try to isolate the affected system or service to minimize the impact on the entire
network. Firewalls and traffic filtering rules can be helpful here.
3 Activate DDoS Defense Mechanisms: Many network devices like routers have built-in DDoS protection
features. These may include rate limiting, which restricts incoming traffic volume, or blackholing malicious IP
addresses.
4 Contact Your Service Provider: If you suspect a large-scale DDoS attack, especially for businesses or
organizations, your internet service provider (ISP) can offer more advanced mitigation techniques and
resources.
5 Analyze and Adapt: Once the immediate attack subsides, analyze logs and traffic patterns to understand
the attack type. This will help refine your mitigation strategies for future attacks.
3 Utilize DDoS Mitigation Services: Consider subscribing to DDoS protection services offered by security
vendors. These services can filter malicious traffic before it reaches your network.
4 Content Delivery Networks (CDNs): CDNs can absorb large traffic spikes and distribute legitimate traffic
more efficiently.
5 Educate Users: Train employees on potential social engineering tactics hackers use to launch DoS attacks
via phishing emails or malware.
NOTE: DoS mitigation strategies depend on the specific attack type and the resources available.
41
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC with network connectivity
• John the Ripper Password cracker tool
• Operating system, Windows/LInux Cain & Abel
tool setup
Procedure
TASK 1: Using tool Cain &Abel
1 Download the Cain&Abel zip file from any browser.
2 Follow the installation instructions, proceeding by clicking “Next,” accepting the terms, and concluding by
selecting “Finish” at the end.
3 To install this tool, WinPcap also need. Click “Install” and then follow the setup steps as instructed by the
wizard.
42
COMPUTER SOFTWARE APPLICATION - CITS
6 Click on the “+” symbol, then select “Import Hashes.” Check the corresponding box and proceed by clicking
“Next.”
7 Choose the account for which you want to crack the password. Right-click on it, then opt for a brute force
attack. Within the attack options, select NTLM hashes.
43
CITS : IT&ITES - Computer Software Application - Exercise 16
COMPUTER SOFTWARE APPLICATION - CITS
8 Specify the Charset, Password length and then click on “Start”. It will start making combinations and take
some time to crack hashes.
44
CITS : IT&ITES - Computer Software Application - Exercise 16
COMPUTER SOFTWARE APPLICATION - CITS
Note: type john followed by the hash file that you want to crack and then just define the
format of the hash.
2 Generate a hash of our zip file using the command sudo zip2john techofide.zip > hash.txt.
3 Use hash of our zip file and apply the command sudo john --format=zip hash.txt to crack the password.
45
CITS : IT&ITES - Computer Software Application - Exercise 16
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Windows PC/Laptop with internet connectivity
Procedure
TASK 1: Set Up the Windows Firewall
1 Open the Control Panel.
5 To change the setting, click the Turn Windows Firewall “On” or “Off” link on the left side of the Windows
Firewall window.
3 Click the “Windows Firewall” option on the top of the search window.
4 “Private networks” and “Guest or public networks” with green shields to the left of them, signifying that the
firewall is active.
46
COMPUTER SOFTWARE APPLICATION - CITS
c ”Connection Security Rules” - Baselines for which connections your computer will allow and which ones it
will block.
47
CITS : IT&ITES - Computer Software Application - Exercise 17
COMPUTER SOFTWARE APPLICATION - CITS
48
CITS : IT&ITES - Computer Software Application - Exercise 17
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Operating System: Windows 10 or 11 (64-bit)
• MySQL Setup Software
• Desktop/Laptop will latest configuration
Procedure
Installation Methods
TASK 1 : Download MySQL
Step 1: Go to the official website of MySQL and download the community server edition software. Here, you will
see the option to choose the Operating System, such as Windows.
Step 2: Next, there are two options available to download the setup. Choose the version number for the MySQL
community server, which you want. If you have good internet connectivity, then choose the mysql-installer-web-
community. Otherwise, choose the other one.
49
COMPUTER SOFTWARE APPLICATION - CITS
Step 3: Once we click on the Next button, it may give information about some features that may fail to install on
your system due to a lack of requirements. We can resolve them by clicking on the Execute button that will
install all requirements automatically or can skip them. Now, click on the Next button.
Step 4: In the next wizard, we will see a dialog box that asks for our confirmation of a few products not getting
installed. Here, we have to click on the Yes button.
50
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
After clicking on the Yes button, we will see the list of the products which are going to be installed. So, if we
need all products, click on the Execute button.
Step 5: Once we click on the Execute button, it will download and install all the products. After completing the
installation, click on the Next button.
Step 6: In the next wizard, we need to configure the MySQL Server and Router. Here, I am not going to
configure the Router because there is no need to use it with MySQL. We are going to show you how to
configure the server only. Now, click on the Next button.
51
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
Step 7: As soon as you will click on the Next button, you can see the screen below. Here, we have to configure
the MySQL Server. Now, choose the Standalone MySQL Server/Classic MySQL Replication option and click on
Next. Here, you can also choose the InnoDB Cluster based on your needs.
Step 8: In the next screen, the system will ask you to choose the Config Type and other connectivity options.
Here, we are going to select the Config Type as ‘Development Machine’ and Connectivity as TCP/IP, and Port
Number is 3306, then click on Next.
52
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
Step 9: Now, select the Authentication Method and click on Next. Here, I am going to select the first option.
Step 10: The next screen will ask you to mention the MySQL Root Password. After filling the password details,
click on the Next button.
Step 11: The next screen will ask you to configure the Windows Service to start the server. Keep the default setup
and click on the Next button.
53
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
Step 12: In the next wizard, the system will ask you to apply the Server Configuration. If you agree with this
configuration, click on the Execute button.
Step 13: Once the configuration has completed, you will get the screen below. Now, click on the Finish button to
continue.
54
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
Step 14: In the next screen, you can see that the Product Configuration is completed. Keep the default setting
and click on the Next-> Finish button to complete the MySQL package installation.
Step 15: In the next wizard, we can choose to configure the Router. So click on Next->Finish and then click the
Next button.
Step 16: In the next wizard, we will see the Connect to Server option. Here, we have to mention the root password,
which we had set in the previous steps.
55
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
It is also required to check about the connection is successful or not by clicking on the Check button. If the
connection is successful, click on the Execute button. Now, the configuration is complete, click on Next.
Step 17: In the next wizard, select the applied configurations and click on the Execute button.
Step 18: After completing the above step, we will get the following screen. Here, click on the Finish button.
Step 19: Now, the MySQL installation is complete. Click on the Finish button.
56
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
57
CITS : IT & ITES - Computer Software Application - Exercise 18
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Operating System: Windows 10 or 11 (64-bit)
• MySQL Setup Software
• Desktop/Laptop will latest configuration
Procedure
Troubleshooting Basic Installation Issues in MySQL on Windows:
TASK 1 : Check Error Logs
• Location: The default location for the error log is C:\ProgramData\MySQL\MySQL Server 8.0\data\
mysql.err.
• Analysis: Open the error log and search for specific error messages. Here are some common errors and their
meanings:
• Access denied: Check the root password or permissions related to data directories.
• Port conflicts: Another program might be using the default port (3306). Disable conflicting programs or
change the MySQL port.
• Missing files or directories: Verify that all installation files are present and in the correct locations.
• Configuration errors: Double-check your configuration settings in my.ini based on your specific setup.
TASK 2 : Verify Installation Status
• Open the “Services” app: On Windows 10,
• press Win+R, type services.msc, and press Enter.On Windows 11,
• right-click the Start button, select “Settings”, then “Apps & features”, and scroll down to “Optional features”.
• Under “More Windows features”, click “Add features”. Look for “MySQL Server” and install it if not already
present.
• Check the status: In the “Services” app, locate “MySQL80” (or your version number) and check its status. If
it’s not running, try starting it manually.
TASK 3 : Address Common Issues
• Insufficient Permissions: Ensure the MySQL service has the necessary permissions to access its data
directories and files.
• Antivirus/Firewall Interference: Temporarily disable antivirus or firewall software to see if it’s blocking MySQL.
• Incorrect Data Directory: Verify the data directory path in the my.ini file matches the actual location.
• Missing Visual C++ Redistributables: Install the correct version of Visual C++ Redistributables,
downloadable from Microsoft’s website.
58
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Operating System: Windows 10 or 11 (64-bit)
• MySQL Setup Software
• Desktop/Laptop will latest configuration
Procedure
TASK 1 : Creating and Using a Database in MySQL
1 Open the MySQL Command Line Client:
Windows: Search for “MySQL Shell” or “mysql.exe” in the Start menu.
macOS/Linux: Open a terminal and type mysql (if installed globally) or path/to/your/mysql/bin/mysql.
59
COMPUTER SOFTWARE APPLICATION - CITS
3 Create a Database:
Use the CREATE DATABASE command:
CREATE DATABASE database name;
Replace database name with the desired name for your database (e.g., employeedb).
60
CITS : IT & ITES - Computer Software Application - Exercise 20
COMPUTER SOFTWARE APPLICATION - CITS
SQL
CREATE TABLE table name (
column1 name data type PRIMARY KEY,
column2 name data type,
column3 name data type,
...
);
Replace:
table name with the desired name for your table (e.g., employee table).
column name with the names of each data column.
data type with the appropriate data type for each column (e.g., INT, VARCHAR, DATE).
PRIMARY KEY specifies the unique identifier for each row (usually an auto-incrementing
INT).
6 Insert Data:
Use the INSERT INTO command:
INSERT INTO table name (column1 name, column2 name, column3 name)
VALUES (value1, value2, value3);
Replace:
table name with the name of your table.
column name with the names of the columns you want to insert data into.
value with the actual data for each column (e.g., numbers, strings, dates).
7 Retrieve Data:
Use the SELECT command:
SELECT * FROM table name;
This retrieves all data from the table.
You can modify the SELECT command to specify specific columns or filter data based on conditions.
61
CITS : IT & ITES - Computer Software Application - Exercise 20
COMPUTER SOFTWARE APPLICATION - CITS
8 Modify Data:
Use the UPDATE command:
UPDATE table name SET column name = new value WHERE condition;
Replace:
table name with the name of your table.
column name with the name of the column you want to update.
new value with the new data for the column.
condition specifies which rows to update (e.g., WHERE id = 1).
9 Delete Data:
Use the DELETE FROM command:
DELETE FROM table name WHERE condition;
Replace:
table name with the name of your table.
condition specifies which rows to delete (e.g., WHERE age > 30).
62
CITS : IT & ITES - Computer Software Application - Exercise 20
COMPUTER SOFTWARE APPLICATION - CITS
10 Exit MySQL:
Type exit or quit to disconnect from the server.
63
CITS : IT & ITES - Computer Software Application - Exercise 20
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Operating System: Windows 10 or 11 (64-bit)
• MySQL Setup Software
• Desktop/Laptop will latest configuration
Procedure
TASK 1 : Creating Table, Insert values and retrieve data from that table
Step 1: Open MySQL Command Line:
Go to the Start menu, find MySQL, and open the MySQL Command Line client.
Step 2: Login to MySQL Server:
Enter the following command and press Enter. Replace username with your MySQL username, and you’ll be
prompted to enter your password.
mysql -u username –p
64
COMPUTER SOFTWARE APPLICATION - CITS
65
CITS : IT & ITES - Computer Software Application - Exercise 21
COMPUTER SOFTWARE APPLICATION - CITS
66
CITS : IT & ITES - Computer Software Application - Exercise 21
COMPUTER SOFTWARE APPLICATION - CITS
67
CITS : IT & ITES - Computer Software Application - Exercise 21
COMPUTER SOFTWARE APPLICATION - CITS
Create a table named CSA (Roll No., Stu name, Father Name, DOB, Adress, Phone No., Email) and insert 10
values in it.
68
CITS : IT & ITES - Computer Software Application - Exercise 21
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : Applying data intergrity rules
1 Start MySQL Server: start the MySQL server. You can do this by going to the Services application in
Windows, finding MySQL service, and starting it.
2 Access MySQL: Open the MySQL command line client or a GUI tool like MySQL Workbench to access your
MySQL server.
69
COMPUTER SOFTWARE APPLICATION - CITS
CHECK: Define custom conditions for valid data (e.g., age must be positive).
4 Create a Database: Use the following SQL command to create a new database:
CREATE DATABASE your database name;
Use the Database: Switch to the newly created database using the following command:
USE your database name;
5 Create Tables: Create the tables for which you want to apply data integrity rules. For
example: CREATE TABLE departments (
id INT AUTO INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
CREATE TABLE employees (
id INT AUTO INCREMENT PRIMARY KEY,
name VARCHAR(100),
department id INT,
FOREIGN KEY (department id) REFERENCES departments(id)
);
In this example, the employees table has a foreign key constraint referencing the id column of the departments
table.
6 Insert Data: Insert some data into the tables you’ve created. Make sure to maintain referential
integrity: INSERT INTO departments (name) VALUES (‘HR’), (‘IT’), (‘Finance’);
INSERT INTO employees (name, department id) VALUES (‘John’, 1), (‘Jane’, 2), (‘Doe’, 3);
70
CITS : IT & ITES - Computer Software Application - Exercise 22
COMPUTER SOFTWARE APPLICATION - CITS
7 Test Data Integrity: Try to insert data that violates the integrity rules you’ve defined. For example, try to
insert an employee with a department id that doesn’t exist:
INSERT INTO employees (name, department id) VALUES (‘Adam’, 10);
You should get an error because the department id 10 doesn’t exist in the departments table.
Update and Delete Data: When updating or deleting data, make sure to maintain referential integrity by updating
or deleting related records appropriately.
Review and Modify Rules: Regularly review your data integrity rules and modify them as necessary to ensure
they continue to meet the requirements of your application.
We can use the graphical interface of phpMyAdmin to manage tables and constraints.
71
CITS : IT & ITES - Computer Software Application - Exercise 22
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Accessing MySQL:
MySQL Workbench: Download and install the graphical user interface (GUI) for MySQL management.
Command Prompt: Open the Command Prompt and navigate to the MySQL installation directory (e.g., C:\
Program Files\MySQL\MySQL Server 8.0\bin).
Connecting to the Database:
MySQL Workbench: Provide your server hostname, username, password, and database name to connect.
Command Prompt: Use the mysql command followed by your credentials (e.g., mysql -h localhost -u root -p).
72
COMPUTER SOFTWARE APPLICATION - CITS
4 Drop Table:
DROP TABLE employees;
73
CITS : IT & ITES - Computer Software Application - Exercise 23
COMPUTER SOFTWARE APPLICATION - CITS
3 Create User:
CREATE USER ‘new user’@’localhost’ IDENTIFIED BY ‘user password’;
4 Drop User:
DROP USER ‘new user’@’localhost’;
74
CITS : IT & ITES - Computer Software Application - Exercise 23
COMPUTER SOFTWARE APPLICATION - CITS
75
CITS : IT & ITES - Computer Software Application - Exercise 23
COMPUTER SOFTWARE APPLICATION - CITS
76
CITS : IT & ITES - Computer Software Application - Exercise 23
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : Access MySQL:
MySQL Workbench: Download and install the user-friendly GUI for database management.
Command Prompt: Open the Command Prompt and navigate to the MySQL installation directory (e.g., C:\
Program Files\MySQL\MySQL Server 8.0\bin).
Connect to your Database:
MySQL Workbench: Enter your server hostname, username, password, and database name to connect.
Command Prompt: Use the mysql command followed by your credentials (e.g., mysql -h localhost -u root -p).
77
COMPUTER SOFTWARE APPLICATION - CITS
Ensure that each table’s primary key constraint is enforced. MySQL automatically enforces primary key constraints,
preventing the insertion of duplicate keys.
3 ON DELETE/UPDATE Actions: Specify how the database reacts when data in the parent table is modified
(e.g., ON DELETE SET NULL sets foreign key to null, ON DELETE CASCADE deletes related rows).
4 CHECK Constraints: Define custom conditions for valid data (e.g., age must be positive).
78
CITS : IT & ITES - Computer Software Application - Exercise 24
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : Access MySQL:
MySQL Workbench: Download and install the GUI for user-friendly management.
Command Prompt: Open it and navigate to the MySQL installation directory (e.g., C:\Program Files\MySQL\ MySQL
Server 8.0\bin).
Connect to your Database:
MySQL Workbench: Provide your server hostname, username, password, and database name.
Command Prompt: Use the mysql command followed by your credentials (e.g., mysql -h localhost -u root -p).
Identify Columns for Indexing:
Choose columns frequently used in WHERE clauses, ORDER BY, or JOINs. Consider data types and selectivities
(percentage of unique values).
Use the Database:
USE your database name;
79
COMPUTER SOFTWARE APPLICATION - CITS
80
CITS : IT & ITES - Computer Software Application - Exercise 25
COMPUTER SOFTWARE APPLICATION - CITS
81
CITS : IT & ITES - Computer Software Application - Exercise 25
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Using select queries:
1 Select all columns from a table:
SELECT * FROM your table name;
82
COMPUTER SOFTWARE APPLICATION - CITS
83
CITS : IT & ITES - Computer Software Application - Exercise 26
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Using next query
1 Create database:
Create database database name:
Use database:
Use database name;
2 Create Table:
CREATE TABLE your table name
( column1 datatype1,
column2 datatype2,
column3 datatype3,
-- add more columns as needed
PRIMARY KEY (column1)
);
Ex:
CREATE TABLE `employee` (
`employee id` bigint unsigned NOT NULL AUTO INCREMENT,
`first name` varchar(45) NOT NULL,
`last name` varchar(45) NOT NULL,
`last update` timestamp NOT NULL DEFAULT CURRENT
TIMESTAMP, UNIQUE KEY `employee id` (`employee id`)
);
84
COMPUTER SOFTWARE APPLICATION - CITS
To find the structure of a table called employee, you can use the MySQL DESCRIBE command:
DESCRIBE employee;
85
CITS : IT & ITES - Computer Software Application - Exercise 27
COMPUTER SOFTWARE APPLICATION - CITS
86
CITS : IT & ITES - Computer Software Application - Exercise 27
COMPUTER SOFTWARE APPLICATION - CITS
The return value here indicates that the DELETE command was processed with a single row being removed.
Using DELETE to remove multiple rows at once
87
CITS : IT & ITES - Computer Software Application - Exercise 27
COMPUTER SOFTWARE APPLICATION - CITS
2 You can remove multiple items at once with DELETE by manipulating the selection criteria specified
in the WHERE clause.
For instance, to remove multiple rows by ID, you could type something like this:
Ex - DELETE FROM employee
WHERE employee id in (3,4);
3 You can even leave out the WHERE clause to remove all of the rows from a given table:
DELETE FROM employee;
Questions
1 How can you insert multiple records in a single query?
2 How can you update multiple columns in a single query?
3 How do you delete a specific record from a table?
88
CITS : IT & ITES - Computer Software Application - Exercise 27
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Using Number Functions:
1 ABS() – Absolute Value:
SELECT ABS(-15);
-- Result: 15
2 ROUND() - Round to specified numbers of decimal places.
SELECT ROUND(123.456, 2);
-- Result: 123.46
89
COMPUTER SOFTWARE APPLICATION - CITS
90
CITS : IT & ITES - Computer Software Application - Exercise 28
COMPUTER SOFTWARE APPLICATION - CITS
91
CITS : IT & ITES - Computer Software Application - Exercise 28
COMPUTER SOFTWARE APPLICATION - CITS
92
CITS : IT & ITES - Computer Software Application - Exercise 28
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Setup & Connect To MySQL:
Make sure you have MySQL installed on your Windows machine. You can use a tool like MySQL Command-
Line Client or a graphical interface like MySQL Workbench.
mysql -u your username –p
93
COMPUTER SOFTWARE APPLICATION - CITS
94
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
95
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
96
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
97
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
98
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
99
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
100
CITS : IT & ITES - Computer Software Application - Exercise 29
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : INDEXING:
1 Open MySQL Command Line-
Open the MySQL Command Line or any MySQL client that allows you to execute SQL commands.
2 Connect to your database-
mysql -u your username p
Enter your password when prompted
3 Select Your Database-
USE your database name;
Identify the column to be indexed
Let’s assume you want to create an index on a column named example column in a table named your table.
4 Create the Index-
CREATE INDEX idx example column ON your table(example column);
5 Verify the Index-
SHOW INDEX FROM your table;
This command displays information about the indexes on the specified table. You should see the newly created
index in the output
Example Output –
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+-----------
-+---------+--------------+
| Table | Non unique | Key name | Seq in index | Column name | Collation | Cardinality | Sub part | Packed
| Null | Index type | Comment | Index comment |
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+-----------
-+---------+--------------+
| your table | 1 | idx example column | 1 | example column | A | 0| NULL | NULL |
YES | BTREE | | |
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+-----------
-+---------+--------------+
101
COMPUTER SOFTWARE APPLICATION - CITS
In this output, you can see information about the index, including its name (idx example column), the indexed
column (example column), and the index type (BTREE).
Test the query performance
After creating the index, you can test the performance of queries involving the indexed column to see if there is
an improvement in retrieval speed.
102
CITS : IT & ITES - Computer Software Application - Exercise 30
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Create and use stored procedure
103
COMPUTER SOFTWARE APPLICATION - CITS
104
CITS : IT & ITES - Computer Software Application - Exercise 31
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Create & execute triggers
105
COMPUTER SOFTWARE APPLICATION - CITS
106
CITS : IT & ITES - Computer Software Application - Exercise 32
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 :Create cursors in MySQL
107
COMPUTER SOFTWARE APPLICATION - CITS
108
CITS : IT & ITES - Computer Software Application - Exercise 33
COMPUTER SOFTWARE APPLICATION - CITS
109
CITS : IT & ITES - Computer Software Application - Exercise 33
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : Using a cursor in MySQL
110
COMPUTER SOFTWARE APPLICATION - CITS
111
CITS : IT & ITES - Computer Software Application - Exercise 34
COMPUTER SOFTWARE APPLICATION - CITS
112
CITS : IT & ITES - Computer Software Application - Exercise 34
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : The process of securing MySQL.
113
COMPUTER SOFTWARE APPLICATION - CITS
114
CITS : IT & ITES - Computer Software Application - Exercise 35
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• create simple application on database using SP Triggers cursors & indexing
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• Operating system: window 10:11
• XAMPP server r3.3.0
Procedure
TASK 1 : Creating a simple application using stored procedures, triggers, cursors, and indexing in MySQL
1 CREATE DATABASE –
CREATE DATABASE library db;
USE library db;
2 CREATE TABLES –
Create table books and users -
CREATE TABLE books (
book id INT PRIMARY KEY AUTO INCREMENT,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
quantity INT NOT NULL
);
CREATE TABLE users (
user id INT PRIMARY KEY AUTO INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL
);
3 INSERT VALUES –
INSERT INTO books (title, author, quantity) VALUES
(‘Book 1’, ‘Author 1’, 5),
(‘Book 2’, ‘Author 2’, 8),
(‘Book 3’, ‘Author 3’, 3);
INSERT INTO users (name, email) VALUES
(‘User 1’, ‘[email protected]’),
(‘User 2’, ‘[email protected]’);
115
COMPUTER SOFTWARE APPLICATION - CITS
4 STORED PROCEDURE –
DELIMITER //
CREATE PROCEDURE GetBooksByAuthor(IN authorName VARCHAR(255))
BEGIN
SELECT * FROM books WHERE author = authorName;
END //
DELIMITER ;
TRIGGER –
DELIMITER //
CREATE TRIGGER AfterBookBorrowed
AFTER INSERT ON borrowed books
FOR EACH ROW
BEGIN
UPDATE books
SET quantity = quantity - 1
WHERE book id = NEW.book
id;
END //
DELIMITER ;
5 CURSOR –
DELIMITER //
CREATE PROCEDURE DisplayBooksAndQuantities()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE book title VARCHAR(255);
DECLARE book quantity INT;
DECLARE books cursor CURSOR FOR
SELECT title, quantity FROM books;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN books cursor;
read loop: LOOP
FETCH books cursor INTO book title, book
quantity; IF done THEN
LEAVE read loop;
END IF;
SELECT CONCAT(book title, ‘: ‘, book quantity) AS BookInfo;
END LOOP;
CLOSE books cursor;
END //
DELIMITER ;
116
CITS : IT & ITES - Computer Software Application - Exercise 36
COMPUTER SOFTWARE APPLICATION - CITS
6 INDEXING –
CREATE INDEX idx email ON users(email);
7 TESTING –
-- Test Stored Procedure
CALL GetBooksByAuthor(‘Author 1’);
-- Test Trigger (Assuming you have a ‘borrowed books’ table)
INSERT INTO borrowed books (user id, book id) VALUES (1,
1);
-- Test Cursor
CALL DisplayBooksAndQuantities();
-- Test Indexing
SELECT * FROM users WHERE email = ‘[email protected]’;
Question
1 How would you call the InsertUser stored procedure to add a new user with the username “nsti” and email
“[email protected]” to the database?
2 Explain the purpose of the before insert user trigger. How does it modify the incoming data before insertion
into the users table?
3 What does the DisplayUsers procedure do, and how would you execute it to see the details of all users in
the users table?
4 Describe the purpose of the idx username index on the users table. How does it improve query performance?
117
CITS : IT & ITES - Computer Software Application - Exercise 36
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
118
COMPUTER SOFTWARE APPLICATION - CITS
119
CITS : IT & ITES - Computer Software Application - Exercise 37
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• crease variables
• use operators
• use operators
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Using Variables
I Declaring variables and assigning values
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Declaring variables and assigning values </title>
</head>
<body>
<script>
// Declaring variables
let x; // Declaration without initialization
let y = 5; // Declaration with initialization
// Assigning values to variables
x = 10;
// Printing variables
console.log(“Value of x:”, x); // Output: 10
console.log(“Value of y:”, y); // Output: 5
// Reassigning variables
x = 20;
y = 8;
console.log(“Updated value of x:”, x); // Output: 20
120
COMPUTER SOFTWARE APPLICATION - CITS
121
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
122
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
123
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
124
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
125
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
126
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
127
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
128
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
129
CITS : IT & ITES - Computer Software Application - Exercise 38
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• use different types if conditional statements
• use different types of loop statements.
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Using if statement
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> if statement </title>
</head>
<body>
<script>
let age = 20;
if (age >= 18)
{
console.log(“You are eligible to vote.”);
}
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Go to the browsers console tab and verify the output.
130
COMPUTER SOFTWARE APPLICATION - CITS
131
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
132
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
133
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
134
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
135
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
136
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
137
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
138
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
139
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
1 Write a JavaScript program that takes a person’s age as input and determines whether they are eligible for
voting. If the age is 18 or above, the function should return “Eligible for voting,” otherwise, it should return
“Not eligible for voting.” Use if-else statements to implement the logic
2 Develop a JavaScript program that takes a year as input and determines whether it is a leap year or not. If
the year is divisible by 4 but not by 100, or if it is divisible by 400, it is considered a leap year.
3 Write a JavaScript program that takes two numbers as input and display the maximum of the two. Use if-else
statements to implement the comparison.
4 Create a JavaScript program that takes a number representing a month (1 for January, 2 for February, etc.)
and prints the corresponding season. Consider the following mappings: 1-3 (Winter), 4-6 (Spring), 7-9
(Summer), 10-12 (Fall). Use if-else-if statements to implement this logic.
5 Create a JavaScript program that takes a student’s score as input and determines their grade. If the score is
greater than or equal to 90, assign the grade ‘A’; if between 80 and 89, assign ‘B’; if between 70 and 79,
assign ‘C’; if between 60 and 69, assign ‘D’; otherwise, assign ‘F’. By Using if-else-if statements.
6 Write a JavaScript program that takes three numbers as input and determines the largest among them.
However, if two or more numbers are equal, display a message indicating that there is a tie, using nested if-
else statements.
7 Write a JavaScript program that takes a grade (A, B, C, D, F) as input and shows message indicating the
corresponding description (excellent, good, average, poor, fail). Use a switch statement to implement this
logic.
8 Create a JavaScript program that takes a month’s number (1 for January, 2 for February, etc.) as input and
returns the name of the month. Use a switch statement to implement this logic.
9 Develop a JavaScript program that generates the Fibonacci sequence up to a given number of terms using
a for loop. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two
preceding ones.
10 Write a JavaScript program that takes a number and then prints its multiplication table up to 10 using a for loop.
11 Create a JavaScript program that takes a positive integer as input and determines whether it is a prime
number or not. Use a while loop to implement the prime number checking algorithm.
12 Write a JavaScript program that calculates the sum of digits of a given number. Use a while loop to extract
digits one by one until the number becomes zero, and accumulate the sum.
13 Develop a JavaScript program that calculates the factorial of a given number using a do-while loop. The
factorial of a number n is the product of all positive integers less than or equal to n.
140
CITS : IT & ITES - Computer Software Application - Exercise 39
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Creating an Object
I Using Object Literal Notation
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Object Literal Notation </title>
</head>
<body>
<script>
// Creating an object using object literal notation var
person = {
firstName: “John”,
lastName: “Doe”,
age: 30,
fullName: function() {
return this.firstName + “ “ + this.lastName;
}
};
// Accessing object properties and methods
console.log(person.firstName); // Output: John
console.log(person.lastName); // Output: Doe
console.log(person.age); // Output: 30
console.log(person.fullName()); // Output: John Doe
</script>
</body>
</html>
141
COMPUTER SOFTWARE APPLICATION - CITS
142
CITS : IT & ITES - Computer Software Application - Exercise 40
COMPUTER SOFTWARE APPLICATION - CITS
143
CITS : IT & ITES - Computer Software Application - Exercise 40
COMPUTER SOFTWARE APPLICATION - CITS
144
CITS : IT & ITES - Computer Software Application - Exercise 40
COMPUTER SOFTWARE APPLICATION - CITS
145
CITS : IT & ITES - Computer Software Application - Exercise 40
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• create user defined functions
• create Anonymus functions
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Creating a Function
I Function without parameters
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Function without parameters </title>
</head>
<body>
<script>
// Defining a function named “greet” without any parameters
function greet()
{
// Inside the function, logging a greeting message to the console
console.log(“Hello, world!”);
}
// Calling the function
greet(); // Output: Hello, world!
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Go to the browsers console tab and verify the output.
146
COMPUTER SOFTWARE APPLICATION - CITS
147
CITS : IT & ITES - Computer Software Application - Exercise 41
COMPUTER SOFTWARE APPLICATION - CITS
148
CITS : IT & ITES - Computer Software Application - Exercise 41
COMPUTER SOFTWARE APPLICATION - CITS
149
CITS : IT & ITES - Computer Software Application - Exercise 41
COMPUTER SOFTWARE APPLICATION - CITS
150
CITS : IT & ITES - Computer Software Application - Exercise 41
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• use HTML forms with javascript
• validate HTML form using javascript
• create Dynamic form elements.
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Simple Form Submission
1 Open the text editor
2 Write the following codes
<html>
<head></head>
<body>
<form id=”myForm”>
<label for=”username”>Username:</label>
<input type=”text” id=”username” name=”username”>
<button type=”submit”>Submit</button>
</form>
<script>
const form = document.getElementById(“myForm”);
form.addEventListener(“submit”, handleSubmit);
function handleSubmit(event) {
event.preventDefault();
const username = document.getElementById(“username”).value;
console.log(“Submitted username:”, username);
}
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Enter a text in the textbox and press submit button.
6 Go to the browsers console tab and verify the output.
151
COMPUTER SOFTWARE APPLICATION - CITS
152
CITS : IT & ITES - Computer Software Application - Exercise 42
COMPUTER SOFTWARE APPLICATION - CITS
153
CITS : IT & ITES - Computer Software Application - Exercise 42
COMPUTER SOFTWARE APPLICATION - CITS
1 Write a JavaScript program that validates an email input field in a form to ensure it is in a valid email format
(e.g., contains “@” and “.”). Display an error message if the email format is invalid.
2 Create a JavaScript program that implements form validation for a password input field. Validate the
password to ensure it meets certain criteria, such as minimum length and inclusion of special characters.
Display an error message if the password does not meet the criteria.
3 Write a JavaScript program that dynamically adds input fields (e.g., text input, select dropdown) to a form
when a button is clicked.
4 Create a JavaScript program that dynamically removes input fields from a form when a button is clicked,
based on user interaction or condition.
5 Create a JavaScript program that disables a form submit button until all required fields in the form are filled.
Enable the submit button only when all required fields are filled.
154
CITS : IT & ITES - Computer Software Application - Exercise 42
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
155
COMPUTER SOFTWARE APPLICATION - CITS
156
CITS : IT & ITES - Computer Software Application - Exercise 43
COMPUTER SOFTWARE APPLICATION - CITS
157
CITS : IT & ITES - Computer Software Application - Exercise 43
COMPUTER SOFTWARE APPLICATION - CITS
158
CITS : IT & ITES - Computer Software Application - Exercise 43
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• use css in HTML page
• manipulate the style property of HTML elements using javascript.
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
159
COMPUTER SOFTWARE APPLICATION - CITS
160
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
161
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
162
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
163
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
164
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
165
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
166
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
167
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
168
CITS : IT & ITES - Computer Software Application - Exercise 44
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Error Handling using try-catch
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Object Literal Notation </title>
</head>
<body>
<script>
try
{
// Code that may throw an error let
x = 1;
let y = x + z; // z is not defined, this will throw an error
}
catch (error)
{
// Handle the error
console.error(“An error occurred:”, error.message);
}
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Go to the browsers console tab and verify the output.
169
COMPUTER SOFTWARE APPLICATION - CITS
170
CITS : IT & ITES - Computer Software Application - Exercise 45
COMPUTER SOFTWARE APPLICATION - CITS
171
CITS : IT & ITES - Computer Software Application - Exercise 45
COMPUTER SOFTWARE APPLICATION - CITS
172
CITS : IT & ITES - Computer Software Application - Exercise 45
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• handle AJAX request
• update HTML page content dynamically
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
• Apache web server
Procedure
TASK 1: Implementation an AJAX application
I Create a JavaScript file to handle the AJAX request and update the content dynamically.
1 Open the text editor
2 Write the following codes
// Get references to the button and content container
const loadButton = document.getElementById(‘loadButton’);
const contentContainer = document.getElementById(‘contentContainer’);
// Function to load content asynchronously
function loadContent() {
// Create a new XMLHttpRequest object const
xhr = new XMLHttpRequest();
// Define the callback function to handle the response xhr.onreadystatechange
= function() {
// Check if the request is complete and successful
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
// Update the content container with the response text
contentContainer.innerHTML = xhr.responseText;
}
};
// Open a GET request to the desired URL
xhr.open(‘GET’, ‘example.txt’, true);
// Send the request xhr.send();
}
// Add an event listener to the button to trigger the AJAX request
loadButton.addEventListener(‘click’, loadContent);
173
COMPUTER SOFTWARE APPLICATION - CITS
174
CITS : IT & ITES - Computer Software Application - Exercise 46
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• web browser
• Internet connection
Procedure
TASK 1: Using Paginators
1 create a basic pagination
• Open the text editor
• Write the following codes
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1”>
<link href=”https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div class=”container mt-3”>
<h2>Pagination </h2>
<p>a basic pagination</p>
<ul class=”pagination”>
<li class=”page-item”><a class=”page-link” href=”#”>Previous</a></li>
<li class=”page-item”><a class=”page-link” href=”#”>1</a></li>
<li class=”page-item”><a class=”page-link” href=”#”>2</a></li>
<li class=”page-item”><a class=”page-link” href=”#”>3</a></li>
<li class=”page-item”><a class=”page-link” href=”#”>Next</a></li>
</ul>
</div>
</body>
</html>
175
COMPUTER SOFTWARE APPLICATION - CITS
176
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
177
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
178
179
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
180
1 Positioning Popovers
• Open the text editor
• Write the following codes
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1”>
<link href=https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js”>
</script>
</head>
<body>
<div class=”container mt-5”>
<h3>Popover Positioning</h3>
<p>Click on the links to see the popover in action:</p>
<p>popover on top and bottom</p>
<br/><br/><br/><br/>
<a href=”#” title=”Header” data-bs-toggle=”popover” data-bs-placement=”top”
data-bs-content=”Content”>Top</a>
<a href=”#” title=”Header” data-bs-toggle=”popover” data-bs-placement=”bottom”
data-bs-content=”Content”>Bottom</a>
</div>
<br/><br/><br/>
<div class=”container mt-5”>
<h3>Popover Positioning</h3>
<p>Click on the links to see the popover in action:</p>
<p>popover on left and right side </p>
<a href=”#” title=”Header” data-bs-toggle=”popover” data-bs-placement=”left”
data-bs-content=”Content”>Left</a>
<a href=”#” title=”Header” data-bs-toggle=”popover” data-bs-placement=”right”
data-bs-content=”Content”>Right</a>
</div>
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll(‘[data-bs-toggle=”popover”]’))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
</script>
</body>
</html>
• Save the program as a .html file
• Open the html file with a web browser
• Verify the output.
181
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
182
183
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
184
185
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
186
187
CITS : IT & ITES - Computer Software Application - Exercise 47
COMPUTER SOFTWARE APPLICATION - CITS
188
Objectives
At the end of this exercise you shall be able to
• use bootstrap tables in HTML
• use bootstrap toasts in HTML
• use bootstrap tooltips in HTML.
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• web browser
• Internet connection
Procedure
TASK 1: Using Table
1 Create a basic Bootstrap 5 table
• Open the text editor
• Write the following codes
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1”>
<link href=”https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div class=”container mt-3”>
<h2>Table</h2>
<table class=”table”>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
189
COMPUTER SOFTWARE APPLICATION - CITS
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>[email protected]</td>
</tr>
</tbody>
190
191
CITS : IT & ITES - Computer Software Application - Exercise 48
COMPUTER SOFTWARE APPLICATION - CITS
192
193
CITS : IT & ITES - Computer Software Application - Exercise 48
COMPUTER SOFTWARE APPLICATION - CITS
194
195
CITS : IT & ITES - Computer Software Application - Exercise 48
COMPUTER SOFTWARE APPLICATION - CITS
196
197
CITS : IT & ITES - Computer Software Application - Exercise 48
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Desktop/Laptop with latest configuration
• web browser
• Internet connection
Procedure
TASK 1: Applying Breakpoints to Components
1 Open the text editor
2 Write the following codes
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
<title>Bootstrap Breakpoints</title>
<!-- Bootstrap CSS -->
<link href=https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css rel=”stylesheet”>
<style>
/* Additional custom styles */
.custom-component
{ background-color:
lightblue; padding: 20px;
margin-bottom: 20px;
}
</style>
<!-- Bootstrap JS (optional) -->
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js”></script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js”></script>
</head>
<body>
198
COMPUTER SOFTWARE APPLICATION - CITS
199
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
200
201
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
202
203
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
204
205
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
206
207
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
208
209
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
<div class=”container”>
<div class=”row mt-5”>
<div class=”col”>
<h2>Positioning Example</h2>
<p>This is a simple example demonstrating how to use Bootstrap v5 classes for positioning elements.</p>
<div class=”position-relative bg-light p-3 mb-3”>
<div class=”position-absolute top-0 start-0 bg-primary p-2”> Top
Left
</div>
<div class=”position-absolute top-0 end-0 bg-success p-2”> Top
Right
</div>
</div>
<div class=”position-relative”>
<img src=”https://via.placeholder.com/400” alt=”Placeholder Image” class=”img-fluid”>
<div class=”position-absolute top-0 start-50 translate-middle-x bg-info p-2”>
Center Top
</div>
<div class=”position-absolute bottom-0 start-50 translate-middle-x bg-secondary p-2”> Center
Bottom
</div>
</div>
<div class=”position-relative bg-light p-3 mb-3”>
<div class=”position-absolute bottom-0 start-0 bg-warning p-2”>
Bottom Left
</div>
<div class=”position-absolute bottom-0 end-0 bg-danger p-2”>Bottom Right
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js”></script>
</body>
</html>
1 Save the program as a .html file
2 Open the html file with a web browser
3 Verify the output.
210
211
CITS : IT & ITES - Computer Software Application - Exercise 49
COMPUTER SOFTWARE APPLICATION - CITS
212
Objectives
At the end of this exercise you shall be able to
• perform installation of apache webserver
• perform installation of PHP
• configure apache webserver to run PHP as a module.
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apsssache web server • seb browser
213
COMPUTER SOFTWARE APPLICATION - CITS
214
215
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
216
217
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
218
219
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
220
221
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
222
223
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
224
225
CITS : IT & ITES - Computer Software Application - Exercise 50
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Using If statement
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
$age = 21;
if ($age>18)
{
echo “You are eligible for DL”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
226
COMPUTER SOFTWARE APPLICATION - CITS
227
CITS : IT & ITES - Computer Software Application - Exercise 51
COMPUTER SOFTWARE APPLICATION - CITS
228
229
CITS : IT & ITES - Computer Software Application - Exercise 51
COMPUTER SOFTWARE APPLICATION - CITS
230
231
CITS : IT & ITES - Computer Software Application - Exercise 51
COMPUTER SOFTWARE APPLICATION - CITS
232
233
CITS : IT & ITES - Computer Software Application - Exercise 51
COMPUTER SOFTWARE APPLICATION - CITS
1 Create a PHP if statement to determine whether a variable $temperature is greater than 30 degrees
Celsius then display “It’s hot outside!”
2 Create a PHP program that determines whether a student has passed or failed an exam based on
their score. If the score is greater than or equal to 60, display a “Pass” message; otherwise, display a
“Fail” message.
3 Write a PHP if statement to determine if a variable $num is divisible by 2 and 3. If it is, echo “The number
is divisible by both 2 and 3”, otherwise echo “The number is not divisible by both 2 and 3”.
4 Write a PHP switch statement that checks the value of a variable $dayOfWeek and echoes “It’s a
weekday” for Monday to Friday, and “It’s a weekend” for Saturday and Sunday.
5 Write a PHP switch statement to determine the discount percentage based on the quantity of items
purchased. If the quantity is 1-10, apply a 5% discount, if it’s 11-20, apply a 10% discount, and if it’s over
20, apply a 15% discount.
6 Write a PHP ternary operator statement to determine if a given number stored in $num is even or odd,
and echo “Even” if it’s even, otherwise echo “Odd”.
7 Write a PHP while loop that calculates the factorial of a given number $n and echoes the result.
8 Create a PHP while loop that generates Fibonacci numbers until reaching a value greater than 1000,
and echoes each Fibonacci number.
9 Create a PHP for loop to generate multiples of 2 and 3 in between 1 and 100, and echoes each number.
10 Write a PHP script using nested for loops to create a simple multiplication table (e.g., 1x1=1, 1x2=2, ...,
5x5=25).
11 Create a script with nested for loops. The outer loop iterates 3 times, and the inner loop iterates 5 times.
Inside the inner loop, use break to exit the entire loop structure (both inner and outer) if the current iteration
number in the inner loop reaches 3.
234
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browsers
Procedure
TASK 1: Create user defined functions
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
function writeMsg()
{
echo “Hello world!”;
}
writeMsg();
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
235
COMPUTER SOFTWARE APPLICATION - CITS
236
237
CITS : IT & ITES - Computer Software Application - Exercise 52
COMPUTER SOFTWARE APPLICATION - CITS
238
239
CITS : IT & ITES - Computer Software Application - Exercise 52
COMPUTER SOFTWARE APPLICATION - CITS
240
241
CITS : IT & ITES - Computer Software Application - Exercise 52
COMPUTER SOFTWARE APPLICATION - CITS
242
1 Write a function named calculateArea that calculates the area of a rectangle given its length and width.
2 Write a PHP function that takes two numbers as parameters ($num1 and $num2) and print their sum. Call the
function with different values and print result.
3 Create a function called sayHello that takes a parameter $name and defaults to “Guest” if no value is
provided. The function should echo “Hello, $name!”. Call the function without providing a value for $name
and observe the output.
4 Create a function named getAgeCategory that determines the age category based on the provided age. It
should take one parameter $age with a default value of 25. The function should return “Child” for ages 0-12,
“Teen” for ages 13-19, “Adult” for ages 20-59, and “Senior” for ages 60 and above.
5 Create a function called incrementByReference that takes an integer parameter $num by reference and
increments it by 1 inside the function. Call the function with a variable and observe its value change after the
function call.
6 Implement a function called swapValues that takes two variables $a and $b by reference and swaps their
values inside the function. Call the function with two variables and print their values before and after the
function call to demonstrate the swap.
7 Write a PHP script that defines a dynamic function named multiply which takes two parameters and returns
their product. Then, call this dynamic function with values 5 and 3, and echo the result.
243
CITS : IT & ITES - Computer Software Application - Exercise 52
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• write content to the browser using PHP
• check common math and random number functions in PHP
• upload download from server using PHP.
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Writing to the browser
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
// Example with echo
echo “Hello, world!”;
244
COMPUTER SOFTWARE APPLICATION - CITS
245
CITS : IT & ITES - Computer Software Application - Exercise 53
COMPUTER SOFTWARE APPLICATION - CITS
<title>Form Example</title>
</head>
<body>
<label for=”email”>Email:</label>
<input type=”email” name=”email” id=”email” required>
246
247
CITS : IT & ITES - Computer Software Application - Exercise 53
COMPUTER SOFTWARE APPLICATION - CITS
248
<body>
<form action=”upload.php” method=”post” enctype=”multipart/form-data”>
<label for=”file”>Select a file:</label>
<input type=”file” name=”file” id=”file” required>
<br>
<input type=”submit” value=”Upload File”>
</form>
</body>
</html>
• Save the program in C:\Apache24\htdocs in a folder as index.html
2 Create PHP Script to Handle Upload
• Open the text editor
• Write the following codes
<html>
<body>
<?php
// upload.php
if ($_SERVER[“REQUEST_METHOD”] == “POST”)
{
// Check if the file was uploaded without errors
if (isset($_FILES[“file”]) && $_FILES[“file”][“error”] == 0)
{
$allowedTypes = [‘jpg’, ‘jpeg’, ‘png’, ‘gif’, ‘txt’];
$maxSize = 5 * 1024 * 1024; // 5 MB
$targetDir = “uploads/”; //create a folder in this name in your php file saved location .
$targetFile = $targetDir . basename($_FILES[“file”][“name”]);
$fileExtension = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
249
CITS : IT & ITES - Computer Software Application - Exercise 53
COMPUTER SOFTWARE APPLICATION - CITS
250
251
CITS : IT & ITES - Computer Software Application - Exercise 53
COMPUTER SOFTWARE APPLICATION - CITS
252
253
CITS : IT & ITES - Computer Software Application - Exercise 53
COMPUTER SOFTWARE APPLICATION - CITS
1 Provide a code example demonstrating the use of the echo and print statements to display text on a web
page.
2 Provide a code example demonstrating how to capture the output of a PHP script and store it in a
variable for further processing.
3 Provide examples of how to retrieve user input from fields such as text fields, checkboxes, radio buttons,
and select dropdowns.
4 Provide a code example demonstrating how to access form data submitted via the GET method.
5 Provide a code example illustrating how to create a form that allows users to upload a file to the server.
6 Provide a simple code example demonstrating how to force the download of a file named “example.txt”.
7 Provide a code snippet illustrating how to set headers for downloading a PDF file named “document.pdf”.
8 Write a PHP function that takes a floating-point number as input and returns its absolute value.
9 Write a PHP code to calculate the sine, cosine, and tangent of an angle in radians.
10 Write a PHP code snippet to generate a random integer between 1 and 100 and display it on the screen.
254
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Knowing anatomy of a cookie
Cookie Name: Choose a descriptive name that identifies the data stored. Cookie
Value: The data you want to store, like user preferences or a session ID.
Lifetime: How long the cookie should last (in seconds, hours, or days).
Path: The URL path where the cookie should be accessible. Default is current path.
Domain: The domain for which the cookie applies. Default is current domain.
Security: Whether the cookie should only be sent over secure HTTPS connections.
HttpOnly: Whether the cookie should be accessible only through HTTP, protecting it from JavaScript
access.
255
COMPUTER SOFTWARE APPLICATION - CITS
256
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
257
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
258
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
$username = $_SESSION[‘username’];
$user_email = $_SESSION[‘user_email’];
// Display session variables
echo “Username: $username <br>”;
echo “Email: $user_email <br>”;
// Modify session variable
$_SESSION[‘user_email’] = ‘[email protected]’;
// Display modified session variable
echo “Modified Email: “ . $_SESSION[‘user_email’] . “<br>”;
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
259
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run the program
7 Click the “Next Page” link to pass ‘Session ID’ in the next page.
260
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
261
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
262
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
$username = $_SESSION[‘username’];
echo “Welcome back, $username!”;
}
else
{
echo “Session not found!”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
263
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
if (isset($_SESSION[‘encoded_username’]))
{
$encodedUsername = $_SESSION[‘encoded_username’];
//decode using base64_decode()
$decodedUsername = base64_decode($encodedUsername);
echo “Decoded Username: $decodedUsername”;
}
else
{
echo “Session variable ‘encoded_username’ not set.”;
}?>
</body>
</html>
3. Save the program in C:\Apache24\htdocs in a folder with .php extension
4. Run the Apache services from windows services
5. Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
264
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
<html>
<body>
<?php
// Start the session
session_start();
// Unset a session variable
unset($_SESSION[‘username’]);
unset($_SESSION[‘user_email’]);
// Destroy all session data
session_destroy();
echo “All session data successfully removed”;
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
265
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as querystring1.php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
II Processing query string
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
echo “Processing query string...<br/> “;
// Check if query string parameters exist
if(isset($_GET[‘name’]) && isset($_GET[‘age’]))
{
// Retrieve and sanitize the parameters
$name = htmlspecialchars($_GET[‘name’]);
$age = intval($_GET[‘age’]); // Convert age to integer
// Process the parameters
if($age >= 18)
{
echo “$name is an adult.”;
}
else
{
echo “$name is a minor.”;
}
}
else
{
// If parameters are not provided, display an error message
echo “Please provide name and age parameters.”;
}
266
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as querystring2.php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
Note: This code needs a functioning mail server configured in the PHP environment to send emails.
<html>
<body>
<?php
$to = “[email protected]”;//provide the actual email address
$subject = “My Email Subject”;
$message = “This is the email body.”;
// Optional headers
$headers = “From: [email protected]” . “\r\n” .
“Reply-To: [email protected]”;
267
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
1 Provide a code example demonstrating how to set a cookie with the value that expires in 24 hours.
2 Provide a code example demonstrating how to retrieve the value of a cookie named “username” set in
a previous request.
3 Provide a code example demonstrating how to delete a cookie named “username” that was previously
set.
4 Provide a code example demonstrating how to start a session and set a session variable
named “myname” with the value “CSATRAINEE”.
5 Provide a code example demonstrating how to modify the value of the session variable “username”
set in a previous request.
6 Provide a code example demonstrating how to unset the session variable “username”.
7 Write a PHP code snippet generating a unique session ID, associating it with a session, and storing it
in a cookie
8 Provide examples of how to add query string parameters programmatically, either within the same
page or when redirecting to another page.
268
CITS : IT & ITES - Computer Software Application - Exercise 54
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Working with directories
I Creating a Directory
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
$directory_path = ‘example_directory’;
// Check if the directory doesn’t exist before attempting to create
if (!is_dir($directory_path))
{
// Create the directory with mkdir()
mkdir($directory_path);
echo “Directory created successfully: $directory_path”;
}
else
{
echo “Directory already exists: $directory_path”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
269
COMPUTER SOFTWARE APPLICATION - CITS
270
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
closedir($directory_handle);
}
else
{
271
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
272
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
273
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
274
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
275
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
// File path
$filePath = ‘my_new_file.txt’;
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
276
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
277
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
278
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
<?php
$file=”info.txt”;
$content=”hai you are welcome”; file_put_contents($file,
$content) or die(“Error not opening”);
echo “Content written in the file”;
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
279
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
280
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
281
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
1 Provide a code example demonstrating how to create a directory named “uploads” within the current
working directory.
2 Provide a code example demonstrating how to list the contents of a directory named “images”.
3 Provide a code example demonstrating how to delete a directory named “temp” and its contents.
4 Provide a code example demonstrating how to open a file named “example.txt” in read mode.
5 Provide a code example demonstrating how to read each line from a file handle using the fgets() function.
6 Provide a code example demonstrating how to use the file_get_contents()
7 Provide a code example demonstrating how to use the fwrite() function to write a string to a file handle.
8 Provide a code example demonstrating how to open a file in append mode (“a”) and write text content to it.
9. Provide a code example demonstrating how to delete a file named “example.txt” from the filesystem.
282
CITS : IT & ITES - Computer Software Application - Exercise 55
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• computer/Laptop with latest configuration • PHP
• operating system: windows 10 or 11 • Text editor
• apache web server • web browser
Procedure
TASK 1: Super global variables the server array
1 Open the text editor
2 Write the following codes
<html >
<head>
<title>$_SERVER Super Global</title>
</head>
<body>
<h2>Server Information</h2>
<ul>
<li>Server Name: <?php echo $_SERVER[‘SERVER_NAME’]; ?></li>
<li>Server Software: <?php echo $_SERVER[‘SERVER_SOFTWARE’]; ?></li>
<li>Server Protocol: <?php echo $_SERVER[‘SERVER_PROTOCOL’]; ?></li>
<li>Request Method: <?php echo $_SERVER[‘REQUEST_METHOD’]; ?></li>
<li>Request Time: <?php echo $_SERVER[‘REQUEST_TIME’]; ?></li>
<li>Request URI: <?php echo $_SERVER[‘REQUEST_URI’]; ?></li>
<li>Query String: <?php echo $_SERVER[‘QUERY_STRING’]; ?></li>
<li>User Agent: <?php echo $_SERVER[‘HTTP_USER_AGENT’]; ?></li>
<li>Remote Address: <?php echo $_SERVER[‘REMOTE_ADDR’]; ?></li>
</ul>
283
COMPUTER SOFTWARE APPLICATION - CITS
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
284
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
// Access form data using $_POST array
$name = $_POST[‘name’];
$email = $_POST[‘email’];
// Display a confirmation message
echo “Thank you, “ . $name . “ for your submission!”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the .html file to run and verify the output
285
<html
<head>
<title>PHP User Input</title>
</head>
<body>
<h2>Enter your name:</h2>
<form action=”process.php” method=”get”>
<input type=”text” name=”name” placeholder=”Enter your name”>
<button type=”submit”>Submit</button>
</form>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as index.html
286
}
else
{
// If the request method is not POST, redirect back to the form
header(“Location: index.html”);
exit();
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the index.html file to run and verify the output
287
288
<html>
<body>
<form method=”post” action=”process.php”>
<input type=”hidden” name=”user_id” value=”123”>
<input type=”text” name=”username”>
<button type=”submit”>Submit</button>
</form>
</body>
</html>
289
<body>
<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
$userId = $_POST[‘user_id’];
$username = $_POST[‘username’];
// Process the values
echo “User ID: $userId, Username: $username”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the .html file to run and verify the output
1 Provide a code example to determine the request method (GET, POST, etc.) used by a client in PHP.
2 Provide examples of accessing common request headers in PHP such as
$_SERVER[‘HTTP_USER_AGENT’] and $_SERVER[‘HTTP_REFERER’].
3 Provide a code example demonstrating how to create a simple HTML form with a text input field and retrieve
the user’s input using the $_GET superglobal.
4 Provide a code example of a PHP file that contains an HTML form for acquiring user input.
5 Provide a code example of setting hidden field values in one page and retrieving them in another page using
the $_POST or $_GET superglobals.
290
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Redirecting a
user I Using header()
function
1 Open the text editor
2 Write the following codes
<html >
<head>
<title >Using header() function </title>
</head>
<body>
<?php
// Redirect to another page after 5 seconds
header(“Location:destination-page.php”);
exit; // Make sure to exit after sending the header
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
291
COMPUTER SOFTWARE APPLICATION - CITS
292
1 Provide a code example of how to redirect a user to another URL with a delay of 5 seconds
293
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Working with basic regular
expressions I Matching a single character
1 Open the text editor
2 Write the following codes
<html >
<head>
<title > Matching a single character </title>
</head>
<body>
<?php
$string = “Hello, world!”;
$pattern = “/w/”; // Matches any word character (alphanumeric or underscore)
if (preg_match($pattern, $string))
{
echo “Match found!”; // Output: Match found!
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
294
COMPUTER SOFTWARE APPLICATION - CITS
http://localhost/foldername/
6 Click the php file to run and verify the output
295
if (preg_match($pattern, $string))
{
echo “The string contains a vowel.”;
}
?>
</body>
</html>
296
$pattern = “/c.t/”;
if (preg_match($pattern, $string))
{
echo “Pattern found in the string.”;
}
else
{
echo “Pattern not found in the string.”;
}
?>
</body>
</html>
if (preg_match($pattern, $string))
{
297
if (preg_match($pattern, $string))
{
echo “The string contains 3 to 5 digits.”;
}
?>
</body>
</html>
298
if (preg_match($pattern, $string))
{
echo “Pattern found in the string.”;
}
else
{
echo “Pattern not found in the string.”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
299
if (preg_match($pattern, $string))
{
echo “Pattern found in the string.”;
}
else
{
echo “Pattern not found in the string.”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
300
if (preg_match($pattern, $string))
{
echo “Pattern found in the string.”;
}
else
{
echo “Pattern not found in the string.”;
}
?>
</body>
</html>
301
302
<?php
$string = “Hello World”;
if (preg_match(“/hello/i”, $string))
{ echo “Match found!”;
} else {
echo “No match found!”;
}
// Output: Match found!
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
}
// Output: Match found!
?>
303
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
}
// Output: Match found!
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
304
IV x (extended) modifier
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> x (extended) modifier </title>
</head>
<body>
<?php
$pattern = “
/
^ # Start of the string
\d{3} # Match exactly 3 digits
- # Match a hyphen
\d{4} # Match exactly 4 digits
$ # End of the string
/x
“;
$string = “123-4567”;
if (preg_match($pattern, $string)) {
echo “Match found!- extended modifier”;
“;
} else {
echo “No match found!”;
}
// Output: Match found!
?>
</body>
</html>
305
306
307
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
308
309
<html >
<head>
<title> Using preg_quote() </title>
</head>
<body>
<?php
// String containing characters to be quoted
$string = “Escaping: .\+*?[^]{}()$=!|:-”;
// Quote the string to escape regular expression characters
$quotedString = preg_quote($string);
// Regular expression pattern containing the quoted string
$pattern = ‘/^’ . $quotedString . ‘$/’;
// Test string to match against the pattern
$testString = “Escaping: .\\+*?[^]{}()$=!|:-”;
// Perform regular expression matching if
(preg_match($pattern, $testString)) {
echo “String matches the pattern.\n”;
} else {
310
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Creating an object, properties and methods
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Creating an object </title>
</head>
<body>
<?php
class Person
{
//Add Properties
public $name;
public $age;
//Add Methods
public function greet()
{
echo “Hello, my name is “ . $this->name . “.”;
}
}
//Create an Object Instance
311
COMPUTER SOFTWARE APPLICATION - CITS
class MyClass
{
// Properties
public $name;
public $age;
// Constructor
public function construct($name, $age)
{
312
CITS : IT & ITES - Computer Software Application - Exercise 59
COMPUTER SOFTWARE APPLICATION - CITS
$this->name = $name;
$this->age = $age;
echo “Constructor called\n”;
}
// Method to display information
public function displayInfo()
{
echo “Name: “ . $this->name . “, Age: “ . $this->age . “\n”;
}
}
?>
</body>
</html>
313
CITS : IT & ITES - Computer Software Application - Exercise 59
COMPUTER SOFTWARE APPLICATION - CITS
<body>
<?php
class MyClass
{
// Destructor
public function destruct()
{
echo “Destructor called\n”;
}
}
1 Create an object of a class named Car in PHP, which has properties such as $make, $model, and $year.
Assign values to these properties during object instantiation.
2 Create a PHP class called Book with properties $title, $author, and $price. Write a constructor method to
initialize these properties. Instantiate an object of the Book class with the title “PHP Programming”, author
“John Doe”, and price $29.99.
3 Create a PHP class Employee with private properties $name and $salary. Implement getter and setter methods
for these properties. Instantiate an Employee object and set the name to “John” and salary to 50000.
314
CITS : IT & ITES - Computer Software Application - Exercise 59
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Using class constants
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> class constants </title>
</head>
<body>
<?php
class MathConstants
{
const PI = 3.14159;
const E = 2.71828;
public function printConstants()
{
echo “The value of PI is: “ . self::PI . “<br/>”;
echo “The value of E is: “ . self::E . “<br/>”;
}
}
class Circle
{
315
COMPUTER SOFTWARE APPLICATION - CITS
private $radius;
public function construct($radius)
{
$this->radius = $radius;
}
public function getArea()
{
return MathConstants::PI * $this->radius * $this->radius;
}
}
$con= new MathConstants();
$con->printConstants()
$circle = new Circle(5);
echo “Area of circle is:”. $circle->getArea(); // Output: 78.53975
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
316
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
// Parent class
class Animal
{
protected $name;
public function construct($name)
{
$this->name = $name;
}
public function speak()
{
echo $this->name . “ makes a sound.\n”;
}
}
// Child class inheriting from
Animal class Dog extends Animal
{
public function bark()
{
echo $this->name . “ barks.\n”;
}
}
// Child class inheriting from Animal
class Cat extends Animal
{
public function meow()
{
echo $this->name . “ meows.\n”;
}
}
// Creating instances of child classes
$dog = new Dog(“Buddy”);
$cat = new Cat(“Whiskers”);
// Calling methods from parent and child classes
$dog->speak(); // Output: Buddy makes a sound.
$dog->bark(); // Output: Buddy barks.
$cat->speak(); // Output: Whiskers makes a sound.
$cat->meow(); // Output: Whiskers meows.
?>
</body>
317
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
318
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
{
parent:: construct($name);
$this->radius = $radius;
}
// Implementing abstract method
public function calculateArea()
{
return pi() * pow($this->radius, 2);
}
}
// Concrete subclass of Shape
class Square extends Shape
{
private $side;
public function construct($name, $side)
{
parent:: construct($name);
$this->side = $side;
}
// Implementing abstract method
public function calculateArea()
{
return pow($this->side, 2);
}
}
// Creating instances of concrete subclasses
$circle = new Circle(“Circle”, 5);
$square = new Square(“Square”, 4);
// Calling methods on instances
echo”Area of circle is :”.$circle->calculateArea(); // Output: 78.539816339745
echo “<br/>”;
echo”Area of square is :”.$square->calculateArea(); // Output: 16
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
319
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
320
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
{
echo “myMethod does not exist in MyClass. <br/>”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
321
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
322
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
}
return $dividend / $divisor;
}
class MyCustomException extends Exception
{
public function construct($message, $code = 0)
{
parent:: construct($message, $code);
}
}
try
{
$result = divide(10, 2);
echo “Result: $result<br/>”;
$result = divide(10, 0); // This will throw an exception
}
catch (MyCustomException $e)
{
echo “Error: “ . $e->getMessage();
}
catch (Exception $e)
{
echo “General error: “ . $e->getMessage();
}
finally
{
echo “<br/>Always executed code”;
}
?>
</body>
</html>
323
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
324
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
{
validateEmail(“[email protected]”);
echo “Valid email address.<br/>”;
validateEmail(“invalid_email_address”);
echo “This line will not be reached due an exception will be thrown.<br/>”;
}
catch (CustomException $e)
{
// Catch the custom exception and handle it
echo $e->errorMessage() . “<br/>”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
TASK 7: Using
Iterators I Using
foreach loop
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Iterators </title>
</head>
<body>
<?php
$numbers = [1, 2, 3, 4, 5];
foreach ($numbers as $number)
{
echo $number . “ “;
}
325
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
II Using ArrayIterator
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Iterators </title>
</head>
<body>
<?php
$numbers = [1, 2, 3, 4, 5];
$iterator = new ArrayIterator($numbers);
while ($iterator->valid())
{
echo $iterator->current() . “ “;
$iterator->next();
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
326
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
$users = [
new User(“Alice”, 25),
new User(“Bob”, 30),
];
// Using foreach loop and custom IteratorAggregate:
class UserCollection implements IteratorAggregate
{
private $users;
public function construct(array $users)
{
$this->users = $users;
}
public function getIterator()
327
{
return new ArrayIterator($this->users);
}
}
$userCollection = new UserCollection($users);
foreach ($userCollection as $user)
{
echo $user->name . “ (“ . $user->age . “)” . PHP_EOL;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
1 Provide an example of a class constants be accessed from outside the class definition in PHP.
2 Create a ‘Person’ class with attributes like ‘name’ and ‘age’. Create a ‘Student’ subclass that inherits
from Person and adds a ‘studentID’ attribute. Instantiate a Student object and access its superclass
attributes along with the subclass attribute.
3 Create an abstract class ‘Animal’ with an abstract method ‘makeSound()’. Create concrete subclasses ‘Cat’
and ‘Dog’ that extend Animal and implement the makeSound() method to produce different sounds for
each animal. Call the makeSound() method for a Cat and a Dog object.
4 Create a class ‘Product’ with properties like ‘name’, ‘price’, and ‘quantity’. Serialize an object of this class
into a string using PHP’s serialization mechanism.
5 Create a function that reads data from a file, use PHP exceptions to handle errors such as file not found
or insufficient permissions while reading the file.
6 Create an array of product objects representing items in a shopping cart. Use the ArrayIterator class in
PHP to iterate over this array and calculate the total cost of all items in the shopping cart.
328
CITS : IT & ITES - Computer Software Application - Exercise 60
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with latest configuration • web browser
• operating system: windows 10 or 11 • apache web server
• Text editor • PHP
• MySQL server
Procedure
TASK 1: Connect to MySQL database from PHP
I Connect to MySQL and create a databse
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> create a databse </title>
</head>
<body>
<?php
$servername = “localhost”; // Change this if MySQL server is on a different host
$username = “your_username”; // Change this to your MySQL username
$password = “your_password”; // Change this to your MySQL password
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error)
{
die(“Connection failed: “ . $conn->connect_error);
}
// Create database
$sql = “CREATE DATABASE myDB”;
329
COMPUTER SOFTWARE APPLICATION - CITS
330
<html >
<head>
<title> create a table </title>
</head>
<body>
<?php
// Database connection parameters
$servername = “localhost”; // Change this if MySQL server is on a different host
$username = “your_username”; // Change this to your MySQL username
$password = “your_password”; // Change this to your MySQL password
$database = “example_db”; // Change this to your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: “ . $conn->connect_error);
}
// sql to create table
$sql = “create table persons(
id int, first_name varchar(30), last_name varchar(30) , email varchar(70))”;
if ($conn->query($sql) === TRUE) {
echo “Table created successfully”;
} else {
echo “Error creating table: “ . $conn->error;
}
$conn->close();
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
331
332
TASK 3: Connect to MySQL database from PHP and insert data using prepare statement
i Create an HTML form in the webpage (index.html) to collect the data from the user
1 Open the text editor
2 Write the following codes
<html >
<head> HTML form </title>
</head>
<body>
333
<body>
<h2>Insert Data into MySQL Database</h2>
<form method=”post” action=”insert.php”>
<label for=”username”>Username:</label><br>
<input type=”text” id=”username” name=”username” required><br><br>
<label for=”email”>Email:</label><br>
<input type=”email” id=”email” name=”email” required><br><br>
<input type=”submit” value=”Submit”>
</form>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as index.html
ii Create a PHP script (insert.php) to connect to the database and handle the insertion process.
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> </title>
</head>
<body>
<?php
// Database connection parameters
$servername = “localhost”; // Change this if the MySQL server is on a different host
$username = “your_username”; // Change this to MySQL username
$password = “your_password”; // Change this to MySQL password
$database = “example_db”; // Change this to database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error)
{
die(“Connection failed: “ . $conn->connect_error);
}
334
$email = $_POST[“email”];
// Prepare and execute the SQL statement to insert data into the table
$stmt = $conn->prepare(“INSERT INTO users (username, email) VALUES (?,?)”);
$stmt->bind_param(“ss”, $username, $email);
if ($stmt->execute())
{
echo “New record inserted successfully”;
}
else
{
echo “Error: “ . $conn->error;
}
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as insert.php
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the index.html file to run and verify the output
335
336
ii Create a PHP script (update.php) to connect to the database and handle the update process based on
user input.
1 Open the text editor
2 Write the following codes
<html >
<head> HTML form </title>
</head>
<body>
<?php
// Database connection parameters
$servername = “localhost”; // Change this if MySQL server is on a different host
$username = “your_username”; // Change this to MySQL username
$password = “your_password”; // Change this to MySQL password
$database = “example_db”; // Change this to database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error)
{
die(“Connection failed: “ . $conn->connect_error);
}
// Check if the form is submitted
if ($_SERVER[“REQUEST_METHOD”] == “POST”)
{
// Get form data
//$id = $_POST[“id”];
$newUsername = $_POST[“username”];
$newEmail = $_POST[“email”];
// Prepare and execute the SQL statement to update data in the table
$stmt = $conn->prepare(“UPDATE users SET email = ? WHERE username = ?”);
$stmt->bind_param(“ss”,$newEmail,$newUsername);
if ($stmt->execute())
{
337
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as update.php
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the index.html file to run and verify the output
338
339
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error)
{
die(“Connection failed: “ . $conn->connect_error);
}
// Check if the form is submitted
if ($_SERVER[“REQUEST_METHOD”] == “POST”)
{
// Get ID from the form
$username = $_POST[“username”];
// Prepare and execute the SQL statement to delete data from the table
$stmt = $conn->prepare(“DELETE FROM users WHERE username = ?”);
$stmt->bind_param(“s”, $username);
if ($stmt->execute())
{
echo “Record deleted successfully”;
}
else
{
echo “Error: “ . $conn->error;
}
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
340
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder as delete.php
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the index.html file to run and verify the output
341
1 Write the PHP code to establish a connection from a MySQL database named my_database hosted
on localhost, using a username and a password.
2 Write the PHP code to connect to the database, execute a query to retrieve data from a table named
users, and then display the results on a webpage.
3 Write PHP code to connect to the database, insert a new product record with specific values in to a
table named products and handle any potential errors during the insertion process.
4 Write PHP code to connect to the database, update existing records in a MySQL database table named
orders. update specific order records with new values, and ensure that the updates are applied
successfully.
5 Write PHP code to connect to the database, delete specific customer records based on certain criteria
from a MySQL database table named customers.
342
Requirements
Tools/Materials
• PC/Laptop with latest configuration • Apache web server
• Operating system: windows 10 or 11 • PHP
• Text editor • MySQL server
• Web browser
Procedure
Project:
Develop a web-based application to manage a library’s book collection, users, loans, and other functionalities.
Technologies:
Front-end: HTML, CSS, JavaScript (optional)
Back-end: PHP
Database: MySQL
System Modules:
1 User Management:
User registration and login (including different user roles, e.g., admin, librarian, member) User
profile management (update details, password change)
2 Book Management:
Add, edit, and delete book information (title, author, genre, publication date, availability)
Search books by various criteria (title, author, genre, keywords)
View detailed information about each book (summary, reviews, borrowed history)
3 Loan Management:
Borrow and return books (check user eligibility, availability, due dates)
Generate loan reports (individual, overdue, most popular books)
Set and manage loan periods and fines
4 Additional Features (optional):
Book reservation system
Online reading platform for eBooks
User reviews and ratings for books
Recommendations based on user borrowing history
Inventory management (track book condition, purchase new books)
343
COMPUTER SOFTWARE APPLICATION - CITS
Database Design:
Tables: Users, Books, Loans, Genres, Authors, etc.
Relationships: Users can borrow Books, Books can have multiple Loans, etc.
Implement data integrity constraints and triggers for efficient management.
Development Approach:
Implement modules iteratively, starting with core functionalities.
Use clear coding practices and modular design for maintainability.
Validate user input to prevent security vulnerabilities.
Implement user authentication and authorization for different roles.
Testing and Deployment:
Thoroughly test all functionalities manually and with automated tools.
Deploy the application on a web server accessible to users.
Evaluation and Future Improvements:
Gather user feedback and address issues during maintenance.
Implement new features based on user needs and feedback.
Consider performance optimization and scalability for large datasets.
Additional Notes:
This is a basic outline, and specific modules and features can be adjusted based on the needs and
requirements.
Research existing open-source library management systems for inspiration and potential libraries to utilize.
Always keep security and data privacy in mind when developing and deploying the system.
344
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
TASK 1: To protect a sheet using a password in Microsoft Excel, follow these steps
1 Open your Excel Workbook:
• Launch Microsoft Excel and open the workbook containing the sheet you want to protect.
2 Navigate to the Sheet:
• Go to the sheet that you want to protect.
345
COMPUTER SOFTWARE APPLICATION - CITS
346
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
• Enter a password in the “Password to unprotect sheet” field. This password will be required to unprotect the
sheet later.
• Choose specific options such as allowing users to select locked cells, format cells, insert rows, insert columns,
etc.
• Click on “OK” when you are done.
6 Re-enter Password (Optional):
347
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
1 Open your Excel Workbook: Open the Excel workbook that you want to protect.
2 Click on the “File” Tab: Click on the “File” tab in the Ribbon to access the Backstage view.
348
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
3 Select “Info” from the menu: In the Backstage view, select the “Info” option from the menu on the left.
4 Click on “Protect Workbook”: Under the “Info” section, you will find an option called “Protect Workbook.”
Click on it.
349
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
6 Enter the Password: If you selected “Encrypt with Password,” enter a password and click “OK.”
Note: Make sure to remember the password, as it will be required to unprotect the workbook.
350
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
7 Confirm the Password: If prompted, confirm the password by entering it again and click “OK.”
8 Save the Workbook: Save the workbook to apply the protection. Your workbook is now protected, and users
will need the password to open or modify it.
351
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 Create a ‘SalesData.xlsx’ Excel file and protect the ‘SalesData’ sheet using the password ‘Secure123.’
2 Create a ‘Confidential.xlsx’ Excel file and protect the ‘Confidential’ sheet using the password ‘Secret789’.
Modify the password from ‘Secret789’ to ‘Classified987.’ Ensure that the new password is required to
unprotect the sheet.
352
CITS : IT & ITES - Computer Software Application - Exercise 63
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
TASK 1: Given a column of full names use Flash Fill to split them into separate columns for first and last
names
1 Data Preparation:
353
COMPUTER SOFTWARE APPLICATION - CITS
354
CITS : IT & ITES - Computer Software Application - Exercise 64
COMPUTER SOFTWARE APPLICATION - CITS
• Similar steps can be applied in the Last Name to get the result.
TASK 2: From a column containing full email addresses and other text, use Flash Fill to extract only the
email addresses
1 Data Preparation:
355
CITS : IT & ITES - Computer Software Application - Exercise 64
COMPUTER SOFTWARE APPLICATION - CITS
356
CITS : IT & ITES - Computer Software Application - Exercise 64
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 Extract the first names from the list of full names using Flash Fill?
2 Separate the email addresses into usernames and domains using Flash Fill.
[email protected]
[email protected]
[email protected]
Hint: Separate the first email address into the “Username” and “Domain” columns (e.g., “john” in the
Username column and “example.com” in the Domain column.
357
CITS : IT & ITES - Computer Software Application - Exercise 64
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• perform Goal seek on data sheet to achieve your target
• use excel solver for data optimization & complex problem solving
• use scenario for various data sheet analysis.
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
a Goal Seek :
Goal Seek in Excel is a feature that allows you to find the value of a particular cell that achieves a desired result
in another cell by adjusting the value of one input cell. It’s often used in financial modeling, engineering, and
other fields where you need to determine the input necessary to achieve a specific outcome.
TASK 1: Imagine you are managing the financial data for a company. The NET SALES are determined by
the formula NET SALES = GROSS SALES * (PROFIT/100), and the ANNUAL PROFIT is the sum
of the net sales from four quarters. Your goal is to set a target ANNUAL PROFIT (23, 00,000)
and use the Goal Seek function to find the required PROFIT percentage for each quarter to
achieve this target
1 Create an Excel table with the following columns:
Sales Details
Quarter Gross Sales Profit Net Sale
Q1 ₹ 2,850,000 20
Q2 ₹ 3,155,000 20
Q3 ₹ 2,940,318 20
Q4 ₹0 20
Annual Profit
Net Profit ₹ 2,300,000
2 Formulas
a In cell C3 (Profit (%) for Q1), enter the initial profit percentage (e.g., 20%).
b In cell D9(Net Profit), enter the target annual profit value (e.g., ₹ 2,300,000).
358
COMPUTER SOFTWARE APPLICATION - CITS
c In cell D3 (Net Sales for Q1), enter the formula and press Enter Key.
Drag it in the below cells to get the Net Sales Value in Q2, Q3 & Q4 as shown below:
359
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
3 In cell D8 (SUM of NET SALES), enter the formula to sum the NET SALES from all four quarters:
360
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
c Under “Data Tools,” find and click on “What-If Analysis,” then select “Goal Seek.”
361
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
362
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2: You want to use Goal Seek to determine the number of units that need to be produced to
achieve a target production cost of 50,0000, assuming fixed costs of 20,0000 and a variable
cost per unit of 150
1 Set Up the Initial Table
Create an Excel table with the following columns:
2 Formulas
1 In cell B4 (Number of Units), enter the initial number of units (e.g., 1,000).
2 In cell C4(Production Cost per Unit), enter the formula:
3 Press Enter
363
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
364
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 You are managing a project budget, and the total project cost (Total CostTotal Cost) is determined by the
formula:
Total Cost=Fixed Costs+(Variable Cost per Unit×Number of Units)Total Cost=Fixed Costs+(Variable Cost
per Unit×Number of Units)
You want to use Goal Seek to determine the required number of units if the fixed costs are $10,000, and the
target total cost is $25,000.
2 In a manufacturing process, the production time per unit (Production TimeProduction Time) is determined
by the formula:
Production Time=Fixed Time+(Variable Time per Unit×Number of Units)Production Time=Fixed Time+
(Variable Time per Unit×Number of Units)
You want to use Goal Seek to determine the required number of units if the fixed time is 5 hours, and the
target production time is 20 hours.
b Excel Solver:
Excel Solver is a powerful tool used for optimization and solving complex problems by finding the best
solution based on a set of constraints. It is commonly used in operations research, engineering, finance, and
other fields where optimization is required
Add Solver to your Excel worksheet
The Solver add-in is added with all versions of Microsoft Excel though it is not enabled by default. You need
to manually add Solver to your Excel worksheet. To incorporate a Solver into your Excel worksheet, follow
the below-given steps.
365
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
2 The MS Excel options dialog box will appear. From the left side of the pane, click on the Add-Ins options.
366
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
3 The Add-Ins screen will be displayed in the center. At the bottom of the screen where the Manage box is
located, make sure that the add-ins option is selected in its field. Click on Go.
4 The Add-Ins dialog box will appear. Check the Solver ‘Add-ins’ box and click on the OK button.
367
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
5 That’s it; it will add the Solver tool to your Excel Worksheet.
6 The Solver add-ins programming tool is located on the Data tab, in the Analysis group.
368
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Step 2:
• Select cell E8 as the objective cell / Set Target Cell of the Solver Parameter box.
• Besides the To: options select Max as we are trying the maximize the value of the cell.
Step 3:
• In the By Changing Variable Cells, select the cell values we are mainly focusing on changing. Here, they
belong to the range C5:C7.
Step 4:
• Now add the constraints by clicking on the Add button on the right of the box.
369
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
370
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Step 5:
• Once you are done with all the steps above, click on Solve at the bottom of the box.
Step 6:
• After that, the Solver Results box will appear.
• Now select the options and reports you want to prefer in this box. For the demonstration, we are choosing
to enable the Keep Solver Solution option only.
• Click on OK button, then you will get the output like this:
371
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercise:
Question1 : Employee Scheduling
You are a manager responsible for scheduling employees for a customer service department. You want to
minimize the total number of hours scheduled while ensuring adequate coverage during peak hours.
Question: How should you schedule employees for each shift to minimize total hours scheduled while
meeting staffing requirements for each day?
Using Solver:
1 For each example, set up the objective function to maximize or minimize.
2 Define the decision variables and constraints based on the problem.
3 Access the Solver tool in Excel, specify the objective cell, decision variables, and constraints.
4 Run Solver to find the optimal solution.
c Scenarios on data
Excel scenarios allow you to create and save different sets of values that can be quickly substituted into your
worksheet
TASK 1:
1 Create Dataset with Proper Parameters
Suppose, that we are going to sell a book and would like to know how the Sale Units, Price per Unit, and
Variable Cost per Unit can affect the final profits. The profit is dependent on Sale Units (Cell B2), Price per
Unit (Cell B3), and the Variable Cost per Unit (Cell B5). Therefore, type the below formula in cell B7.
= B3*B4-B5-B6*B3
372
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
• As a result, a Scenario Manager dialogue box will appear in front of you. From the dialog box, click on Add
option.
373
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
• In the prompted Add Scenario dialogue box, fill in the required details. Enter a name (Worst Case) for the
Scenario name Add any comment that you wish to into the Comment box. Or you can also leave it blank.
As for the Changing cells, fill in all the reference cells (B3,B4,B6 in this case) that contain the input
values. Please note that the references must be separated by commas. Or, just press the CTRL key on
your keyboard and select all the cells, one by one, that contain the input values. At last, press the OK
option.
• Hence, the Scenario Values dialogue box pops up. Fill in the Scenario Values dialog box with the input
values that define the worst case, and press the Add option to add another scenario. Click on OK, and
the Worst Case scenario will be successfully created.
• Since we’d like to create another scenario, we click on Add. After clicking on Add, another Add Scenario
dialogue box will appear. Use the same approach that we applied when creating the Worst Case scenario
to build the Best Case scenario. Please note that Excel has set changing cells for the worst-case
scenario as the default changing cells for the best-case scenario. The details are given in the following
screenshot.
374
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
• With the same approach, create the Most Likely Case Here the below screenshot presents the details.
• You can also use the same above approach to creating other scenarios if you have other combinations
of input values. In this example, we assume that there are only 3 scenarios available and thus we click
on the OK button in the Scenario Values dialogue box. Now, you can see that three scenarios have been
successfully created and they are listed in sequence. Click on Close, and the Scenario Manager dialogue
box will be closed.
375
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
The Scenario Manager dialogue box is no longer blank. Now you can view the result from each of the scenarios
by simply double-clicking on any scenario.
To view a specific scenario and its corresponding outputs, you can click on that scenario and then click
on the Show button at the bottom. For example, if we double-click on Best Case, the input values in the
Excel worksheet will change into what has been filled for Best Case, and the output value will be calculated
automatically based on the formula in cell B7. The dataset will change automatically.
376
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
377
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
• After clicking on Summary, a Scenario Summary dialog box appears for you to put Result cells (B7 in this
case) and choose between Scenario summary. At last, press the OK option.
Related Exercises:
Question 1: Sales Projection Scenarios
Suppose you have a sales projection table like this:
378
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Question: How can you use Excel scenarios to compare different sales projections for the first quarter?
Steps to do :
1 Fill in the actual budget allocations in the “Actual” column.
2 Go to the “Data” tab, click on “What-If Analysis,” and select “Scenario Manager.”
3 Click on “Add” to create new scenarios, naming them as needed (e.g., Scenario 1, Scenario 2).
4 Input different budget allocations for each scenario.
5 By switching between scenarios, you can compare the impact of different budget allocations on departmental
spending.
Question 2: Project Timeline Scenarios
Imagine a project timeline table like this:
Question: How can you use scenarios to analyze different project completion timelines?
Steps to do:
1 Enter the duration of each task in the “Duration (Days)” column.
2 Go to the “Data” tab, click on “What-If Analysis,” and select “Scenario Manager.”
3 Create new scenarios (e.g., Scenario 1, Scenario 2) and input different durations for each task.
4 By comparing scenarios, you can assess how adjustments in task durations impact the overall project timeline.
379
CITS : IT & ITES - Computer Software Application - Exercise 65
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
In Excel, there are three main types of cell references: relative, absolute, and mixed. Using different types of cell
references can be helpful when creating formulas that you plan to copy or fill to other cells.
TASK 1: Different types of Cell References
Method 1: Relative Cell Reference
A relative cell reference adjusts when you copy the formula to other cells.
In a scenario where the objective is to establish a formula P (Price) equals INR (Indian Rupees), the suggestion is
to create a single formula in cell E3 and then copy it to other rows to avoid the need for a new formula for each
row. The emphasis is on using relative references to ensure the formula calculates the total for each item
correctly.
380
COMPUTER SOFTWARE APPLICATION - CITS
Step 1: Select the cell that will contain the formula. In our example, we’ll select cell E3.
Step 2: Enter the formula to calculate the desired value. In our example, we’ll type=(C3*D3)*(12/100). And
Press Enter on your keyboard. The formula will be calculated, and the result will be displayed in the cell.
381
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Step 3: Select the cell E3. The fill handle will appear in the bottom-right corner of the cell.
Step 4: Click and drag the fill handle over the cells. Select cells E3:E12, Release the mouse. The formula will be
copied to the selected cells with relative references, displaying the result in each cell.
Note: Double-click the filled cells to check formulas for accuracy. The relative cell references should
be different for each cell, depending on their rows.
382
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Step 1: Input the formula in the selected cell (E3) to compute the desired value. In this instance, the formula will
be =(C3*D3)*($F$3), with $F$3 being specified as an absolute reference.
383
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Step 2: Press Enter on your keyboard. The formula will calculate, and the result will display in the cell.
Step 3: Click and drag the fill handle across the cells where you intend to replicate the formula. Once you
release the mouse, the formula will be copied to the designated cells, retaining the absolute reference, and the
values will be automatically calculated in each corresponding cell.
Double-click the filled cells to check their formulas for accuracy. The absolute reference should be the same for
each cell, while the other references are relative to the cell’s row.
384
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Step 1: Input the formula in the selected cell (E3) to compute the desired value. In this instance, the formula
will be = ($C3*$D3)($F$3), with $F$3 being specified as an absolute reference and $C3 and $D3 is the mixed
reference.
385
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Step 2: Press Enter on your keyboard. The formula will calculate, and the result will display in the cell.
Step 3: Click and drag the fill handle across the cells where you intend to replicate the formula. Once you
release the mouse, the formula will be copied to the designated cells, retaining the absolute reference, and the
values will be automatically calculated in each corresponding cell
386
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
Question 1: Sales Commission Calculation
Suppose you work as a sales representative and earn a commission based on the total sales amount. Your
commission rate is 5% of total sales. You have a table with sales data for different months.
Calculate the percentage of inventory remaining for each product using a formula with absolute references?
Solution: You can calculate the percentage of inventory remaining as (Inventory Count / Total Inventory) * 100%.
Question 3: Monthly Expense Analysis
Suppose you are analyzing your monthly expenses and want to calculate the percentage of each expense
category relative to the total expenses. You have a table with the expense categories and their amounts:
Calculate the percentage of each expense category relative to the total expenses using a formula with relative
references?
Solution: You can calculate the percentage of each expense category relative to the total expenses by dividing
the amount of each category by the total expenses, multiplied by 100. Here’s the formula you can use in the
“Percentage of Total Expenses (%)” column:
= (B2 / SUM(B$2:B$6)) * 100
387
CITS : IT & ITES - Computer Software Application - Exercise 66
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
R1C1 notation is an alternative way of referencing cells in Microsoft Excel, as opposed to the more common A1
notation. In R1C1 notation:
• R stands for Row.
• C stands for Column.
• The numbers following R and C represent the row and column numbers,
respectively. The basic format of an R1C1 reference is R[row]C[column].
For example:
• R1C1 refers to the cell in the first row and first column.
• R2C3 refers to the cell in the second row and third column.
In addition to explicit cell references, you can use relative references in R1C1 notation. For instance:
• RC[-1] refers to the cell in the same row and one column to the left of the active cell/current cell.
• R[2]C refers to the cell two rows below and in the same
column. How to Switch to R1C1 Notation in Excel:
1 Open Excel.
388
COMPUTER SOFTWARE APPLICATION - CITS
2 Go to the “File” tab. Now you can see the Excel in A1 reference style.
389
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
390
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
Once switched, you’ll notice that the column headers change from letters (A, B, C, etc.) to numbers (1, 2, 3, etc.),
indicating the R1C1 notation mode.
391
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
This formula instructs Excel to sum the value in the cell two columns to
the left (column A ie, C[-2]) from the current cell(R3C3) and the value in
the cell one column to the left (column Bie, C[-1])).
R3C3= RC[-2]+RC[-1]
Step 3: Press Enter
Press Enter to execute the formula. Excel will calculate the sum and
display the result in cell R3C3.
Step 4:
Drag down from R3C3:R7C3 to obtain the result.
Result:
392
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
Step 2: Access VBA Editor: Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
393
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
1 Sub R1C1Style(): This line defines the beginning of a subroutine named R1C1Style. Sub indicates the start
of a subroutine, followed by the name of the subroutine (R1C1Style), and parentheses to denote that it
doesn’t take any arguments.
2 Selection.FormulaR1C1 = “=rc[-2]*rc[-1]”: This line sets the formula of the selected cell or range using R1C1
reference style. Here’s the breakdown:
• Selection: Refers to the currently selected cell or range in Excel.
• .FormulaR1C1: Indicates that the formula will be assigned using R1C1 reference style.
• =: Assignment operator used to assign the following formula to the selected cell(s).
• “=rc[-2]*rc[-1]”: The formula being assigned. In R1C1 notation:
• rc[-2]: Refers to the cell in the same row (relative reference) and two columns to the left.
• *: Represents the multiplication operator.
• rc[-1]: Refers to the cell in the same row (relative reference) and one column to the left.
3 End Sub: Marks the end of the subroutine R1C1Style. This line tells VBA that the subroutine has finished and
returns control to the main program.
In summary, this subroutine sets the formula of the selected cell(s) to multiply the value in the cell two columns to
the left by the value in the cell one column to the left, using R1C1 reference style.
Step 5: Close VBA Editor:
• Close the VBA editor by clicking the close button or pressing Alt + Q.
Step 6: Run the Macro:
• Press Alt + F8 to open the “Macro” dialog.
• Choose the macro named “ ‘r1c1.xlsm’!Module2.R1C1Style” from the list.
394
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
• Click “Run.”
Result:
395
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 Create Mark Sheet of Students Using R1C1 Reference in VBA and Calculate the following:
• Calculate Total and Average Marks
• Calculate Average
John 80 75 85
Mary 85 90 80
Alice 70 65 75
Bob 75 80 70
EMI Calculator
Amount
Rate of Interest
Year
EMI
396
CITS : IT & ITES - Computer Software Application - Exercise 67
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
TASK 1: Calculating Total Marks of Students
In our first task we’ll calculate the total marks for each student using an array formula in Excel. It’s simple and
easy. Just follow along.
Step 1: In Office 365, Select cell E5 and enter the following formula.
=C5:C14+D5:D14
397
COMPUTER SOFTWARE APPLICATION - CITS
Note: Check the image carefully until you see a light blue line around the cells in Column E.
This is because they are in an array. We didn’t use the Fill Handle or anything like that to fill
these cells.
Here, we’re using Microsoft Excel 365 version. So, we can run the array formula by pressing ENTER. But, in the
older version do the following steps.
• So, first select E5:E14 and type the above formula in cell E5.
• After that, press CTRL + SHIFT + ENTER at a time.
Note: After pressing these buttons, a pair of curly brackets will automatically be applied within
two sides of the formula. You don’t have to write them manually.
Also, you can’t make any changes inside the cell of an array. Excel will not allow you to do this. If you ever try to
do this kind of thing, the following phenomena will happen.
• Here, go to cell E8 and change the cell element to 5.
• After that, press ENTER.
Immediately, Excel will show a warning box on the display like the image below.
398
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
399
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
• Then, go to cell B20 and paste the following formula into that cell.
=FILTER(B5:E14,(C5:C14=B17)*(D5:D14=D17),””)
Here, B5:E14 represents the range of the array. C5:C14 serves as the Section column. B17 performs as the
section to be filtered. D5:D14 means the Subject column. Lastly, D17 acts as the subject to be filtered.
The FILTER function has three arguments. Here, B5:E14 is the array argument. And (C5:C14=B17)*(D5:D14=D17)
is the include argument. Basically, this works like a Boolean array; it carries the condition or criteria for filtering.
In this case, we’ve two criteria combined by a (*) sign.
• After that, tap ENTER.
400
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
From the picture above, we can see that the unit price is decreasing gradually with the increase in order amount.
So, it will cost us less if we order in bulk. Let’s see it in action.
• Initially, go to cell C12 and put the following formula into the cell.
=C11*IF(C11>=101,C9, IF(C11>=51, C8, IF(C11>=21, C7, IF( C11>=11, C6, IF(C11>=1, C5, “”)))))
Formula Breakdown
• IF(C11>=1, C5, ” “) →The IF function checks whether a condition is met, and returns one value if TRUE,
and another one if FALSE. Here, C11>=1 is the logical_test argument which compares the value of the C11
cell with 1. If this value is greater than or equal to 1 then the function returns the value of cell C5
(value_if_true argument) otherwise it returns blank(value_if_false argument).
Output → 20
• IF( C11>=11, C6, IF(C11>=1, C5, “”)) → this becomes IF( C11>=11, C6, 20).
Output → 19
• IF(C11>=21, C7, IF( C11>=11, C6, IF(C11>=1, C5, “”))) → this becomes IF(C11>=21, C7, 19).
Output → 16
• IF(C11>=51, C8, IF(C11>=21, C7, IF( C11>=11, C6, IF(C11>=1, C5, “”)))) → this becomes IF(C11>=51,
C8, 16).
Output → 15
• IF(C11>=101,C9, IF(C11>=51, C8, IF(C11>=21, C7, IF( C11>=11, C6, IF(C11>=1, C5, “”))))) → this becomes
IF(C11>=101,C9, 15).
Output → 13
• C11*IF(C11>=101,C9, IF(C11>=51, C8, IF(C11>=21, C7, IF( C11>=11, C6, IF(C11>=1, C5, “”))))) → this
becomes C11*15.
Output → 80*15 → 1200
• Following this, press the ENTER key.
401
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
You can do it in two ways. The first way is: separate the positive numbers manually, create a new range, and at the
end use the AVERAGE function to find out the average of the positive numbers. Another way is: we can use an
array formula. It will save us time and effort. So, without further delay, let’s see how we can do it.
Steps:
• Primarily, go to cell C5 and enter the following formula.
=AVERAGE(IF(B5:B14>0,B5:B14,FALSE))
Formula Breakdown
Observe closely the arguments of the IF function. You know how the IF function works. If the first argument of the
function is TRUE, then the second argument is returned by the IF function. If the first argument is FALSE, then
the third argument is returned by the IF function. Arguments are separated by commas.
In our case, the third argument is FALSE, so if the first argument is FALSE, then the IF function will return the
FALSE statement.
402
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
OKAY! The main focus is now on the first argument and the second argument. You see the first argument is a
range, and the second argument is also a range. And the whole formula is an array formula.
• IF(B5:B14>0,B5:B14,FALSE) → here Excel will create an array internally with the positive numbers and
False statements.
• Output → {15, FALSE, 14, FALSE, FALSE, 45, 78, 65, 54, FALSE}
AVERAGE(IF(B5:B14>0,B5:B14,FALSE)) → this becomes AVERAGE({15, FALSE, 14, FALSE, FALSE, 45,
78, 65, 54, FALSE}).
• Output → 45.167
The AVERAGE function finds out the average of the values in the array, except the FALSE values, the False
values are not numbers, so the AVERAGE function neglects the FALSE values.
• As usual, press ENTER.
Related Exercises:
• You are managing a bookstore and want to calculate the total revenue generated by each genre of books over
a specific period. Create an Excel spreadsheet with the following details:
• Column A: Book titles.
• Column B: Genre of each book.
• Column C: Unit price for each book.
• Column D: Number of units sold for each book.
• Row 1: Use an array formula to calculate the total revenue generated by each genre by summing the
revenue from each book sold in that genre. Ensure that the array formula adjusts correctly for each genre
as you copy it across.
• You are organizing a charity event and want to track the donations received from different sources. Create an
Excel spreadsheet with the following details:
• Column A: Donation amounts.
• Column B: Donation sources (e.g., Individuals, Corporations, Organizations, etc.).
• Row 1: Use an array formula to calculate the total donations received from each source by summing the
donations from each source. Ensure that the array formula adjusts correctly for each donation source as
you copy it across.
403
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
• You are analyzing the performance of different marketing campaigns and want to calculate the conversion
rate for each campaign based on the number of leads generated and the number of conversions. Create an
Excel spreadsheet with the following details:
• Column A: Campaign names.
• Column B: Number of leads generated by each campaign.
• Column C: Number of conversions from leads for each campaign.
• Row 1: Use an array formula to calculate the conversion rate for each campaign by dividing the number
of conversions by the number of leads generated. Ensure that the array formula adjusts correctly for each
campaign as you copy it across.
• You are managing a restaurant and want to analyze the popularity of different menu items. Create an Excel
spreadsheet with the following details:
• Column A: Menu item names.
• Columns B through G: Weekly sales figures for each menu item for the past six weeks (varying values).
• Row 1: Use an array formula to calculate the total sales for each menu item by summing the sales figures
across all weeks. Ensure that the array formula adjusts correctly for each menu item as you copy it across.
404
CITS : IT & ITES - Computer Software Application - Exercise 68
COMPUTER SOFTWARE APPLICATION - CITS
Objectives
At the end of this exercise you shall be able to
• use various Audit Excel formulas in your task for trouble shooting errors in large data sheets
• check the accuracy of financial reports quickly.
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
TASK 1 : Trace Precedents
Trace Precedents displays tracer arrows from the cells showing the direction of information flow. You see a
blue box around the cells when this method is active. However, one can press this button multiple times to
catch additional levels.
• Choose a cell (D5), and visit the Trace Precedents option from the Formulas tab.
• As a result, we will see two arrows from cell (C5) and cell (C11) indicating towards cell (D5) as the interest
amount is calculated using the principal amount and interest rate.
405
COMPUTER SOFTWARE APPLICATION - CITS
• Finally, you will see the arrows from the cell (C11) to other cells indicating the cells that are dependent on the
value of the selected cell.
406
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
407
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
• Immediately, all the cells with formulas will represent the formulas inside the cells.
TASK 5: Error Checking (Includes Error Checking, Trace Error, Circular References)
Sometimes while applying formulas, you will get errors like #DIV/0!, #VALUE!, #NAME? Errors. To check why it’s
happening you can visit Error Checking option from the Formula tab.
• Select a cell (E5), and hit the Error Checking option from the Formulas tab.
408
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
Now, you can click the Help on this Error option to check in detail about the error
• As a result, a new window will open in your browser providing you details about the error and its solution.
• In order to trace from which cells these are happening, click the Trace Error option from the Formulas tab.
409
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
• Immediately, an arrow will appear to indicate the error and its corresponding cells.
410
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
• Another update will come describing the formula. Click Evaluate again to get the result.
• After completing the evaluation, you will get the cell value in the window.
411
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
• Now choosing the cell (C12), hit the Watch Window feature from the Formulas tab.
• Within a glimpse, a window will open at the top of the spreadsheet showing cell value and formula. This
watch window is really a helpful tool for making a summary of your dataset. And if you scroll or jump to
another sheet the watch window will always be visible on that place.
412
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 You are reviewing a complex financial model and want to trace precedents to understand how a particular
calculation is derived. Perform the following tasks:
• Identify a cell containing a formula that you want to audit.
• Use the “Trace Precedents” feature in Excel to visually trace the cells that contribute to the formula’s
calculation.
• Document the path of precedents to understand the formula’s logic.
2 You are troubleshooting errors in a large dataset and suspect that circular references may be causing incorrect
calculations. Perform the following tasks:
• Use the “Error Checking” feature in Excel to check for circular references within the worksheet.
• If circular references are found, analyze the affected cells to identify and resolve the circular dependency.
3 You are verifying the accuracy of a financial report and want to identify any external references to cells in other
workbooks. Perform the following tasks:
• Use the “Workbook Audit” feature in Excel to audit external references to cells in other workbooks.
• Review the list of external references and ensure that they are accurately referencing the intended data
sources.
4 You are collaborating on a spreadsheet with multiple colleagues and want to track changes made by each
user. Perform the following tasks:
• Enable the “Track Changes” feature in Excel to track changes made to the workbook by different users.
• Review the change history to identify who made specific changes and when they were made.
413
CITS : IT & ITES - Computer Software Application - Exercise 69
COMPUTER SOFTWARE APPLICATION - CITS
Requirements
Tools/Materials
• PC/Laptop with Windows OS
• MS Excel 2013 or Higher
Procedure
TASK 1: Area of a rectangle
Step 1 : Open MS Excel and press Alt+F11 to activate Visual Basic Editor
Step 2: Develop the Interface ie., Place the required Controls from Developer tab in the Excel Sheet and Set the
Properties .
Step 2.1: To set the property Right Click on each controls (CommandButton1& CommandButton2) and select
‘properties’ from the drop down menu.
414
COMPUTER SOFTWARE APPLICATION - CITS
For Example:
Step 3: Double Click on each Control and write down the Code .
Private Sub cmdarea_Click()
Dim length As Integer, breadth As Integer
length = Range(“B2”)
breadth = Range(“B3”)
Range(“A5”) = “Area is”
Range(“B5”) = length * breadth
End Sub
Private Sub cmdclear_Click()
Range(“A5,B2:B5”) = “ “
End Sub
Step 4 : Then save the workbook type as a ‘Excel Macro- Enabled Workbook’
Step 5: Run the Macro
Step 5.1: Click on the Design mode icon to turn of the Design mode .
415
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Step 5.2: Enter the values of Length in Cell B2 and Breadth in Cell B3 AND Click on the Area Button to view the
Area in the Cell B5.
Step 5.3: Clear Button is used to clear the input data and result .
416
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Explanation :
This VBA macro is designed to calculate the area of a rectangle based on the length and breadth entered into
specific cells in an Excel worksheet. Let’s break down the code:
1 Variable Declarations:
• Two integer variables, length and breadth, are declared to store the dimensions of the rectangle.
2 Assigning Values:
• The length variable is assigned the value of the cell B2, which presumably holds the length of the rectangle.
• The breadth variable is assigned the value of the cell B3, which presumably holds the breadth of the
rectangle.
3 Calculating Area:
• The area of the rectangle is calculated by multiplying the length and breadth variables.
• The result is then displayed in cell B5 of the Excel worksheet.
4 Displaying Result:
• The message “Area is” is displayed in cell A5, followed by the calculated area in cell B5.
Explanation Summary:
• The macro retrieves the length and breadth of a rectangle from specific cells in the Excel worksheet.
• It calculates the area of the rectangle using the formula: Area=length×breadthArea=length×breadth.
• The calculated area is displayed in another cell of the worksheet, along with a descriptive label.
This macro simplifies the process of calculating the area of a rectangle in Excel, allowing users to quickly
obtain results based on the provided dimensions.
TASK 2: Create and modify a simple macro in Excel to calculate Body Mass Index (BMI) based on user
input of weight in kilograms and height in meters
Step 1: Open Ms Excel and press Alt+F11 to activate VBE(Visual Basic Editor) and go to Insert Module as
follows:
417
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Step 2: Type the following Sub Procedure and save it in a macro enabled work book
Sub Calculate_BMI()
Dim weight As Double
Dim height As Double
Dim bmi As Double
Dim result As String
‘ Prompt user to enter weight in kilograms
weight = InputBox(“Enter your weight in kilograms:”)
‘ Prompt user to enter height in meters
height = InputBox(“Enter your height in meters:”)
‘ Check if weight and height are greater than 0
If weight > 0 And height > 0 Then
‘ Calculate BMI using the formula: weight / (height * height)
bmi = weight / (height * height)
‘ Determine the BMI category
If bmi< 18.5 Then
result = “Underweight”
ElseIfbmi>= 18.5 And bmi< 25 Then
result = “Normal weight”
ElseIfbmi>= 25 And bmi< 30 Then
result = “Overweight”
Else
result = “Obese”
End If
‘ Display the calculated BMI and category
MsgBox “Your BMI is: “ &Round(bmi, 2) &vbCrLf& “BMI Category: “ & result
418
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Else
‘ Display error message if weight or height is not valid
MsgBox “Invalid input. Please enter valid weight and height.”
End If
End Sub
Step 3 : Run the Macro and view the result.
Output:
419
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
This VBA subroutine named Calculate_BMI calculates the Body Mass Index (BMI) based on the weight and
height entered by the user and categorizes the BMI into different weight categories such as underweight,
normal weight, overweight, and obese. Here’s an explanation of the code:
1 Variable Declarations:
• weight, height, bmi: These variables of type Double are used to store the weight, height, and
calculated BMI, respectively.
• result: This variable of type String holds the category of BMI.
2 Prompt for Weight and Height:
• The user is prompted to enter their weight in kilograms and height in meters using the InputBox function.
3 Check for Valid Input:
• The code checks if the entered weight and height are greater than 0.
4 Calculate BMI:
• If the weight and height are valid, the BMI is calculated using the formula weight / (height * height).
5 Determine BMI Category:
• The BMI is categorized based on standard BMI ranges:
• BMI less than 18.5 is considered “Underweight”.
• BMI between 18.5 and 24.9 is considered “Normal weight”.
• BMI between 25 and 29.9 is considered “Overweight”.
• BMI 30 or greater is considered “Obese”.
6 Display Results:
• The calculated BMI, rounded to two decimal places using the Round function, along with its
corresponding category, is displayed in a message box using the MsgBox function.
7 Error Handling:
• If the user enters invalid input (weight or height less than or equal to 0), an error message is displayed
using MsgBox.
This subroutine provides a simple way to calculate BMI and categorize it, offering users insights into their weight
status.
420
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
421
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Property Box
Step 3: Double click on the Clear button and write down the following code:
Private Sub cmdclear_Click()
Range(“B2:B9,A6:A8”) = “ “
End Sub
Step 4: Double click on the Solution button and write down the following code:
Private Sub cmdsolution_Click()
Dim a As Integer, b As Integer, c As Integer
Dim d As Single, root1 As Single, root2 As Single
a = InputBox(“Enter the value of a”)
b = InputBox(“Enter the value of b”)
c = InputBox(“Enter the value of c”)
Range(“B2”) = a
Range(“B3”) = b
Range(“B4”) = c
d=b*b-4*a*c
Range(“A6”) = “Discriminent”
Range(“B6”) = Round(d, 2)
If d = 0 Then
root1 = -b / (2 *
a)
Range(“A7”) = “Root is “
Range(“B7”) = Round(root1, 2)
Range(“B9”) = “ Roots are real and Equal”
ElseIf d > 0 Then
root1 = (-b + Sqr(d)) / (2 * a)
root2 = (-b - Sqr(d)) / (2 * a)
Range(“A7”) = “Root1 is “
Range(“B7”) = Round(root1, 2)
Range(“A8”) = “Root2 is “
Range(“B8”) = Round(root2, 2)
Range(“B9”) = “ Roots are real and UnEqual”
Else
Range(“B9”) = “ Roots are imaginary”
422
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
End If
End Sub
Step 5: Then save the workbook type as a ‘Excel Macro- Enabled Workbook’
Step 6: Run the Macro and view the result.
423
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
This VBA (Visual Basic for Applications) macro is designed to solve quadratic equations of the form ax² + bx +
c = 0 and display the roots and nature of the roots (real and equal, real and unequal, or imaginary) in an Excel
worksheet.
Here’s an explanation of the macro:
1 Variable Declarations:
• Three integer variables a, b, and c are declared to store the coefficients of the quadratic equation.
• Three single precision variables d, root1, and root2 are declared to store the discriminant and roots of the
equation.
2 User Input:
• The macro prompts the user to input the values of a, b, and c using InputBoxes.
3 Calculating the Discriminant:
• The discriminant d is calculated using the formula: b2- 4ac
• The calculated discriminant is rounded to 2 decimal places.
4 Displaying the Discriminant:
• The calculated discriminant is displayed in cell B6 of the Excel worksheet under the heading “Discriminant”.
5 Determining the Roots:
• The macro checks the value of the discriminant d to determine the nature of the roots.
• If d is equal to 0, there is one real root, which is calculated and displayed.
• If d is greater than 0, there are two real roots, which are calculated and displayed.
• If d is less than 0, the roots are imaginary.
6 Displaying the Roots:
• The roots, along with their nature, are displayed in cells A7, B7 (for root 1), and A8, B8 (for root 2) of the
Excel worksheet.
• If the roots are real and equal or real and unequal, the nature of the roots is displayed in cell B9.
Explanation Summary:
• The macro prompts the user for coefficients of a quadratic equation.
• It calculates the discriminant and determines the nature of the roots.
• The roots and their nature are displayed in an Excel worksheet.
This macro offers a handy tool for quickly solving quadratic equations and understanding their nature within Excel.
Related Exercises:
1 Develop a macro to perform temperature conversion( Celsius to Fahrenheit and Vice versa)
2 Develop a macro for interest calculation(I=PNR)
3 Develop a macro to do Simple Arithmatic Operations
424
CITS : IT & ITES - Computer Software Application - Exercise 70
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
User form is a customised interface, developed in VBA. It enables a user to interact, using a form, in an organised
and logical manner or to enter data and retrieve data with an Excel Worksheet or Run a VBA application.
• User Forms acts as a container in which you add multiple controls, each of which has a specific use and
associated properties.
• Step 1: Navigate to VBA Window by pressing Alt+F11 and Navigate to “Insert” Menu and select “User
Form”. Upon selecting, the user form is displayed as shown in the following screenshot.
425
COMPUTER SOFTWARE APPLICATION - CITS
• Step 3: After adding each control, the controls have to be named through property settings. Caption
corresponds to what appears on the form and name corresponds to the logical name that will be appearing
when you write VBA code for that element.
• Step 4: Add the code for the form load event by performing a right-click on the form and selecting ‘View Code’
426
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
• Step 5: Select ‘Userform’ from the objects drop-down and select ‘Initialize’ method as shown in the following
screenshot.
• Step 6: Upon Loading the form, ensure that the text boxes are
cleared. Private Sub UserForm_Initialize()
txtid.Value = “ “
txtname.Value = “ “
txtbp.Value = “ “
txtda.Value = “ “
txthra.Value = “”
txtded.Value = “ “
txtts.Value = “ “
txtns.Value = “ “
txtid.SetFocus
End Sub
427
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
when the user form is initialized, all text boxes’ contents are cleared or set to default values, and the focus is
set to the txtid text box. This ensures a clean and focused user interface when the form is opened, providing
a clear starting point for user input or interaction.
• Step 7: Now add the code to the Calculate and Submit button. Upon clicking the submit button, the user
should be able to add the values into the worksheet. The following VBA code seems to be part of a user
interface for calculating salaries based on certain inputs such as employee ID, name, basic pay, and
deductions.
Dim row As Long ‘in general declaration
Private Sub cmdcalculate_Click()
Dim eid As Integer, ename As String, bp As Single, da As Single, hra As Single, ts As Single, ns As Single,
ded As Single
Cells(2, 1).Value = “Employee Id”
Cells(2, 2).Value = “Employee Name”
Cells(2, 3).Value = “Basic Pay”
Cells(2, 4).Value = “DA”
Cells(2, 5).Value = “HRA”
Cells(2, 6).Value = “Deduction”
Cells(2, 7).Value = “Total Salary”
Cells(2, 8).Value = “Net Salary”
eid = txtid.Value
ename =
txtname.Text bp =
txtbp.Value
da = bp * (107 / 100)
txtda.Text = da
hra = bp * (25 / 100)
txthra.Text = hra
ded = txtded.Value
txtts.Value = bp + hra + da
txtns.Value = txtts.Value - ded
End Sub
This VBA code seems to be part of a user interface for calculating salaries based on certain inputs such as
employee ID, name, basic pay, and deductions. Let’s break down the code and explain each part:
1 Variable Declarations:
• row As Long: This declares a variable named row as a Long data type. However, this variable is not
used in the provided code snippet.
• eid As Integer, ename As String, bp As Single, da As Single, hra As Single, ts As Single, ns As
Single, ded As Single: These lines declare several variables:
• eid as an Integer to store Employee ID,
• ename as a String to store Employee Name,
• bp, da, hra, ts, ns, and ded as Single data types to store Basic Pay, Dearness Allowance, House Rent
Allowance, Total Salary, Net Salary, and Deductions respectively.
2 Command Button Click Event (cmdcalculate_Click()):
• This subroutine is executed when the user clicks the “Calculate” button.
428
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
• The values from text boxes (txtid, txtname, txtbp, txtded) are assigned to respective variables (eid,
ename, bp, ded).
• Dearness Allowance (da) is calculated as 107% of the Basic Pay (bp) and stored in the da variable.
• House Rent Allowance (hra) is calculated as 25% of the Basic Pay (bp) and stored in the hra variable.
• Total Salary (ts) is calculated as the sum of Basic Pay (bp), Dearness Allowance (da), and House Rent
Allowance (hra) and displayed in the txtts textbox.
• Net Salary (ns) is calculated as the Total Salary (ts) minus Deductions (ded) and displayed in the txtns
textbox.
3 Worksheet Cell Values:
• The lines setting values in Cells(2, 1) through Cells(2, 8) are meant to label the columns in the worksheet.
These cells are likely the headers for the data being entered or calculated.
4 Displaying Calculated Values:
• The calculated values for Dearness Allowance (da) and House Rent Allowance (hra) are displayed in
text boxes txtda and txthra respectively. However, these text boxes are not shown in the provided code
snippet.
Overall, this code snippet captures the process of calculating and displaying employee salary details based on
input provided through a user interface. It seems to be designed to work with Excel VBA given the references to
cells and text boxes.
Private Sub cmdsubmit_Click()
Dim row As Long
‘Determine emptyRow
row = WorksheetFunction.CountA(Range(“A:A”)) + 1
429
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
430
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
Output:
1 CLICK ON CALCULATE BUTTON
Related Exercise:
1 Create a User Form – Student’s Result Sheet (Hints: Design a form with Roll No, Name, Marks of 3
subjects(each subject out of 100), calculate the total marks, percentage and grade and display the details in
the Excel sheet).Grade can be calculated based on the following conditions
431
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
Percentage Grade
>=90 A+
2 Build a form to input student grades for different assignments and exams. Include fields for Assignment Scores,
Exam Scores, and weights for each category. Calculate the overall grade based on weighted averages.
3 Create an Excel form for inventory management. Include fields for Item Name, Quantity In, Quantity Out, and
a button to calculate the current inventory level. Display the calculated inventory level for each item.
432
CITS : IT & ITES - Computer Software Application - Exercise 71
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
Method 1: VLOOKUP
VLOOKUP is a powerful function in Excel used to search for a value in the first column of a range (table or array)
and return a value in the same row from a column you specify.
Syntax:
TASK 1: Create a new dataset with columns ID, Product, and Price. Use the VLOOKUP function to find the
price of a product with ID 201
Products Details
ID Product Price
Now, suppose you want to look up the Price of the Product with ID 201. You can use the VLOOKUP function.
In cell D2, you can enter the formula:
=VLOOKUP(A7,A3:C7,3,FALSE)
433
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• lookup_value: This is the value you want to search for in the first column of the table array (in this case, cell A7).
• table_array: This is the range of cells that contains the data. It must include the column containing the
lookup value and the column containing the data you want to retrieve (in this case, cells A3:C7).
• col_index_num: This is the column number in the table_array from which the matching value should be
returned (in this case, 3, indicating the third column of the table_array).
• range_lookup: This is an optional argument that specifies whether to find an exact match or an approximate
match. If set to FALSE, it will find an exact match.
In the given example, the VLOOKUP function searches for the value in cell A7 within the range A3:C7. It then
returns the value from the third column (index 3) of the range if it finds an exact match. If no exact match is
found, it returns an error or a value specified in the function.
After entering this formula, it will return the Price of the Product with ID 201.
Related Exercises:
1 Create a new dataset with columns ID, Product, and Price, Department. Use the VLOOKUP function to find
the price of a product with ID 104.
434
CITS : IT & ITES - Computer Software Application - Exercise 72
COMPUTER SOFTWARE APPLICATION - CITS
2 Create a dataset with columns EmployeeID, Name, Department, and Salary. Use VLOOKUP to find the salary
of an employee with a given EmployeeID.
3 Create a dynamic table that allows users to input an EmployeeID, and VLOOKUP should automatically fetch
and display the corresponding employee name, department, and salary.
Method 2: HLOOKUP
HLOOKUP is a function in Excel used to search for a value in the first row of a table (or array) and return a value
in the same column from a row you specify. Here’s how to use HLOOKUP in Excel:
Syntax:
TASK 1: Create a dataset with columns Product, Samsung_Price, Apple_Price, and Realme_Price. Use
HLOOKUP to find the price of a specific product in row 2.
435
CITS : IT & ITES - Computer Software Application - Exercise 72
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• C1: The value we are looking for in the first row of the table.
• A1:D4: The table array where the lookup value is located.
• 2: The row number in the table from which to retrieve the value.
• FALSE: Exact match for the lookup value.
Step 3: Result
The formula would return the price of the “Smartphone” from row 2 of the table, which is Rs.100000/-
Related Exercises:
1 Create a dataset with columns representing different cities (Chandigarh, Bhopal, Indore, Patna,
Thiruvananthapuram, Kochi, Surat, Visakhapatnam) and rows representing temperature data for each
month. Use HLOOKUP to find the temperature in Patna for the month of March.
2 Create a dataset with columns representing different months (January, February, March) and rows
representing sales data for each product. Use HLOOKUP to find the sales of a specific product in January.
The INDEX function in Excel is used to return the value of a cell in a specified row and column of a given range.
It is particularly useful when you want to retrieve a specific value from a table of data.
The syntax of the INDEX function is as follows:
INDEX(array, row_num, [column_num])
• array: This is the range of cells from which you want to retrieve the value.
• row_num: This is the row number within the array from which to retrieve the value.
• column_num: (Optional) This is the column number within the array from which to retrieve the value. If omitted,
INDEX returns the entire row specified by row_num.
TASK 1: Consider the following table representing the sales data for different products
436
CITS : IT & ITES - Computer Software Application - Exercise 72
COMPUTER SOFTWARE APPLICATION - CITS
Result:
The result of the formula is the sales value of “Item B” in February, which is 90.
Related Exercises:
1 Create a data range in cells A1 to D10. Use the INDEX function to retrieve the value located in the 4th row
and 3rd column.
2 Create a dataset in column A, starting from A1. Create a formula using INDEX to create a dynamic range
that automatically expands as new data is added in column A.
437
CITS : IT & ITES - Computer Software Application - Exercise 72
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
TASK 1: Change Dates from/to Text
Note: Dates are stored in Excel as consecutive integers, and it is only the formatting of a cell that
permits a number to be shown as a date. All dates are recorded as integers denoting the number
of days from January 1, 1900 (number 1) to December 31, 9999 (number 2958465). You can
change the serial number back to date format by pressing Ctrl+1.
The TEXT function is used to convert a numeric value, date, or time into a text string with a specified format.
Syntax of TEXT function:
=TEXT(value,format_text)
438
COMPUTER SOFTWARE APPLICATION - CITS
The MONTH function extracts the month from a given date and returns it as a numeric value.
Syntax of MONTH function:
=MONTH(date)
439
CITS : IT & ITES - Computer Software Application - Exercise 73
COMPUTER SOFTWARE APPLICATION - CITS
The YEAR function extracts the month from a given date and returns it as a numeric value.
Syntax of YEAR function:
=YEAR(date)
The EOMONTH function finds the last day of the output month based on a specified number of months before
or after a referenced date.
Syntax of EOMONTH function:
=EOMONTH(start_date, months)
440
CITS : IT & ITES - Computer Software Application - Exercise 73
COMPUTER SOFTWARE APPLICATION - CITS
The WEEKDAY function returns the day of the week for a given date and returns it as a numeric value.
Syntax of WEEKDAY function:
=WEEKDAY(date, [return_type])
The WEEKNUM function calculates the week number of a given date based on a specified numbering system.
Syntax of WEEKNUM function:
=WEEKNUM(date, [return_type])
The WEEKNUM function can be used in two different ways based on return type:
Way 1: Week 1 specifies the week which contains January 1st;
Way 2: Week 1 is the week that contains the first Thursday of the year.
441
CITS : IT & ITES - Computer Software Application - Exercise 73
COMPUTER SOFTWARE APPLICATION - CITS
The ISOWEEKNUM function gives the ISO week number of the year of a given date.
Syntax of ISOWEEKNUM function:
=ISOWEEKNUM(date)
442
CITS : IT & ITES - Computer Software Application - Exercise 73
COMPUTER SOFTWARE APPLICATION - CITS
The DAYS360 function calculates the difference between two dates using a 360-day year, assuming each month
has 30 days.
Syntax of DAYS360 function:
=DAYS360(start_date, end_date, [method])
Note: Method is an optional argument to specify the day-count method. TRUE means the function
counts European method and FALSE means the method will be the US method. The default is
FALSE.
The EDATE function adds or subtracts a specified number of months to a given date and returns the resulting
date.
Syntax of EDATE function:
=EDATE(start_date, months)
443
CITS : IT & ITES - Computer Software Application - Exercise 73
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
TASK 1: Prepare 3D Chart based on the following table
Step 1: First open the MS-EXCEL and then write your data there in the sheet.
Step 2: Then select all your required data. Go to the insert option, from this you can insert any type of chart and
graph according to your data.
444
COMPUTER SOFTWARE APPLICATION - CITS
For example here selected a 3D column chart for our dataset. Excel will automatically create the following chart
based on your data.
Once we click on the Format Axis option, Excel will automatically open a Format Axis Pane.Using the format
axis pane, we can format our chart axis according to our requirements. Here, we are going to change units to
display in Major Unit with an increment of ‘50’.
445
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
Step 4: Similarly you can format the chart area by Right Clicking anywhere inside the chart area and choose
format chart area option as follows.
446
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
When selecting Format Chart Area option you will get a dialogue box as shown below.
From this dialogue box you can apply the required options in your chart.
447
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
Combination of two or more chart types in a single chart is known as a combination chart. To create a
combination chart, follow the steps
Step1: First open the MS-EXCEL and then write your data there in the sheet.
Step 2: Create a basic chart and here we are going to plot a column chart for our dataset.
Step 3: We have created a basic chart and now it’s time for complex graphs to play their role. Click either on the
orange bars or blue bars.
Note: Here, we are going to click on the blue bars which are representing the No of Employees. Go
to the design tab, click on the change chart type.
448
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
In that dialog window, navigate to combo from the left side of the panel and click on the employees chart type
drop down menu.
Choose the first graph under the line and press ok.
449
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
The primary axis is the x-axis and the y-axis which is usually on the right side of the chart is known as the
secondary axis. Now add a secondary axis to our Excel chart to make it more understandable and look
presentable.
Step 1: Click on the chart. Go to the Design tab and click on the change chart type, a dialog window appears.
450
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
Click on the change chart type. Then the following dialogue box will appear
In that dialog window, navigate to combo from the left side of the panel and click on it. You will get the following
screen
451
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
In the screen select the required chart type for No of Employees and No of Articles and check the Secondary Axis.
452
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
453
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
Eg 2: Filled Radar
In filled radar charts, the data series is filled with a colour. This chart represents the values relative to a centre
point.
Related Exercise
Here’s a simple table of a sales data containing ProductCode, product Name, QuantitySold and Rate:
454
CITS : IT & ITES - Computer Software Application - Exercise 74
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
Demonstrate PivotTables
A PivotTable in Microsoft Excel is a powerful tool used for summarizing, analyzing, exploring, and presenting
large amounts of data from various sources. It allows users to rearrange and summarize selected columns and
rows of data into a more useful format without altering the original data set. Here’s a step-by-step guide on how
to create a PivotTable in Excel:
1 Prepare your data: Ensure that your data is organized in rows and columns with a clear header row. There
should be no blank rows or columns within the data set. Each column should have a header that describes
the data it contains.
2 Select your data: Click anywhere within the range of data you want to analyze.
3 Insert a PivotTable:
• Go to the “Insert” tab on the Excel ribbon.
• Click on the “PivotTable” button. This will open the “Create PivotTable” dialog box.
4 Choose your data range:
• In the “Create PivotTable” dialog box, Excel will automatically detect the range of your data. Ensure that
this range is correct.
• You can also manually specify the data range if Excel doesn’t detect it automatically.
5 Choose where to place your PivotTable:
• Decide whether you want the PivotTable to be placed in a new worksheet or an existing worksheet.
• Select the location where you want your PivotTable to be placed and click “OK”.
6 Design your PivotTable:
• Once the PivotTable is inserted, you’ll see the PivotTable Field List pane on the right.
• Drag and drop the fields from your data into the “Rows”, “Columns”, “Values”, or “Filters” area, depending
on how you want to summarize and analyze your data.
• You can also apply functions (e.g., sum, count, average) to the values in the PivotTable by clicking on the
drop-down arrow next to the field in the “Values” area and selecting “Value Field Settings”.
7 Customize your PivotTable:
• You can further customize your PivotTable by formatting the cells, changing the layout, applying filters,
sorting data, and more.
• Experiment with different arrangements and configurations to see what best suits your analysis needs.
8 Refresh your PivotTable (if needed):
• If your source data changes, you can refresh your PivotTable to reflect those changes. Right-click anywhere
in the PivotTable and select “Refresh”.
9 Save your workbook:
• Once you’re done creating and customizing your PivotTable, make sure to save your Excel workbook to
preserve your work.
By following these steps, you can create and customize PivotTables in Excel to analyze your data more effectively.
455
COMPUTER SOFTWARE APPLICATION - CITS
TASK 1: Let’s say we wanted to answer the question: What is the amount sold by each salesperson? for
the sales data in the example below. Answering this question could be time consuming and difficult-
each salesperson appears on multiple rows, and we would need to total all of their different orders
individually. We could use the Subtotal command to help find the total for each salesperson, but we
would still have a lot of data to work with.
Fortunately, a PivotTable can instantly calculate and summarize the data in a way that’s both easy to read
and manipulate. When we’re done, the PivotTable will look something like this:
Once you’ve created a PivotTable, you can use it to answer different questions by rearranging-or pivoting-the
data. For example, if we wanted to answer the question: What is the total amount sold in each month? we
could modify our PivotTable to look like this:
To create a PivotTable:
1 Select the table or cells (including column headers) containing the data you want to use.
456
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
3 The Create PivotTable dialog box will appear. Choose your settings, then click OK. In our example, we’ll use
Table1 as our source data and place the PivotTable on a new worksheet.
457
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
5 Once you create a PivotTable, you’ll need to decide which fields to add. Each field is simply a column
header from the source data. In the PivotTable Field List, check the box for each field you want to add. In
our example, we want to know the total amount sold by each salesperson, so we’ll check the Salesperson
and Order Amount fields.
6 The selected fields will be added to one of the four areas below the Field List. In our example, the
Salesperson field has been added to the Rows area, while the Order Amount has been added to the
Values area. Alternatively, you can click, hold, and drag a field to the desired area.
458
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
7 The PivotTable will calculate and summarize the selected fields. In our example, the PivotTable shows the
amount sold by each salesperson.
Just like with normal spreadsheet data, you can sort the data in a PivotTable using the Sort & Filter command
in the Home tab. You can also apply any type of number formatting you want. For example, you may want to
change the Number Format to Currency. However, be aware that some types of formatting may disappear
when you modify the PivotTable.
459
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
If you change any of the data in your source worksheet, the PivotTable will not update automatically. To
manually update it, select the PivotTable and then go to Analyze > Refresh.
Pivoting data
One of the best things about PivotTables is that they can quickly pivot—or reorganize—data, allowing you to
look at your worksheet data in different ways. Pivoting data can help you answer different questions and even
experiment with the data to discover new trends and patterns.
In our example, we used the PivotTable to answer the question: What is the total amount sold by each
salesperson? But now we’d like to answer a new question: What is the total amount sold in each month? We
can do this by simply changing the field in the Rows area.
To change the row:
1 Click, hold, and drag any existing fields out of the Rows area. The field will disappear.
460
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
2 Drag a new field from the Field List into the Rows area. In our example, we’ll use the Month field.
3 The PivotTable will adjust-or pivot-to show the new data. In our example, it now shows the total order
amount for each month.
To add columns:
So far, our PivotTable has only shown one column of data at a time. In order to show multiple columns, you’ll need
to add a field to the Columns area.
1 Drag a field from the Field List into the Columns area. In our example, we’ll use the Region field.
461
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
2 The PivotTable will include multiple columns. In our example, there is now a column for each region.
Filters
Sometimes you may want focus on just a certain section of your data. Filters can be used to narrow down the data
in your PivotTable, allowing you to view only the information you need.
To add a filter:
In our example, we’ll filter out certain salespeople to determine how they affect the total sales.
1 Drag a field from the Field List to the Filters area. In this example, we’ll use the Salesperson field.
462
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
2 The filter will appear above the PivotTable. Click the drop-down arrow, then check the box next to Select
Multiple Items.
3 Uncheck the box for any items you don’t want to include in the PivotTable. In our example, we’ll uncheck the
boxes for a few different salespeople, then click OK.
463
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
Slicers
Slicers make filtering data in PivotTables even easier. Slicers are basically just filters, but they’re easier and faster
to use, allowing you to instantly pivot your data. If you frequently filter your PivotTables, you may want to
consider using slicers instead of filters.
To add a slicer:
1 Select any cell in the PivotTable.
2 From the Analyze tab, click the Insert Slicer command.
464
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
3 A dialog box will appear. Select the desired field. In our example, we’ll select Salesperson, then click OK.
4 The slicer will appear next to the PivotTable. Each selected item will be highlighted in blue. In the example
below, the slicer contains a list of all salespeople, and six of them are currently selected.
5 Just like filters, only selected items are used in the PivotTable. When you select or deselect items, the
PivotTable will instantly reflect the changes. Try selecting different items to see how they affect the
PivotTable. Press and hold the Ctrl key on your keyboard to select multiple items from a slicer.
465
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
You can also click the Filter icon in the top-right corner to select all items from the slicer at once.
466
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
3 The Insert Chart dialog box will appear. Select the desired chart type and layout, then click OK.
467
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
a Create a Pivot Table to display the Order ID and Sum of Total Cost
b Create a Pivot Chart based on that Pivot Table
To create a PivotTable:
1 Select the table or cells (including column headers) containing the data you want to use.
468
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
3 The Create PivotTable dialog box will appear. Choose your settings, then click OK. In our example, we’ll use
Table1 as our source data and place the PivotTable on a new worksheet.
4 The selected fields will be added to one of the four areas below the Field List. In our example, the Order ID
field has been added to the Rows area, while the Total Cost has been added to the Values area.
Alternatively, you can click, hold, and drag a field to the desired area.
469
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
470
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
7 The Insert Chart dialog box will appear. Select the desired chart type and layout, then click OK.
471
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercise.
1 “By using the provided employee data, create a pivot table to analyze the total salary expenditure by
department. Additionally, identify the department with the highest total salary expenditure and the average
salary within that department.”
Customize your pivot table further by applying filters, formatting, and rearranging fields as needed. Also prepare
the Pivot Chart.
2 “By using the following product sales data, analyze the total sales revenue generated by each product.
Additionally, visualize this data by creating both a pivot table and a pivot chart. Identify the product with the
highest total sales revenue and its corresponding sales quantity.
Product Code Product Name Sales Quantity Unit Price Total Price
001 Widget A 100 $10 $1000
002 Widget B 150 $8 $1200
003 Widget C 200 $15 $3000
004 Widget D 75 $20 $1500
005 Widget E 120 $12 $1440
006 Widget F 90 $18 $1620
472
CITS : IT & ITES - Computer Software Application - Exercise 75
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
How to Install Power Query
Excel 2016
Power Query is included with Excel 2016 (Office 365). It has been renamed and is now on the Data tab of the
Ribbon in the Get & Transform section.
This means there is nothing to install. If you are using Excel 2016, go to the Data tab on the ribbon and press the
New Query button to create a query and open the Power Query editor.
Power Query is available with all levels of Office 365 subscriptions.
Excel 2010 & 2013
For Excel 2010 and 2013 you will need to download the Power Query add-in and install it.
The installation steps are about the same in Excel 2010 and 2013.
1 Close (exit) Excel completely.
2 Click the following link to go to the download page.
https://www.microsoft.com/en-us/download/details.aspx?id=39379
3 Click the Download button.
473
COMPUTER SOFTWARE APPLICATION - CITS
4 Click the checkbox for the bit version you are using. Most likely you will be using 32-bit.
5 Click Next
6 The add-in installation file will download. Click the file to run the installation.
474
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
7 The Setup Wizard window will open. Follow the steps to install Power Query.
8 Once the installation is complete, open Excel. You should now see the Power Query tab in the Ribbon.
475
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
6 That will open the COM Add-ins Window. If the Power Query check box is not selected, just select it to reload
the add-in.
476
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
TASK 1: Create a simple Power Query program using a sample Excel file
1 Load Data:
• Open Excel and create a new workbook.
• Enter some sample data into a worksheet.
• Go to the “Data” tab and click “Get Data” > “From Table/Range.”/ Go to the “Power Query” tab and click
“From Table/Range.”
477
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
478
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
3 Transform Data:
• Let’s add a new column that calculates a bonus based on the Principal Amount. Click on “Add Column” >
“Custom Column.”
479
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
480
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2: Create a simple Power Query program using a sample Excel file
481
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
• Select the data and Go to the “Data” tab and click “Get Data” > “From Table/Range.”/ Go to the “Power
Query” tab and click “From Table/Range.
• Then Power Query Editor will open. Here, you can see a preview of your data.
482
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
483
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
484
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
// Add a new column “Sum” by adding the values from the referenced cells
CombinedQuery = Table.AddColumn(Source, “Sum”, each [Principal Amount] + [Interest])
• Excel.CurrentWorkbook(): Function that references the entire current workbook.
• {[Name=”Table13_2”]}: Accesses a specific table in the workbook named “Table13_2.”
• [Content]: Retrieves the content of the “Table13_2” table.
Add a New Column “Sum”
// Add a new column “Sum” by adding the values from the referenced cells
CombinedQuery = Table.AddColumn(Source, “Sum”, each [Principal Amount] + [Interest])
• Table.AddColumn(Source, “Sum”, each [Principal Amount] + [Interest]): Adds a new column named
“Sum” to the Source table.
• each [Principal Amount] + [Interest]: Defines the operation to be performed in each row of the new “Sum”
column. It adds the values from the “Principal Amount” and “Interest” columns.
• Click “Close & Apply” to apply the changes and load the data into your Excel workbook or Power BI report.
485
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
This code assumes that you have a table named “Table13_2” in your workbook with columns named “Principal
Amount” and “Interest.” The result is a new table (CombinedQuery) that includes the original columns from
“Table13_2” and an additional column named “Sum” containing the sum of the “Principal Amount” and “Interest”
values for each row.
TASK 3 :
Create a table named “OrderDetails” containing columns for “Product”, “Quantity”, and “UnitPrice”. Apply a 10%
discount to the “UnitPrice” for orders where the quantity purchased is greater than or equal to 10.
Order Details
Product A 8 20.00
Product B 15 30.00
Product C 5 10.00
Product D 12 25.00
Product E 20 15.00
Product F 9 18.00
Product G 7 22.00
Product H 14 28.00
Product I 6 12.00
Product J 11 35.00
486
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
1 Load Data:
• Open Excel and create a new workbook.
• Enter some sample data into a worksheet.
• Go to the “Data” tab and click “Get Data” > “From Table/Range.”/ Go to the “Power Query” tab and click
“From Table/Range.”
487
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
3 Transform Data:
• Let’s add a new column that calculates a DiscountedPrice based on the Quantity. Click on “Add Column” >
“Custom Column.”
488
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
489
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
• Let’s add a new column that calculates Net Price based on the Quantity, Unit Price and Discounted Price.
Click on “Add Column” > “Custom Column.”
490
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
491
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
TASK 4:
As an HR analyst at a company managing employee information, you have been provided with two tables in your
Excel workbook: “EmployeeData” and “DepartmentData”. The “EmployeeData” table contains details of
employees, including their ID, name, and department ID, while the “DepartmentData” table includes information
about departments, including their ID and name.
Your task is to perform the following operations:
1 Merge the “EmployeeData” and “DepartmentData” tables based on the department ID to create a
consolidated dataset.
2 Add a new column in the consolidated dataset containing the name of the department for each employee.
3 Organize the workbook queries to ensure efficient management.
Employee Data Table:
492
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
493
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
3 In the “Navigator” window, select both tables and click “Load” to load them into the Power Query Editor.
494
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
6 Choose “DepartmentData” from the dropdown list and select “Department ID” as the matching column.
7 Select an appropriate join type, such as “Inner Join”, and click “OK”.
495
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
496
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
Related Exercises:
1 Create “Employee Data” table containing information about employees, including their EmployeeID, Name,
Department, and Salary. Your task is to perform advanced filtering and parameterization to analyze
employee bonuses based on salary levels.
Employee Data:
TASKS :
497
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
TASKS :
1 Load the “Sales Data” into Power Query.
2 Combine this table with a reference table containing information about each product, such as the
“ProductID” and “ProductCategory.” Assume this reference table is named “ProductInfo.”
3 Aggregate the combined data to calculate the total revenue for each product category.
4 Create a new column in the final table named “AverageRevenuePerUnit” that calculates the average revenue
per unit sold for each product category.
You have a “Monthly Sales” table containing information about sales data over several months. Your task is to
perform time series analysis to understand the trends in monthly sales.
TASKS :
1 Load the “Monthly Sales” into Power Query.
2 Create a new column named “Month” that extracts the month and year from the “Date” column.
3 Calculate the month-to-month percentage change in sales and add it as a new column.
4 Identify any months with significant increases or decreases in sales.
498
CITS : IT & ITES - Computer Software Application - Exercise 76
COMPUTER SOFTWARE APPLICATION - CITS
Procedure
Power BI is a powerful business analytics tool developed by Microsoft. It allows users to visualize and analyze
data from various sources in interactive reports and dashboards.
Download and Install Power BI Desktop
Here are some requirements of the system to download the Power BI Desktop:
• Window 7, window 8, window 8.1, window 10, and windows server 2008 R2, windows server 2012, windows
server 2012 R2.
• It requires internet explorer 9 or higher.
• Power BI Desktop is available for both 32 bit and 64-bit platforms.
• Let’s see the downloading process of the Power BI Desktop step by step:
Step 1: Click on the below link to directly download Power BI Desktop. https://powerbi.microsoft.com/en-us/
desktop/
Step 2: Then click on the Download Free button.
Step 3: Now, you will redirect to a Microsoft Store and then select the Get button.
499
COMPUTER SOFTWARE APPLICATION - CITS
you can see the progress status of the Power BI Desktop on the screen.
Step 5: You can see “welcome to Power BI Desktop” screen and then register yourself on the desktop.
500
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
Step 6: When you run the Power BI desktop, it displayed the home page or welcome screen.
Power BI Dashboard
Power BI dashboard is a single page, also called a canvas that uses visualization to tell the story. It is limited to
one page; therefore, a well-designed dashboard contains only the most essential elements of that story.
The visualizations visible on the dashboard are known as tiles. These tiles are pinned to the dashboard from
reports. The visualizations on a dashboard come from reports, and each report is based on one data set.
A dashboard can combine on-premises and cloud-born data. And they are providing a consolidated view
regardless of where the data lies.
501
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
Step 4: Select the procurement analysis sample file. Eg: You can select the sample data set from the link https://
www.kaggle.com/datasets
502
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
It starts import excel workbook and creating report view worksheets shown in the below screenshot.
503
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
Step 7: When the completed message appears, then select the Close button to dismiss it.
In the below screenshot, you can see the discount analysis of the imported dataset in the form of tiles.
504
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
Power BI Reports
A Power BI report is a multi-perspective view into the dataset, with visualizations which represent different
findings and insights from that dataset.
A report can have a single visualization or multiple visualizations. The visualizations in a report represent
something like a dashboard does but serve a different purpose.
These visualizations are not static. These are highly interactive & highly customizable visualizations which
update, as the underlying data changes. You can add and remove the data, change visualization types, and
apply filters in your model to discover insights.
Related Exercises:
Simple Data Visualizations in Power BI
Scenario:
You have been provided with a dataset containing information about monthly sales for a retail business. The
dataset includes columns such as Date, Product Category, Sales Amount, and Region.
TASKS:
1 Import Data:
• Load the provided dataset into Power BI.
2 Data Cleaning and Transformation:
• Perform any necessary data cleaning and transformation steps to ensure the data is suitable for analysis.
3 Create Visualizations:
• Design the following visualizations:
• Line Chart: Display the trend of total sales over different months.
505
CITS : IT & ITES - Computer Software Application - Exercise 77
COMPUTER SOFTWARE APPLICATION - CITS
506
CITS : IT & ITES - Computer Software Application - Exercise 77