Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra

Kerala Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra

Number System:
It is a systematic way to represent numbers in different ways. Each number system has its own Base, that is a number and that number of symbols or digits used.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 1

  1. Most Significant Digit (MSD): The digit with most weight is called MSD. MSD is also called Left Most Digit(LMD)
  2. Least Significant Digit (LSD): The digit with least weight is called LSD. LSD is also called Right Most Digit(RMD)
    • eg: 106 : Here MSD : 1 and LSD : 6
    • 345.78: Here MSD : 3 and LSD : 8
  3. A Binary Digit is also called a bit.
  4. The weight of each digit of a number can be represented by the power of its base.

Number conversions:
In general, to convert a decimal number into another number system(binary or octal or hexadecimal) do the following. Divide the number successively by the base of the number system do you want to convert and write down the remainders from bottom to top.

To convert a decimal fraction into another number system .multiply the number by the base of the number system do you want to convert then integer part and fractional part are separated again multiply the fractional part by the base and do the steps repeatedly until the fractional part becomes zero. Finally write down the integer part from top to bottom.

Decimal to Binary:
Divide the number by the base 2 successively and write down the remainders from bottom to top.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 2

Decimal fraction to binary:
multiply the number by the base 2 then integer part and fractional part are separated again multiply the fractional part by the base 2 and do the steps repeatedly until the fractional part becomes zero. Finally write down the integer part from top to bottom.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 3

Decimal to Octal:
Divide the number by the base 8 successively and write down the remainders from bottom to top.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 4
Decimal fraction to octal:
multiply the number by the base 8 then integer part and fractional part are separated again multiply the fractional part by the base 8 and do the steps repeatedly until the fractional part becomes zero. Finally write down the integer part from top to bottom.
eg: (55)10 = ()8
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 5
(0.140625)10 = (0.11)8

Decimal to Hexadecimal:
Divide the number by the base 16 successively and write down the remainders from bottom to top.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 6
Decimal fraction to hexadecimal:
multiply the number by the base 16 then integer part and fractional part are separated again multiply the fractional part by the base 16 and do the steps repeatedly until the fractional part becomes zero. Finally write down the integer part from top to bottom.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 7
Converting a number from any number system into decimal: For this multiply each digit by its corresponding weight and sum it up.

Binary to decimal conversion:
For this multiply each bit by its corresponding weight and sum it up. The weights are power of 2.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 8
Converting binary fraction to decimal
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 9
101.101 = 1 × 22 + 0 × 21 + 1 × 20 + 1 × 2-1 + 0 × 2-2 + 1 × 2-3
= 4 + 0 + 1 + 1/2 + 0 + 1/8
= 5 + 0.5 + 0.125
(101.101)2 = (5.625)10

Octal to decimal conversion:
For this multiply each bit by its corresponding weight and sum it up. The weights are power of 8.
Eg: (1007)8 =()10?
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 10
1 × 83 + 0 × 82 + 0 × 81 + 7 × 80
= 512 + 0 + 0 + 7
=(519)10
Converting octal fraction to decimal (600.005)8 =()10?

Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 11

= 6 × 82 + 0 × 81 + 0 × 80 + 0 × 8-1 + 0 × 8-2 + 5 × 8-3
= 384 + 0 + 0 + 0 + 0 + 0.009765625
= (384.009765625)10

Hexadecimal to decimal conversion:
For this multiply each bit by its corresponding weight and sum it up. The weights are power of 16.
Eg: (100)16 = ()10?
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 12
= 1 × 162 + 0 × 161 + 0 × 160
= 256 + 0 + 0
= (256)10
Converting Hexadecimal fraction to decimal (60A.4)8 =()10?
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 13
= 6 x 162 + 0 x 161 + 10 x 160 + 4 x 16-1
= 1536 + 0 + 0 + .25
= (1536.25)10

Octal to binary conversion:
Convert each octal digit into its 3 bit binary equivalent. Consider the following table
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 14

Hexadecimal to binary conversion:
Convert each Hexadecimal digit into its 4 bit binary equivalent. Consider the following table
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 15

1010 1011 1100 (ABC)16=(101010111100)2

Binary to octal conversion
Divide the binary number into groups of 3 bits starting from the right to left(But in the fractional part start dividing from left to right). Insert necessary zeros in the left side(or right side in the case of fractional part)if needed and write down the corresponding octal equivalent.
eg: (10100110)2= ()8?
Insert one zero in the left side to form 3 bits group
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 16
(10100110)2= (246)8

Binary to Hexadecimal conversion:
Divide the binary number into groups of 4 bits starting from the right to left(But in the fractional part start dividing from left to right). Insert necessary zeros in the left side(or right side in the case of fractional part)if needed and write down the corresponding Hexadecimal equivalent.
eg: (100100110)2 = ()16?
Insert 3 zeros in the left side to form 4 bits group
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 17
(100100110)2 = (126)16

Octal to Hexadecimal conversion:
First convert octal number into binary(see 1.6.7), then convert this binary into hexadecimal(also see 1.6.10)
eg: Convert (67)8 = ( )16
Step I: First convert this number into binary equivalent for this do the following:
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 18
Step II: Next convert this number into hexadecimal equivalent for this do the following.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 19
So the answer is (67)8 = ( 37)16

Hexadecimal to octal conversion:
First convert Hexadecimal to binary(see 1.6.8), then covert this binary into octal(also see 1.6.9)
eg: Convert (A1)16 = ( )8?
Step I: First convert this number into binary equivalent. For this do the following
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 20
Step II. Next convert this number into octal equivalent. For this do the following.
So the answer is (A1)16 = (241)8

Data representation:
The data stored in the computer memory is in the form of binary.

Representation of integers
There are three ways to represent integers in computer. They are as follows:

  1. Sign and Magnitude Representation (SMR)
  2. 1’s Complement Representation
  3. 2’s Complement Representation

1. SMR:
Normally a number has two parts sign and magnitude, eg: Consider a number+5. Here + is the sign and 5 is the magnitude. In SMR the most significant Bit (MSB) is used to represent the sign. If MSB is 0 sign is +ve and MSB is 1 sign is -ve. eg: If a computer has word size is 1 byte then
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 21
Here MSB is used for sign then the remaining 7 bits are used to represent magnitude. So we can , represent 27 = 128 numbers. But there are negative and positive numbers. So 128 + 128 = 256 number. The numbers are 0 to +127 and 0 to -127. Here zero is repeated. So we can represent 256 – 1 = 255 numbers.

2. 1’s Complement Representation:
To get the 1’s complement of a binary number, just replace every 0 with 1 and every 1 with 0. Negative numbers are represented using 1’s complement but +ve number has no 1 ’s complement,
eg:
(i) To find the 1’s complement of -21
+21 = 00010101
To get the 1’s complement change all 0 to 1 and.all 1 to 0.
-21 = 11101010
1’s complement of-21 is 11101010

(ii) Find the 1’s complement of +21. Positive numbers are represented by using SMR.
+21 = 00010101 (No need to take the 1’s complement)

3. 2’s Complement Representation:
To get the 2’s complement of a binary number, just add 1 to its 1’s complement +ve number has no 2’s complement.
eg: To find the 2’s complement of -21
+21 = 00010101
First take the 1’s complement for this change all 1 to 0 and all 0 to 1
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 22
2’s complement of -21 is 1110 1011

Representation of floating point numbers:
A real number consists of an integer part and fractional part and represent by using Exponent and Mantissa method. This method is also used to represent too big numbers as well as too small numbers.
Eg: .0000000000000000000000001 can be represented easily as 1 × 10-25. Here T is the Mantissa and -25 is the exponent.

A computer with 32 bit word length is used 24 bits for mantissa and the remaining 8 bits used to store exponent.

Representation of characters:
1. ASCII(American Standard Code for Information Interchange):
It is 7 bits code used to represent alphanumeric and some special characters in computer memory. It is introduced by U.S. government. Each character in the keyboard has a unique number.

Eg: ASCII code of ‘a’ is 97, when you press ‘a’ in the keyboard , a signal equivalent to 1100001 (Binary equivalent of 97 is 1100001) is passed to the computer memory. 27 = 128, hence we can represent only 128 characters by using ASCII. It is not enough to represent all the characters of a standard keyboard.

2. EBCDIC(Extended Binary Coded Decimal Interchange Code):
It is an 8 bit code introduced by IBM(lnternational Business Machine). 28 = 256 characters can be represented by using this.

3. ISCII(lndian Standard Code for Information Interchange):
It uses 8 bits to represent data and introduced by standardization committee and adopted by Bureau of Indian Standards(BIS).

4. Unicode:
The limitations to store more characters is solved by the introduction of Unicode. It uses 16 bits so 216 = 65536 characters (i.e, world’s all written language characters) can store by using this.

Binary arithmetic:
Binary addition:
The rules for adding two bits
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 23
eg: Find the sum of binary numbers 110011 and 100001.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 24

Binary subtraction:
The rules for subtracting a binary digit from another digit.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 25

Subtraction using 1’s complement:
The steps are given below:

Step 1: Add 0s to the left of the subtrahend, to make two numbers with same number of bits.
Step 2: Find 1’s complement of subtrahend.
Step 3: Add the complement with minuend.
Step 4: If there is a carry, ignore the carry, the result is positive then add the carry 1 to the result.
eg: Subtract 1101 from 111100 using 1’s complement method.
Step 1: Insert two Os to the left of 1101. Hence the subtrahend is 001101.
Step 2: 1’s complement of 001101 is 110010
Step 3: Add this to the minuend.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 26
Step 4: Ignore the carry the result is positive and add add the carry 1 to 101110
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 27
Hence the result is 101111.

Subtraction using 2’s complement:
The steps are given below :
Step 1: Add 0s to the left of the subtrahend, to make two numbers with same number of bits.
Step 2: Find 2’s complement of subtrahend.
Step 3: Add the complement with minuend.
Step 4: If there is a carry, ignore the carry, the result is positive.
eg: Subtract 1101 from 111100 using 2’s complement method.
Step 1: Insert two 0s to the left of 1101. Hence the subtrahend is 001101.
Step 2: Find the 2’s complement of 001101.
1’s complement is 110010.
2’s complement is 110010 + 1 = 110011
Step 3: Add this to the minuend.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 28
Step 4: Ignore the carry the result is positive. Hence the result is 101111.

Introduction to Boolean algebra:
The name Boolean Algebra is given to honour the British mathematician George Boole. Boolean algebra deals with two states true or false otherwise Yes or No and numerically either 0 or 1.

Binary valued quantities:
A logical decision which gives YES or No values is a binary decision, A statement which gives YES or NO values(TRUE or FALSE) is a logical statement or truth function. A variable which can assign TRUE or FALSE (1 or 0) values is a logical variable

Boolean operators and logic gates:
Logical Operators are AND, OR and NOT. A logical gate is a physical device (electronic circuit)that can perform logical operations on one or more logical inputs and produce a single logical output. A table represents the set f all possible values and the corresponding results in a statement is called truth table.
1. The OR operator and OR gate:
The OR operator gives a 1 either one of the operands is 1. If both operands are 0, it produces 0. The truth table of X OR Y is
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 29
The logical OR gate is given below.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 30
The truth table and the gate for the Boolean expression Y = A + B + C
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 31

2. The AND operator and AND gate:
The AND operator gives a 1 if and only if both operands are 1. If either one of the operands is 0, it produces 0 The truth table of X AND Y is
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 32
The logical AND gate is given below.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 33
The truth table and the gate for the Boolean expression Y = A . B . C
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 34
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 35

3. The NOT operator and NOT gate:
It produces the vice versa. NOT gate is also called inverter. It is a unary operator that means it has only one input and one output. The truth table of NOT X is
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 36

Basic postulates of Boolean algebra:
Boolean algebra consists of some fundamental laws. These laws are called postulates.
Postulate 1: Principles of 0 and 1
If A ≠ 0 , then A = 1 and A 1, then A = 0
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 37

Principle of Duality:
When changing the OR(+) to AND(.), AND (.) to OR(+), 0 to 1 and 1 to 0 in a Boolean expression we will get another Boolean relation which is the dual of the first, this is the principle of duality.

Basic theorems of Boolean algebra:
There are some standard and accepted rules in every theory, these rules are known as axioms of the theory.

Identity law:
If X is a Boolean variable, the law states that

  1. 0 + X = X
  2. 1 + X = 1 (these are additive identity law)
  3. 0 . X = 0
  4. 1 . X = X (these are multiplicative identity law)

Following are the truth tables
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 38

Idempotent law:
This law states that

  1. X + X = X
  2. X . X = X

Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 39

Involution law:
This states that
\(\overline{\overline{\mathrm{X}}}=\mathrm{x}\)
The compliment of compliment of a number is the number itself.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 40

Complimentary law:
This law states that

  1. \(x+\bar{x}=1\)
  2. \(x \cdot \bar{x}=0\)

The truth table is given below
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 41

Commutative law:
This law allows to change the position of variable in OR and AND

  1. X + Y = Y + X
  2. X . Y = Y . X

The truth table is given below
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 42

Associative law:
It allows grouping of variables differently

  1. X + (Y + Z) = (X + Y) + Z
  2. X . (Y . Z) = (X . Y) . Z

The truth table is given below
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 43

Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 44

Distributive law:
This law allows expansion of multiplication over addition and also allows addition operation over multiplication.

  1. X . (Y + Z) = X . Y + X . Z
  2. X + Y . Z = (X + Y) . (X + Z)

The truth table is given below
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 45

Absorption law:
It is a kind of distributive law in which two variables are used and result will be one of them

  1. X + (X . Y) = X
  2. X . (X + Y) = X

The truth table is given below
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 46

De Morgan’s theorem:
Demorgan’s first theorem states that
\(\overline{\mathrm{X}+\mathrm{Y}}=\overline{\mathrm{X}} \cdot \overline{\mathrm{Y}}\)
ie. the compliment of sum of two variables equals product of their compliments.

The second theorem states that
\(\overline{\mathrm{X} . {\mathrm{Y}}}=\overline{\mathrm{X}}+\overline{\mathrm{Y}}\)
ie. The compliment of the product of two variables equals the sum of the compliment of those variables.

Circuit designing for simple Boolean expressions:
By using basic gates such as AND, OR and NOT gates we can create logic circuits.

Universal gates:
By using NAND and NOR gates only we can create other gates hence these gates are called Universal gate.

NAND gate:
The output of AND gate is inverted by NOT gate is the NAND gate
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 47

NOR gate:
The output of OR gate is inverted by NOT gate is the NOR gate.
Plus One Computer Science Notes Chapter 2 Data Representation and Boolean Algebra 48

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 12 Internet and Mobile Computing

Kerala Plus One Computer Science Notes Chapter 12 Internet and Mobile Computing

Summary
History of the Internet:
Internet means international network of networks. The first form of Internet is ARPANET(Advanced Research Project Agency Network) started by US Department of Defence for their military during 1970’s. In 1989 a team lead by Tim Berners Lee introduced WWW(World Wide Web) by using the protocol HTTP. In 1998, Internet Corporation for Assigned Names and Numbers (ICANN) was established.

Internet:
It is a network of networks. It means that international network. We can transfer information between computers within nations very cheaply and speedily.

Intranet:
A private network inside a company or organisation is called intranet.

Extranet:
It allows vendors and business partners to access the company resources.

The hardware and software requirement for internet:

  • A computer with a modem (internal/external)
  • A telephone connection
  • An account with an ISP
  • A browser S/W eg: Internet Explorer or Mozilla…

Types of connectivity:
There are two ways to connect to the internet. First one dialing to an ISP’s computer or with a direct connection to an ISP.

Dial-up Connection:
Here the internet connection is established by dialing into an ISP’s computer. If ISP is not busy they verify the user name and password if it is valid they will connect our computer to the internet.lt uses Serial Line Internet Protocol (SLIP) or Point to Point Protocol (PPP). It is slower and has a higher error rate.

Direct connection:
In direct connection there is a fixed cable or dedicated phone line to the ISP. Here it uses ISDN (Integrated Services Digital Network) a high speed version of a standard phone line. Another method is leased lines that uses fibre optic cables.

Digital Subscribers Line (DSL) is another direct connection, this uses copper wires instead of fibre optic for data transfer. Direct connection provides high speed internet connection and error rate is less. Fibre To The Home(FTTH) uses optical fibers for data transmission.

Wireless broadband connectivity:
1. Mobile broadband:
Accessing Internet using wireless devices like mobile phones, tablet, USB dongles.

2. Wi MAX(Wireless Microwave Access):
It uses micro waves to transmit information across a network in a range 2 GHz to 11 GHz over very long distance.

3. Satellite broadband:
Accessing internet through satellite. A Very Small Aperture Terminal(VSAT) dish antenna and transceiver and modem are required at the user’s location. Expensive and high speed.

Internet access sharing methods:
One Internet connection can be shared among several computers using a LAN, Wi Fi or Li Fi.
1. Using LAN:
The Internet connection in a LAN can be shared among other computers in the network

2. Using Wi Fi(Wireless Fidelity):
It uses radio waves to transmit information across a network in a range 2.4 GHz to 5 GHz in short distance. Nowadays this technology is used to access internet in campuses, hyper markets, hotels by using Laptops, Desktops, tablet, mobile phones etc

3. Using Li Fi(Light Fidelity) network:
It is a fast optical(uses visible light for data transmission) version of Wi Fi. Its main component is a LED lamp that can transmit data and a photodiode that acts as a receiver.

Services on Internet:
1. www(World Wide Web):
This means this website address is unique and can be accessed each nook and corner of the world.

2. A browser is a piece of software that acts as an interface between the user and the internal working of the internet. With the help of a browser the user can search information on the internet and it allows user to navigate through the web pages. The different browsers are

  • Microsoft internet explorer
  • Mozilla Firefox
  • Netscape Navigator
  • Google Chrome
  • Opera.

3. Web Browsing:

  1. The browser determines the URL entered.
  2. The browser asks the DNS for URLS corresponding IP address (Numeric address)
  3. The DNS returns the address to the browser.
  4. The browser makes a TCP connection using the IP address.
  5. Then it sends a GET request for the required file to the server.
  6. The server collects the file and send it back to the browser.
  7. The TCP connection is released.
  8. The text and the images in the web pages are displayed in the browser.

Search engines:
By using search engines we will get a variety of information. It is a newly developed tool that helped to search the information on the internet more effectively and easily. Search engines are programs that help people to locate information from crores of website on internet using a database that consists of references.

Users can interact with the search engine through the home page of the search engine. To get the information about artificial intelligence just type this in the box provided for it and click the search button. Search engines searches by using a particular search algorithm then displays the matching documents or web addresses.

Search engine use soft wares called spiders or bots to search documents and their web addresses. Spiders search the internet using the directions given by the search engines and prepare an index and stores it in a database. The searching algorithm searched this database when the users submits a request and create a web page displaying the matching results as hyperlinks.
eg: Google, Yahoo, Rediff etc.

E mail(Electronic mail):
It is used to send text, multi media messages between computers over internet. An example of an email id is [email protected]. Here jobi_cg is the user name, rediffmail is the website address and .com is the top level domain which identifies the types of the organisation. To send an email we require an email address. Some websites provide free email facility.

To send an email first type the recipients address and type the message then click the send button. The website’s server first check the email address is valid, if it is valid it will be sent otherwise the message will not be sent and the sender will get an email that it could not deliver the message.

This message will be received by the recipient’s server and will be delivered to recipient’s mail box. He can read it and it will remain in his mail box as long as he will be deleted. Simple Mail Transfer Protocol(SMTP) is used.
The email message contains the following fields:

  1. To: Recipient’s address will be enter here. Multiple recipients are also allowed by using coma.
  2. CC: Enterthe address of other recipients to get a carbon copy of the message.
  3. bcc: The address to whom blind carbon copies are to be sent. This feature allows people to send copies to third recipient without the knowledge of primary and secondary recipients
  4. From: Address of the sender
  5. Reply to: The emait address to which replies are to be sent.
  6. Subject: Short summary of the message.
  7. Body: Here the actual message is to be typed.

The advantages of email are given below:

  1. Speed is high
  2. It is cheap
  3. We can send email to multiple recipients
  4. Incoming messages can be saved locally
  5. It reduces the usage of paper
  6. We can access mail box anytime and from anywhere.

The disadvantages are:

1. It requires a computer, a modem, software and internet connection to check mail.
2. Some mails may contain viruses
3. Mail boxes are filled with junk mail. So very difficult to find the relevant mail.

Social media:
Various social medias are Internet forums, social blogs, microblogs etc.

  1. Internet forums: It is an online discussion site where people can exchange information about various issues like social, political, educational etc in the text form.
  2. Social blogs: Conducting discussions about . particular subjects by entries or posts. eg: Blogger.com
  3. Microblogs: It allows users to exchange short messages, multi media files etc. eg: www.twitter.com
  4. Wikis: In this we can give our contributions regarding various topics. eg: www.wikipedia.org
  5. Social networks: By using these web sites we can post our data and’ view others data. eg: www.facebook.com
  6. Content communities: By using these websites we can share multi media files. eg: www.youtube.com

Advantages of social media:

  1. Bring people together: It allows people to maintain the friendship
  2. Plan and organize events: It allows users to plan and organize events.
  3. Business promotion: It helps the firms to promote their sales.
  4. Social skills: There is a key role of the formation of society.

Disadvantages:

  1. Intrusion to privacy: Some people may misuse the personal information.
  2. Addiction: sometimes it may waste time and money.
  3. Spread rumours: The news will spread very quickly and negatively.

Cyber Security:
It is used to provide protection of valuable information such as credit card information from unauthorized access, intentional access, deletion, etc. while shopping on the internet.

Computer virus:
A virus is a bad program or harmful program to damage routine working of a computer system. It reduces the speed of a computer. It may delete the useful system files and make the computer useless.

Worm:
It is a stand alone malware program that replicates itself in order to spread to other computers. It slows down the traffic by consuming the bandwidth. In 2000 a worm called “ILOVEYOU” is affected many computers.

Trojan horse:
It appears as a useful software but it is a harmful software and it will delete useful software or files.

Spams:
Sending an email without recipient’s consent to promote a product or service is called spamming. Such an email is called a spam.

Hacking:
It is a process of trespassing computer networks. Two types white hats and black hats. White hats hack the computer networks to test the security but black hats intentionally stealing valuable data or destroying data.

Phishing (Fishing):
It is an attempt to get others information such as usenames, passwords, bank a/c details etc by acting as the authorized website. Phishing websites have URLs and home pages similar to their original ones and mislead others , it is called spoofing.

Denial of Service(DoS) attack:
Its main target is a Web server. Due to this attack the Web server/computer forced to restart and this results refusal of service to the genuine users. If we want to access a website first you have to type the web site address in the URL and press Enter key, the browser requests that page from the web server.

Dos attacks send huge number of requests to the web server until it collapses due to the load and stops functioning.

Man in the Middle attacks:
It is an attack in which an attacker secretly intercepts electronic messages send by the sender to the receiver and then modifies the message and retransmit it to the receiver.

To prevent this type of attack encrypted connections such as HTTPS(HTTP Secure), SFTP(Secure FTP) etc, must be used, that will be displayed in the URL.

Preventing network attacks
Firewall:
It is a system that controls the incoming and outgoing network traffic by analyzing the data and then provides security to the computer network in an organization from other network (internet).

Antivirus scanners:
It is a tool used to scan computer files for viruses, worms and Trojan horses and cure the infected system. If any fault found it stops the file from running and stores the file in a special area called Quarantine(isolated area) and can be deleted later.

Cookies:
Cookies are small text files that are created when we visit a website that keep track of our details. This information will help the hacker to use it for malicious purposes. It acts as a spyware.

Guidelines for using computers over internet:

  • Emails may contain Viruses so do not open any unwanted emails
  • Download files from reputed sources(sites)
  • Avoid clicking on pop up Advt.
  • Most of the Viruses spread due to the use of USB drives so use cautiously.
  • Use firewall in your computer
  • Use anti virus and update regularly
  • Take backups in a regular time intervals

Mobile Computing:
The advancements in computing technology have led to the developments of more computing power in hand held devices like laptops, tablets, smart phones, etc. Nowadays people are able to connect to others through internet even when they are in move.

Mobile communication:
The term ‘mobile’ help the people to change their life styles and become the backbone of the society. Mobile communication networks do not require any physical connection.

Generations in mobile communication:
The mobile phone was introduced in the year 1946. Early stage it was expensive and limited services hence its growth was very slow. To solve this problem, cellular communication concept was developed in 1960’s at Bell Lab. 1990’s onwards cellular technology became a common standard in our country.
The various generations in mobile communication are
1.First Generation networks(1 G):
It was developed around 1980, based on analog system and only voice transmission was allowed.

2. Second Generation networks (2G):
This is the next generation network that was allowed voice and data transmission. Picture message and MMS(Multimedia Messaging Service) were introduced. GSM and CDMA standards were introduced by 2G.
(i) Global System for Mobile(GSM):
It is the most successful standard. It uses narrow band TDMA(Time Division Multiple Access), allows simultaneous calls on the same frequency range of 900 MHz to 1800 MHz. The network is identified using the SIM(Subscriber Identity Module).
(a) GPRS(General Packet Radio Services):lt is a packet oriented mobile data service on the 2G on GSM. GPRS was originally standardized by European Telecommunications Standards Institute (ETSI) GPRS usage is typically charged based on volume of data transferred. Usage above the bundle cap is either charged per megabyte or disallowed.

(b) EDGE(Enhanced Data rates for GSM Evolution):
It is three times fasterthan GPRS. It is used for voice communication as well as an internet connection.

(ii) Code Division Multiple Access (CDMA):
It is a channel access method used by various radio communication technologies. CDMA is an example of multiple access, which is where several transmitters can send information simultaneously over a single communication channel. This allows several users to share a band of frequencies To permit this to be achieved without undue interference between the users, and provide better security.

3. Third Generation networks(3G):
It allows high data transfer rate for mobile devices and offers high speed wireless broadband services combining voice and data. To enjoy this service 3G enabled mobile towers and hand sets required.

4. Fourth Generation networks(4G):
lt is also called Long Term Evolution(LTE) and also offers ultra broadband Internet facility such as high quality streaming video. It also offers good quality image and videos than TV.

Mobile communication services:
1. Short Message Service(SMS):
It allows transferring short text messages containing up to 160 characters between mobile phones. The sent message reaches a Short Message Service Center(SMSC), that allows ‘store and forward’ systems. It uses the protocol SS7(Signaling System No7). The first SMS message ‘Merry Christmas’ was sent on 03/12/1992 from a PC to a mobile phone on the Vodafone GSM network in UK.

2. Multimedia Messaging Service (MMS):
It allows sending Multi Media(text, picture, audio and video file) content using mobile phones. It is an extension of SMS.

3. Global Positioning System(GPS):
It is a space- based satellite navigation system that provides location and time information in all weather conditions, anywhere on or near the Earth where there is an unobstructed line of sight to four or more GPS satellites. The system provides critical capabilities to military, civil and commercial users around the world.

It is maintained by the United States government and is freely accessible to anyone with a GPS receiver. GPS was created and realized by the U.S. Department of Defense (DoD) and was originally run with 24 satellites. It is used for vehicle navigation, aircraft navigation, ship navigation, oil exploration, Fishing, etc. GPS receivers are now integrated with mobile phones.
Plus One Computer Science Notes Chapter 12 Internet and Mobile Computing 1

Smart Cards:
A smart card is a plastic card with a computer chip or memory that stores and transacts data. A smart card (may be like your ATM card) reader used to store and transmit data. The advantages are it is secure, intelligent and convenient. The smart card technology is used in SIM for GSM phones. A SIM card is used as identification proof.

Mobile operating system:
It is an OS used in hand held devices such as smart phone, tablet, etc. It manages the hardware, multimedia functions, Internet connectivity,etc. Popular OSs are Android from Google,iOS from Apple, BlackBerry OS from Black Berry and Windows Phone from Microsoft.

Android OS:
It is a Linux based OS forTouch screen devices such as smart phones and tablets.lt was developed by Android Inc. founded in Palo Alto, California in 2003 by Andy Rubin and his friends. In 2005, Google acquired this. A team led by Rubin developed a mobile device platform powered by the Linux Kernel.

The interface of Android OS is based on touch inputs like swiping, tapping, pinching in and out to manipulate on screen objects. In 2007 onwards this OS is used in many mobile phones and tablets. Android SDK(Software Development Kit) is available to create applications(apps) like Google Maps, FB, What’s App, etc.

It is of open source nature and many Apps are available for free download from the Android Play Store hence increase the popularity.
Different Android Versions are shown below
Plus One Computer Science Notes Chapter 12 Internet and Mobile Computing 1

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 11 Computer Networks

Kerala Plus One Computer Science Notes Chapter 11 Computer Networks

Summary
Computer network:
Two or more computers connected through a communication media that allows exchange of information between computers is called a Computer Network. Eg: Internet

Need for network:
The advantages of Networks are given below.
1. Resource sharing:
All the computers in a network can share software (programs, data ) and hardware (printer, scanner, CD drive, etc.).

2. Reliability:
If one computer fails, the other computer can perform the work without any delay. This is very important for banking, air traffic control and other application.

3. Price Vs Performance:
A main frame computer can be 10 times faster than a PC but it costs thousand times a PC. Therefore instead of a main frame 10 personal computers are used with less cost and same performance.

4. Communication Medium:
It is a powerful communication medium. We can exchange information between computers in a network.

5. Scalable:
This means, System performance can be increased by adding computers to a network.

Terminologies:

  1. Bandwidth: The maximum amount of data that can be transmitted by the medium measured in Hertz.
  2. Noise: It is the unwanted electrical or electromagnetic interferences that adversely affect the transmitted data signals.
  3. Node: A computer or an I/O device connected to a network is called Node.

Data communication system:
Communication is the exchange of information between two human beings. But data communication is the exchange of information between two computers(devices).

  1. Message: It is the data/information to be transmitted from one computer to another
  2. Sender: It is a computer or a device that sends data. It is also called.source or transmitter
  3. Receiver: It is a computer ora device that receives data
  4. Medium: It is the path through which message transmitted from the sender to the receiver. There are two types Guided and Un Guided media.
  5. Protocol: The rules and conventions for transmitting data.

Communication Medium:
There are two types guided and unguided.
Guided Media:
1. Twisted Pair cable:
2 types unshielded twisted pair and shielded twisted pair. Two copper wires individually insulated and twisted around each other and put in a plastic cover.

2. Coaxial cable:
A sturdy copperwire is insulated by plastic, it is covered just like a mesh by a conductor which is enclosed in an protective plastic coating. It is expenssive, less flexible and more difficult to install. But it is more reliable and carry for higher data rates.

3. Optical fibre:
These are made of glass fibres that are enclosed in a plastic jacket. It uses light instead of electrical signals. The light sources are LED or ILD.

Unguided Media:

  1. Radio waves: It transmits data at different frequencies ranging from 3 kHz. to 300 GHz.
  2. Microwaves: Microwave signals can travel in straight line if there is any obstacle in its path, it can’t bend. So it uses tall towers instead of short one.
  3. Infrared waves: These waves are used for transmitting data in short distance and its frequency range is 300 GHz to 400 GHz.

Wireless communication technologies using:
radio waves
1. Bluetooth:
This technology uses radio waves in the frequency range of 2.402 GHz to 2.480 GHz. And transmit data in short distance. Mobile phones, Laptops, tablets etc use Bluetooth technology to transmit data.

2. Wi Fi(Wireless Fidelity):
It uses radio waves to transmit information across a network in a range 2.4 GHz to 5 GHz in short distance. Nowadays this technology is used to access internet in Laptops, Desktops, tablets, Mobile phones etc.

3. Wi MAX(Wireless Microwave Access):
It uses micro waves to transmit information across a network in a range 2 GHz to 11 GHz over very long distance.

4. Satellites:
By using satellite we can communicate from eny part of the world to any other. The ground stations are connected via the satellite. The data signals transmitted from earth to satellite (uplink) and from the satellite to the earth (downlink).

Data communication devices:
It acts as an interface between computer and the communication channel

Network Interface Card (NIC):
This device enables a computer to connect to a network and transmit information.

Hub:
It is a small, simple and inexpensive device used to connect computers(devices) to a network. If a computer wants to transmit data to another computer. First it sends to the hub, the hub retransmits this data to all other computers.

Each and every computer gets the data and check whether it is for them or not. It increases the network traffic and hence the transmission speed is low.

Switch:
It is an expensive device used to connect computers(devices) to a network. Unlike hub, switch transmit data not to all computers, it retransmits data only to the intended computer. So the traffic is less and speed is high

Repeater:
It is a device used to strengthen weak signals on the network.

Bridge:
It is a device used to link same type of networks.

Router:
It is similar to a bridge, but it can connect two networks with different protocols.

Gateway:
It is used to connect two different networks with different protocols.

Data terminal equipments:
These devices are used to control data flow to and from a computer

Modem:
It is a device used to connect the computer to the internet. It converts digital signal into analog signal (modulation) and vice versa (Demodulation)

Multiplexer:
It combines the inputs from different channels of a medium and produces one output.

Network topologies:
Physical or logical arrangement of computers on a network is called structure or topology. It is the geometrical arrangement of computers in a network. The major topologies developed are star, bus, ring, tree and mesh.
1. Star Topology:
A star topology has a server all other computers are connected to it. If computer A wants to transmit a message to computer B. Then computer A first transmit the message to the server then the server retransmits the message to the computer B.

That means all the messages are transmitted through the server. Advantages are added or remove workstations to a star network is easy and the failure of a workstation will not effect the other. The disadvantage is that if the server fails the entire network will fail.

2. Bus Topology:
Here all the computers are attached to a single cable called bus. Here one computer transmits all other computers listen. Therefore it is called broadcast bus. The transmission from any station will travel in both the direction.

The connected computers can hear the message and check whether it is for them or not. Advantages are add or remove computer is very easy. It requires less cable length and the installation cost is less. Disadvantage is fault detection is very difficult because of no central computer.

3. Ring Topology:
Here all the computers are connected in the shape of a ring and it is a closed loop. Here also there is no central computer. Here a computer transmits a message, which is tagged along with its destination computer’s address.

The message travels in one direction and each node check whether the message is for them. If not, it passes to the next node. It requires only short cable length. If a single node fails, at least a portion of the network will fail. To add a node is very difficult.

4. Hybrid Topology:
It is a combination of any two or more network topologies. Tree topology and mesh topology can be considered as hybrid topology.
(a) Tree Topology:
The structure of a tree topology is the shape of an inverted tree with a central node and branches as nodes. It is a variation of bus topology. The data transmission takes place in the way as in bus topology. The disadvantage is that if one node fails, the entire portion will fail.

(b) Mesh Topology:
In this topology each node is connected to more than one node. It is just like a mesh (net). There are multiple paths between computers. If one path fails, we can transmit data through another path.

Types of networks:
The networks are classified into the following based upon the amount of geographical area that covers.
(i) Personal Area Network(PAN):
It is used to connect devices situated in a small radius by using guided media or unguided media

(ii) Local Area Network (LAN):
This is used to connect computers in a single room, rooms within a building or buildings of one location by using twisted pair wire or coaxial cable. Here the computers can share Hardware and software. Data transferrate is high and error rate is less, eg: The computers connected in a school lab.

(iii) Metropolitan Area Network (MAN):
A Metropolitan Area Network is a network spread over a city. For example a Cable TV network. MAN have lesser speed than LAN and the error rate is less. Here optical fiber cable is used.

(iv) Wide Area Network (WAN):
This is used to connect computers over a large geographical area. It is a network of networks. Here the computers are connected using telephone lines or Micro Wave station or Satellites. Internet is an example for this.

LAN and MAN are owned by a single organization but WAN is owned by multiple organization. The error rate in data transmission is high.

Logical classification of networks:
Peer to peer:
In this configuration all the computers have equal priority. That means each computer can function as both a client and a server. There is no dedicated server.

Client-Server:
In this configuration a computer is powerful which acts as a dedicated server and all others are clients (work stations). A Server fulfils the needs of the clients.

  1. File Server: A computer that stores and manages files for other devices on a network
  2. Web Server: A computer that handles the requests for web pages.
  3. Print Server: A computer that handles the print jobs from other computers on a network.
  4. Database Server: A computer that manages the database.

Network protocols:
A protocol is a collection of rules and regulations to transfer data from one location to another. Transmission Control Protocol (TCP), which uses a set of rules to exchange messages with other Internet points at the information packet level. Internet Protocol (IP), which uses a set of rules to send and receive messages at the Internet address level
1. FTP:
File Transfer Protocol which is used for transferring files between computers connected to local network or internet.

2. HTTP:
is a protocol used for WWW for enabling the web browse to access web server and request HTML documents.

3. DNS (Domain Name System):
When we type web sites address in the address bar, the browser determines the URL and asks the DNS for URLS corresponding IP address (Numeric address). The DNS returns the address to the browser.

Identification of computers over a network:
A computer gets a data packet on a network, it can identify the sender’s address easily. It is similar to our snails mail, each letter is stamped in sender’s post office as well as receiver’s post office.

Media Access Control(MAC) address:
It is a unique 12 digit hexadecimal number(IMEI for mobile phones, it is a 15 digit decimal number) assigned to each NIC by its manufacturer. This address is known as MAC address and its permanent. It is of the form. MM:MM:MM:SS:SS:SS.

The first MM:MM:MM contains the ID number of the adapter company and the second SS:SS:SS represents the serial number assigned to the adapter by the company.

Internet Protocol (IP) address:
An IP address has 4 parts numeric address. Each parts contains 8 bits. By using 8 bits we can represent a decimal number between 0 to 255(28 = 256 numbers). Each part is separated by dot. A total of 4 × 8 = 32 bits used. But nowadays 128 bits are used for IP address.

Uniform Resource Locator(URL):
Every resource on the internet has a unique URL. Mainly it has three parts
eg: http://www.hscap.kerala.gov.in /index.html.

  • http: http means hypertext transfer protocol. It is a protocol used to transfer hypertext.
  • www: World Wide Web. With an email address we can open our mail box from anywhere in the world.
  • hscap.kerala: It is a unique name. It is the official website name of Single Window System
  • gov: It is the top level domain. It means that it is a government organization’s website.
  • in: It is the geographical top level domain. It represents the country, in is used for India.
  • index.html: It represents the file name.

Top Level Domain Names:

  • .com The site register for commercial purpose
  • .edu The site register for educational purpose
  • .gov The site register by Government agencies
  • .mil The site register for military services
  • .net The site register for network purpose
  • .org The site register by organizations

Country-Specific Domain Names:

  • .in India
  • .au Australia
  • .ca Canada
  • .ch China
  • .jp Japan
  • .us United States of America

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 10 Functions

Kerala Plus One Computer Science Notes Chapter 10 Functions

Concept of modular programming:
The process of converting big and complex programs into smaller programs is known as modularisation. This small programs are called modules or sub programs or functions. C++ supports modularity in programming called functions
Merits of modular programming:

  • It reduces the size of the program
  • Less chance of error occurrence
  • Reduces programming complexity
  • Improves reusability

Demerits of modular programming:
While dividing the program into smaller ones extra care should be taken otherwise the ultimate result will not be right.

Functions in C++:
Some functions that are already available in C++ are called pre-defined or built in functions. In C++, we can create our own functions for a specific job or task, such functions are called user defined functions. A C++ program must contain a main() function. A C++ program may contain many lines of statements(including so many functions) but the execution of the program starts and ends with main() function.

Pre-defined functions:
To invoke a function that requires some data for performing the task, such data is called parameter or argument. Some functions return some value back to the called function.

String functions:
To manipulate string in C++ a header file called string.h must be included.
1. strlen():
to find the number of characters in a string(i.e. string length).
Syntax: strlen(string);
eg:
cout<<strien(“Computer”); It prints 8.

2. strcpy():
It is used to copy second string into first string.
Syntax: strcpy(string1, string2);
eg:
strcpy(str,”BVM HSS”);
cout<<str; It prints BVM HSS.

3. strcat():
It is used to concatenate second string into first one.
Syntax: strcat(string1,string2)
eg:
strcpy(str1,’’Hello”);
strcpy(str2,” World”);
strcat(str1 ,str2);
cout<<str1; It displays the concatenated string “Hello World”

4. strcmp():
It is used to compare two strings and returns an integer.
Syntax: strcmp(string1,string2)

  • if it is 0 both strings are equal.
  • if it isgreaterthan 0(i.e. +ve) stringl is greater than string2
  • if it is less than 0(i.e. -ve) string2 is greater than stringl

eg:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str1 [10],str2[10];
strcpy(str1,”Kiran”);
strcpy(str2,”Jobi”);
cout<<strcmp(str1 ,str2);
}
It returns a +ve integer.

5. strcmpi():
It is same as strcmpO but it is not case sensitive. That means uppercase and lowercase are treated as same.
eg: “ANDREA” and “Andrea” and “andrea” these are same.
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str1 [10],str2[10];
strcpy(str1,”Kiran”);
strcpy(str2,”KIRAN”);
cout<<strcmpi(str1 ,str2);
}
It returns 0. That is both are same.

Mathematical functions:
To use mathematical functions a header file called math.h must be included.
1. abs():
To find the absolute value of an integer.
eg: cout<<abs(-25); prints 25.
Cout<<abs(+25); prints 25.

2. sqrt():
To find the square root of a number.
eg: cout<<sqrt(49); prints 7.

3. pow():
To find the power of a number.
Syntax. pow(number1, number2)
eg: cout<<pow(2,10); It is equivalent to 210. It prints 1024.

4. sin():
To find the sine value of an angle and the angle must be in radian. To convert an angle into radian multiply by 3.14(“) and divide by 180.
float x = 60 × 3.14/180;
cout<<sin(x); prints 0.86576.

5. cos():
To find the cosine value of an angle and the angle must be in radian. To convert an angle into radian multiply by 3.14(“) and divide by 180.
float x = 60 × 3.14/180;
cout<<cos(x); prints 0.50046.

Character functions:
To manipulate character in C++ a header file called ctype.h must be included.
1. isupper():
To check whether a character is in uppercase or not. If the character is in uppercase it returns a value 1 otherwise it returns 0.
Syntax: isupper(charch);

2. islower():
To check whether a character is in lowercase or not. If the character is in lowercase it returns a value 1 otherwise it returns 0.
Syntax: islower(char ch);

3. isalpha():
To check whether a character is an alphabet or not. If the character is an alphabet it returns a value 1 otherwise it returns 0.
Syntax: isalpha(char ch);

4. isdigit():
To check whether a character is a digit or not. If the character is a digit it returns a value 1 otherwise it returns 0.
Syntax: isdigit(charch);

5. isalnum():
To check whether a character is an alphanumeric or not. If the character is an alphanumeric it returns a value 1 otherwise it returns 0.
Syntax: isalnum(char ch);

6. toupper():
It is used to convert the given character into uppercase.
Syntax: toupper(char ch);

7. tolower():
It is used to convert the given character into lowercase.
Syntax: tolower(char ch);

Conversion functions:
Some occasions we have to convert a data type into another for this conversion functions used. The header file stdlib.h must be included.
1. itoa():
It is used to convert an integer value to string type.
Syntax: itoa(int v, char str, int size); This function has 3 arguments, first one is the integer to be converted, second is the string variable to store and third is the size of the string.
eg: itoa(“123”,str,4);
cout<<str;

2. atoi():
It Is the opposite of itoa( ). That is it converts a string into integer.
Syntax: atoi(str);

I/O Manipulating function:
It is used to manipulate I /O operations in C++. The header file iomanip.h must be included,
(a) setw(): It is used to set the width for the subsequent string.
Syntax: setw(size);

User defined functions:
Syntax: Return type Function_name(parameterlist)
{
Body of the function
}

  • Return type: It is the data type of the value returned by the function to the called function;
  • Function name: A name given by the user.

Different types of User defined functions.

  • A function with arguments and return type.
  • A function with arguments and no return type.
  • A function with no arguments and with return type.
  • A function with no arguments and no return type.

Prototype of functions:
Consider the following codes
Method 1:
#include<iostream>
using namespace std;
int sum(int n1,int n2)
{
return(n1 + n2);
}
int main()
{
int n1 ,n2;
cout<<“Enter 2 numbers:”;
cin>>n1>>n2;
cout<<“The sum is “<<sum(n1,n2);
}

Method 2:
#include<iostream>
using namespace std;
int main()
{
int n1 ,n2;
cout<<“Enter 2 numbers:”;
cin>>n1>>n2;
cout<<“The sum is “<<sum(n1,n2);
}
int sum(int n1 ,int n2)
{
return(n1 + n2); ‘
}
In method 1 the function is defined before the main function. So there is no error. In method 2 the function is defined after the main function and there is an error called “function sum should have a prototype”.

This is because of the function is defined after the main function. To resolve this a prototype should be declared inside the main function as follows.

Method 3:
#include<iostream>
using namespace std;
int main()
{
int n1,n2;
int sum(int.int);
cout<<“Enter 2 numbers:”;
cin>>n1>>n2;
cout<<“The sum is “<<sum(n1,n2);
}
int sum(int n1,int n2)
{
retum(n1 + n2);
}

Functions with default arguments:
We can give default values as arguments while declaring a function. While calling a function the user doesn’t give a value as arguments the default value will be taken. That is we can call a function with or without giving values to the default arguments.

Methods of calling functions:
Two types call by value and call by reference.
1. Call by value:
In call by value method the copy of the original value is passed to the function, if the function makes any change will not affect the original value.

2. Call by reference:
In call by reference method the address of the original value is passed to the function, if the function makes any change will affect the original value.

Scope and life of variables and functions:
1. Local scope:
A variable declared inside a block can be used only in the block. It cannot be used any other block.
eg:
#include<iostream>
using namespace std;
int sum(int n1,int n2)
{
int s;
s = n1 + n2;
return(s);
}
int main()
{
int n1,n2;
cout<<“Enter 2 numbers:”;
cin>>n1>>n2;
cout<<“The sum is “<<sum(n1,n2);
}
Here the variable s is declared inside the function sum and has local scope;

2. Global scope:
A variable declared outside of all blocks can be used any where in the program.
#include<iostream>
using namespace std;
int s;
int sum(int n1,int n2)
{
s = n1 + n2;
return (s);
}
int main()
{
int n1 ,n2;
cout<<“Enter 2 numbers :”;
cin>>n1>>n2;
cout<<“The sum is “<<sum(n1 ,n2);
}
Here the variable s is declared out side of all functions and we can use variable s any where in the program

Recursive functions:
A function calls itself is called recursive function.

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 9 String Handling and I/O Functions

Kerala Plus One Computer Science Notes Chapter 9 String Handling and I/O Functions

Summary
String handling using arrays:
A string is a combination of characters hence char data type is used to store string. A string should be enclosed in double quotes. In C++ a variable is to be declared before it is used.Eg. “BVM HSS KALPARAMBU”.

Memory allocation for strings:
To store “BVM” an array of char type is used. We have to specify the size. Remember each and every string is end with a null (\0) character. So we can store only size- 1 characters in a variable. Please note that \0 is treated as a single character. \0 is also called as the delimiter.
char school_name[4]; By this we can store a maximum of three characters.
Plus One Computer Science Notes Chapter 9 String Handling and IO Functions 1
Consider the following declarations

  • char my_name[10] = ”Andrea”;
  • char my_name2[ ] = ”Andrea”;
  • char str[ ] = ”Hello World”

In the first declaration 10 Bytes will be allocated but it will use only 6 + 1 (one for ‘\0’) = 7 Bytes the remaining 3 Bytes will be unused. But in the second declaration the size of the array is not mentioned so only 7 Bytes will be allocated and used hence no wastage of memory.

Similarly in the third declaration the size of the array is also not mentioned so only 12( one Byte for space and one Byte for ‘\0’) Bytes will be allocated and used hence no wastage of memory

Input/output operations on strings:
Consider the following code
#include<iostream>
using namespace std;
int main()
{
char name[20];
cout<<“Enter your name:”;
cin>>name;
cout<<“Hello “<<name;
}
If you run the program you will get the prompt as follows
Enter your name: Alvis Emerin
The output will be displayed as follows and the “Emerin” will be truncated.
Hello Alvis
This is because of cin statement that will take upto the space. Here space is the delimiter. To resolve this gets() function can be used. To use gets() and puts() function the header file stdio.h must be included. gets() function is used to get a string from the keyboard including spaces.

puts() function is used to print a string on the screen. Consider the following code snippet that will take the input including the space.
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char name[20];
cout<<“Enter your name:”;
gets(name);
cout<<“Hello “<<name;
}

More console functions:
Plus One Computer Science Notes Chapter 9 String Handling and IO Functions 2

Stream functions for I / O operations:
Some functions that are available in the header file iostream.h to perforrn I/O operations on character and strings(stream of characters). It transfers streams of bytes between memory and objects. Keyboard and monitor are considered as the objects in C++.

Input functions:
The input functions like get( )(to read a character from the keyboard) and getline() (to read a line of characters from the keyboard) is used with cin and dot(.) operator.
Plus One Computer Science Notes Chapter 9 String Handling and IO Functions 3
eg:
#include<iostream>
using namespace std;
int main()
{
char str[80],ch=’z’;
cout<<“enter a string that end with z:”;
cin.getline(str,80,ch);
cout<<str;
}
If you run the program you will get the prompt as follows
Enter a string that end with z: Hi I am Jobi. I am a teacher. My school is BVM HSS The output will be displayed as follows and the string after ‘z’ will be truncated.
Hi, I am Jobi. I am a teacher

Output function:
The outputt functions like put() (to print a character on the screen) and write() (to print a line of characters on the screen) is used with cout and dot(.) operator.
Plus One Computer Science Notes Chapter 9 String Handling and IO Functions 4

Plus One Computer Science Notes