12 Computer Science EM
12 Computer Science EM
in
Government of Tamilnadu
in
2021-2022
s.
es
pr
12
ex
vi
al
.k
COMPUTER SCIENCE
w
w
w
in
s s.
p re
ex
vi
al
.k
w
w
w
II
CONTENTS
SL.NO. TITLE Page No.
1 Fundamentals of Computers 1
2 Computer Organization 3
3 Windows Operating System 5
4 Windows Operating System 7
5 Flowchart 9
6 Pseudo-Code 11
7 Introduction to C++ 13
in
8 Operators 15
9 Sample C++ Program and Execution 18
s.
10 Data Types,Variables 20
s
11 Selection Statements-if,if..else 23
12
13
Selection Statements-nested if..else
Iteration Statements -for loop
p re 26
30
ex
14 while and do-while Loops 33
15 Jump Statements 35
vi
16 Functions 38
17 C++ header files and Built-in functions 40
al
20 Recursive function 48
21 Scope Rules of variables 50
w
22 Single-Dimensional Array 53
w
III
in
s s.
p re
ex
vi
al
.k
w
w
w
IV
Fundamentals of
1 Computers
Learning Outcome
After learning the concepts in this topic , the students will be able
To know about computers.
To know the components and their functions.
To know about various generations of computer.
in
Teacher Activity 1
s.
Introduction
s
A Computer is an electronic device that manipulates information or data. It has the ability to store,
retrieve and process data.
Uses of computer
p re
Computers are used in the field of education, research, travel and tourism, weather forecasting,
social networking, e-commerce etc.
ex
Generations of Computers
vi
Period and
S.no Generations Merit/Demerit
component used
al
1
GENERATION tube Ex: ENIAC,EDVAC
w
GENERATION
IBM 1620
w
Teacher Activity 2
Components of Computer
Input unit
It is used to feed any form of data to the computer. Ex : Keyboard, Mouse etc.
in
It controls the flow of data between the CPU, memory and I/O devices.
MU (Memory Unit )
s.
It has two types. They are primary memory and secondary memory.
s
Primary Memory: It is used to store the programs and data temporarily. Eg: RAM
Output Unit
p re
Secondary Memory: Used to store the data permanently. Eg: CD-ROM
Student Activity
vi
al
1. The teacher asks the students to categorize the input and output devices in their note book.
.k
Evaluation
w
w
1. What is computer ?
w
Computer
2 Organization
Learning Outcome
After learning the concepts in this topic , the students will be able
To know the processors and their characteristics.
To know the importance of memory devices and their roles in a computer.
in
To know the secondary storage devices and their usage.
s.
Teacher Activity 1
s
Basics of Microprocessors
p re
¾¾ Microprocessor is a programmable multipurpose silicon chip.
¾¾ It processes data as per instructions stored in memory.
¾¾ Performance of microprocessor depends on the characteristics
ex
i) CLOCK SPEED: Internal clock that regulates the speed at which it executes instructions.
INSTRUCTION SET: Basic set of machine level instructions that a microprocessor is
ii)
vi
iii) WORD SIZE: It determines the amount of RAM that can be accessed by a microprocessor.
Memory Devices
.k
¾¾ RAM is a volatile memory. It means that the information stored in it is not permanent.
¾¾ It allows both read and write operations.
w
Teacher Activity 2
Secondary Storage Devices
¾¾ To store data and programs permanently .
Hard Disk :
It is a magnetic disk on which you can store data.
It has the stacked arrangement of disks accessed by a pair of heads for each of the disks.
in
Flash Memory:
It offers fast access time.
s.
The time taken to read or write a character in memory is called access time.
s
Capacity of flash memory varies from 1 GB to 2 TB.
Blue-ray Disc:
It is a high density optical disc used for PlayStation games and playing High definition movies.
vi
Student Activity
w
1. The students are divided into groups and are asked to identify the storage capacity of CD, DVD,
Flash Memory and Blue-Ray Disc.
w
w
Evaluation
Windows Operating
3 System
Learning Outcome
After learning the concepts in this topic , the students will be able
To know the concepts of operating system and its types.
To know the elements of the windows Desktop.
in
Teacher Activity 1
s.
Introduction of Operating System:
¾¾ It is a System software.
s
¾¾ It enables the hardware to communicate and operate with other software.
the computer.
p re
¾¾ I t acts as an interface between the user and the hardware and controls the overall execution of
ex
vi
al
.k
w
w
w
Teacher Activity 2
Windows Desktop:
The opening screen of windows is called “Desktop”.
in
s s.
p re
ex
Elements of Desktop:
Start button, Icons, Taskbar, Notification area and Date and Time.
vi
Icons:
al
Student Activity
w
w
1. The teacher asks the students to pair up with a partner and to list out the elements of windows
desktop.
w
Evaluation
4 Windows Operating
System
Learning Outcome
After learning the concepts in this topic , the students will be able
To understand the different Elements of a window
To manage the files and folders
in
Teacher Activity 1
Introduction
s.
The teacher brings a laptop to the class and opens the window screen and asks the students what
s
they are seeing. The teacher introduces the topic and explains it
Explain the Elements Of the Window.
1. Title bar:
p re
The title bar displays the name of the application. It also contain minimize, maximize and close
ex
button.
2. Menu bar:
vi
The menu bar contain the different types of menus like file, edit ,help etc.
3. The workspace:
al
The workspace is the area in the document window to enter or type the text of your document.
.k
4. Scroll bar:
The scroll bars are used to scroll the workspace horizontally or vertically.
w
e corners and borders of the window helps to drag and resize the windows. The mouse pointer
Th
changes to a double headed arrow when positioned over a border or a corner.
w
Teacher Activity 2
Files and folders
The teacher asks the students how they will save or store data or information in the windows. The
teacher explains the importance of files and folders through demonstration method.
1. Files:
The data or information are stored in windows as files. Each file has its own name. The extension
name followed by the name of the file indicates the application in which it is created.
Creating files
Wordpad is an inbuilt word processor in windows to create and manipulate text documents.
Method-1.
Step 1: open computer icon and open a drive in which you want to create a new folder.
Step 2: Click on File New Folder
Step 3: A new folder is created with the default name “New folder”
Step 4: Type the Folder Name and Press Enter Key
in
Method -2.
s.
Step 1: In the desktop, right Click New Folder
Step 2: A folder appears with the default name “New folder”
s
Step 3: Type the Folder Name and Press Enter Key
Step 1: Click the start button, the search box appears at the bottom of the start menu
al
Step 2: Type the name of the file or the folder you want to search
Step 3 The files or folders with the specified names will appear, if you click that file it will directly
.k
Student Activity
w
1. The teacher divides the students into groups and asks each group to present various elements of
w
Evaluation
5 FLOW CHART
Learning Outcome
After learning the concepts in this topic , the students will be able
To Understand the purpose of using flow charts
To Know the Flow chart symbols
To Know the Advantages and disadvantages of using flow charts
in
Teacher Activity 1
s.
Introduction
s
Before starting the topic the teacher asks the students about the traffic sign. what do
re
you understand on seeing the traffic signs?. Most of the traffic signs are represented in
the form of pictures. So the purpose of representing traffic signs in the diagrammatic
way is to understand the meaning for everyone despite of languages. Teacher draws
p
an image on the board and asks the students to identify the name of the symbol.
ex
The student answers it is a school nearby.
vi
Teacher Activity 2
al
The teacher gives explanation of flowchart by drawing its symbols on the board
¾¾ A flow chart is a diagrammatic representation of an algorithm
.k
language
w
¾¾ Since flow chart uses symbols to represent every step in algorithm, it is easy to understand by
everyone
w
Symbol meaning
Start/end
Process
Input / output
Decision making
Arrows to connect
Teacher Activity 3
Draw a flow chart to add two numbers
START
Input A,B
C= A+ B
Print C
in
END
s s.
Advantages of flow chart
¾¾ It is easy to understand
p re
¾¾ The flow charts are the better way of communicating the logic of a problem
ex
¾¾ It is very efficient and helps in debugging
Student Activity
w
The students individually prepare a flowchart to find out the multiplication of any two numbers.
w
Evaluation
w
a.
b.
c.
6 PSEUDO-CODE
Learning Outcome
After learning the concepts in this topic , the students will be able
¾¾ To know the way of writing a pseudo code
¾¾ To solve a problem using Pseudo Code
in
Teacher Activity 1
s.
Before entering into the topic, the teacher asks the students a common example. “How do you
prepare coffee?”. Each student says one step and teacher writes steps one by one on the board.
s
1. First take a bowl
2. Pour milk into the bowl
3. Switch on the gas stove and place it on the stove.
4. Let the milk boil
p re
ex
5. After that pour milk in a glass and add sugar and coffee powder.
So the teacher concludes that just to prepare a coffee we need atleast five steps. Similarly to solve a
problem in a computer we have to frame few steps.
vi
n algorithm is a step by step sequence of statements intended to solve a problem. The planning
¾¾ A
to solve a problem is written in our own language.
al
¾¾ A
fter planning a solution, we decide a programming language to be used and we use some of
.k
the keywords in that language along with the algorithm. Now it is called as a pseudo language.
A pseudo code is a step by step written outline of our code.
w
Teacher Activity 2
w
1. Teacher gives an example to write a pseudo code to find whether the given number is greater
w
Teacher Activity 3
Write a pseudo code and draw a flow chart to find smallest of two numbers
Pseudo code
START
READ A, B
IF A < B
PRINT “A is smaller”
ELSE
PRINT “B is smaller”
END
in
Flow chart
s.
start
s
input A, B
p re
ex
Yes No
IF a < b
vi
A is small B is small
al
.k
END
w
Student Activity
w
w
1 The students individually prepare a pseudo code find out the division of any two numbers.
Evaluation
7 Introduction to C++
Learning Outcome
After completion of this topic, the student will be able to
Know the History of C++
Understand the Basic Building blocks of C++
in
Know the Benefits of C++
Teacher Activity 1
s s.
History of C++ :
¾¾ It is a programming language which supports both procedural and Object Oriented
al
Benefits of C++ :
.k
¾¾ It is often the language of choice for multi-device, multi-platform and app development.
w
Teacher Activity 2
C++ Keywords :
asm double new switch
auto else operator template
break enum private this
case extern protected throw
catch float public try
char for register typedef
class friend return union
const goto short unsigned
continue if signed virtual
in
default inline sizeof void
delete int static volatile
s.
do long struct while
s
ÂÂ I dentifiers User-defined names given to different parts of the program.
Eg- Num, _ add, total_sales
re
ÂÂ Literals(Constants) – Data items whose value do not change during the execution of the
p
program. The Kinds of literals are Integer, Float, Real, Boolean, Character and String.
ex
ÂÂ Operators - The Symbols which are used to do some mathematical or logical operations.
ÂÂ Punctuators - The symbols which are used as delimiters while constructing a C++ Program.
vi
al
Student Activity
.k
1. The students are asked to work in groups to trace out whether the given identifiers are valid or
invalid and to share their reasons to the class.
w
i) Num
w
ii) NUM
iii) this
w
iv) 2myfile
v) total-sales
Evaluation
8 OPERATORS
Learning Outcome
After completion of this topic, the students will be able to
Know about Operators and different types of Operators.
Understand mathematical or logical operators.
in
Teacher Activity 1
s.
Operators :
ÂÂ Operators – Symbols used to do some mathematical or logical operations.
s
ÂÂ Operands – Operators which acts upon the data item or values.
Arithmetic Operators :
p re
¾¾ Performs simple arithmetic operations like addition, subtraction, multiplication, division etc.
ex
- Subtraction 5-5=0
al
* Multiplication 5*5=25
.k
/ Division 10/5=2
w
% Modulus 10%3=1
w
Relational Operators :
w
Logical operators :
¾¾ Used to evaluate logical and relational expressions.
in
NOT works on a single expression / operand. It simply negates or
s.
! NOT inverts the truth value. i.e., if an operand / expression is 1 (true) then
this operator returns 0 (false) and vice versa
s
Assignment Operator :
re
¾¾ Used to assign a value to a variable which is on the left hand side of an assignment statement
p
ex
= Assignment a = 10
al
Conditional Operator :
¾¾ Th
is operator is used as an alternate to if ….else control statement. It is also known as Ternary
Operator.
¾¾ ?: is a Conditional operator.
Teacher Activity 2
Other Operators :
¾¾ (,) Comma operator – Used to string together several expression.
¾¾ * Pointer to a variable
Input/Output Operator :
in
¾¾ >> - Input Operator Eg: cin>>num;
s s.
Student Activity
Mind Map.
p re
1. The teacher uses some arithmetic operators and asks the students to state their various uses through
ex
2. The students prepare a flowchart for the ternary operator and explain that to the class.
vi
al
Evaluation
.k
1. Write an expression involving a logical operator to test, if marks are 90 and grade is ‘A’.
w
2. Give that i=8, j=10, k=8 What will be the result of the following expression?
w
in
Teacher Activity 1
s.
Introduction:
Lets start with a very simple program which makes students easily understand about C++ coding,
s
and then we shall look at the basic Elements one by one that every C++ program has.
Create a new source code :
{
cout<<”Welcome to School”;
al
return 0;
}
.k
¾¾ Here //C++program to print a string line is a comment line. Any line beginning with // is a
w
comment line.
¾¾ #include<iostream> tells the compiler’s pre-processor to include the header file in the program.
w
Teacher Activity 2
Ask students to create a simple program using the above steps and their first C++ program is below
with an output “Hello World !”.
// My first C++ Program
#include<iostream>
using namespace std ; Output:
int main() Hello World !
{
cout<<”Hello World !”;
return 0;
}
After the execution of programs students understand about the types of errors that occurs during
compilation.
in
ÂÂ Syntax Error – Set of Grammatical rules to construct a Program.
ÂÂ Semantic Error – Wrong use of variables, operators, order of execution etc.
s.
ÂÂ Run-Time Error – Some illegal operations that takes place.
s
For Example
Student Activity
.k
w
1. The teacher facilitates the students during the execution of the task and also guides them to cor-
rect the errors that occur during execution.
w
w
Evaluation
1. Write a C++ program that prints a string “Stay Home Stay Safe!”
2. Write a C++ program to find the total marks of three subjects.
3. Point out the type of error.
# include<iostream>
using namespace std;
int main()
{
int l=10; b=12;
cout<<”Area of rectangle”<< l*b;
}
DATA TYPES,
10 VARIABLES
Learning Outcome
in
Understand the need for variable declaration
Teacher Activity 1
s s.
Data Types and variables
p re
Every programming language has two fundamental elements data types and variables. They are
very essential elements to write programs. C++ provides a predefined set of data types for handling the
data items. Such data types are known as fundamental or built-in data types. Apart from the built-in
data types, a programmer can also create their own data types called as User-defined data types.
ex
Example:
Name = Ram
vi
Age = 15
al
Average_mark = 85.6
Here Name, Age and Average mark are called fields, Ram, 15 and 85.6 are values. Fields are referred
.k
Teacher Activity 2
int data type accepts only integer number. It may or may not be signed. it uses the keyword ‘int’.
int num = 12;
cout<<num; Output : 12
char data type accepts only characters. It store either a character or an integer value. It uses the
keyword ‘char’
char ch =‘A’;
cout<<ch: Output : A
int n;
char ch =‘d’;
n=ch;
cout <<n; Output : 100
in
float data type accepts only floating point values. . It uses the keyword ‘float’
float a,b;
s.
a=12.5;
s
b=5;
cout << a+b; Output : 17.5
re
double data type also accepts double precision floating point numbers. It is also used for handling
p
floating point numbers. It uses the keyword ‘double’
ex
void data type is a special data type, it stores nothing. It does not return any value.
Memory Representation:
vi
Important reason for declaring a variable as a particular data type is to allocate appropriate space
in memory. Depending on the compiler (Turbo C++, dev C++) the memory size differs.
al
char - 1 byte
.k
int - 4 bytes
w
float - 4 bytes
double - 8 bytes
w
Programmers can define their own data types called user defined data types.
Example: structure, union, class, enumeration
Declaration of variables:
Every variable should be declared before they are used in a program. Declaration is a process to
instruct the compiler to allocate memory as per the data type specified along with the variable name.
Syntax :
<datatype><var 1>,<var 2>,<var 3>....<var n>;
Example
int a,b;
Here the compiler allocates 4 bytes of memory for each variable.
Student Activity
1. The students pair up and identify the variables used in the given program. Each group share their
data type to the class.
#include<iostream>
using namespace std;
in
int main()
s.
{
float a,c;
s
int b;
cout<<”Enter values”;
cin>>a>>b;
p re
c=a+b;
ex
Output :
al
2. The teacher divides the class into two groups as A & B and group A writes a C++ program to find
the area of a circle using radius as integer data type and the other group ‘B’ in the radius as float
w
data type.
w
Evaluation
11 Selection Statements -
if,if..else
Learning Outcome
in
To understand ‘if ’ statement
s.
To know ‘if-else’ statement.
s
Teacher Activity 1
Introduction:
p re
Generally, a program executes its statements sequentially from beginning to end. However, in
ex
some situations, the flow of control jumps from one part of the code to another segment of code. Such
jumps are called “control flow”. Here we are going to study about the basic control structure “Selection”.
vi
Statements:
A computer program is a set of statements or instructions to perform a specific task.
al
Control statements:
.k
Control statements are statements that alter the sequence of flow of instructions.
w
Teacher Activity 2
w
w
‘if ‘statement:
The ‘if ’ statement evaluates a condition, if the condition is true then a true-block is executed, oth-
erwise the true-block is skipped.
Here if the expression is true then the true block is executed and followed by statement-x are also
executed, otherwise the control passes to statement-x.
Program:
C++ program to check whether a person is eligible to vote using if statement.
#include <iostream>
using namespace std;
int main ()
{ Output:
int age; Enter your age: 23
You are eligible for voting
cout<<’’\n Enter your age:’’; This statement is always executed.
in
cin>>age;
s.
if (age>=18)
s
cout<<”\n You are eligible for voting”;
return 0;
}
cout<<’’This statement is always executed.”;
p re
ex
Teacher Activity 3
vi
if (expression)
w
{
w
True –block;
w
}
else
{
False-block;
}
Statement x;
In ’if – else’ statement, if the result is true then the statements inside true-block is executed and
false block is skipped. If the result is false, then the statement inside false-block is executed and the
true block is skipped.
Program:
Write a C++ program to find whether the given number is odd or even
# include <iostream>
using namespace std;
int main ()
{
int num,rem;
cout<<’’\n Enter number:’’;
cin>>num;
rem=num%2;
in
if (rem==0)
s.
cout<<’’\n The given number”<<num<<”is even”;
s
else
return 0; re
cout<<”\n The given number “<<num<<”is odd”;
p
}
ex
Output:
vi
Enter number: 10
The given number 10 is even
al
.k
Student Activity
w
w
1 The teacher splits the class into groups and ask to write a program to get computer science mark of
a student and check whether the student is pass or fail. (mark>=35 pass, otherwise fail).
w
Evaluation
1. Write a C++ program to find whether the given person is a Senior Citizen or not.
2. Write a C++ program to check whether the given number is divisible by 10 or not.
12 Selecton Statements -
Nested if. Else
Learning Outcome
in
Teacher Activity 1
s.
Introduction
s
The teacher motivates the students to ask previous topic questions.
Nested if:
p re
An ‘if ’ statement which contains another if statement is called nested if. There are three types.
ex
1. If nested inside if part
2. If nested inside else part
vi
Teacher Activity 2
al
.k
The teacher explains the different syntax and examples of nested if statement.
The syntax of the nested if:
w
if (expression-1) if (expression-1)
{ {
w
in
}
else
s.
{
if (expression-2)
s
{
True_Part_Statements;
}
p re
else
ex
{
False_Part_Statements;
vi
}
al
Program:
.k
Sales Commission
w
>5000 10%
Otherwise 5%
w
#include <iostream>
using namespace std;
int main()
{
int sales, commission;
cout<< “\n Enter Sales amount:”;
cin>> sales;
if (sales>5000)
{
commission= sales * 0.10;
}
else
{
Output:
commission= sales * 0.05;
Enter Sales amount: 6000
}
Commission: 600
cout<<”\n Commission:”<<commission;
return 0;
}
in
Teacher Activity 3
s.
The teacher explains the different syntax and examples of if-else-if ladder statement.
s
if-else-if ladder
re
The if-else-if ladder is a multi-path decision making statement. In this type of statement ‘if ’ is
followed by one or more ‘else if ’ statements and finally end with an else statement.
p
The syntax of if-else ladder:
ex
if (expression 1)
vi
{
Statement-1
al
}
else
.k
if (expression 2)
When the respective expression
w
Program:
C++ program to find your grade using if-else ladder
#include <iostream>
using namespace std;
int main()
{
int mark;
cout<< “\n Enter your Mark:”; Output:
cin>> mark; Enter your Mark: 60
if (mark >= 60) Your grade is 1st class !!
cout<< “Your grade is 1 class !!”;st
in
cout<< “Your grade is 2nd class !!”;
else if (mark >=40)
s.
cout<<”Your grade is 3rd class !!”;
s
else
cout<<”You are Fail !!”<<endl;
}
return 0;
p re
ex
Student Activity
vi
1. The teacher splits the class into groups and ask each group to share their ideas and thoughts to
prepare a C++ program to find the biggest of three numbers
al
.k
Evaluation
w
1. Write a C++ program to calculate the income tax for the given annual income using the following
w
data.
w
2. Write a C++ program to find the given number is positive, negative or zero.
13 Iteration statements -
For loop
Learning Outcome
in
Teacher Activity 1
s.
Introduction
s
re
Selection statements and iteration statements are executed depending upon the conditional
expression. The conditional expression evaluates to either true or false. Here we are going to study
about for loop.
p
ex
Iteration
An iteration (or looping) is a sequence of one or more statements that are repeatedly executed
vi
until a condition is satisfied. These statements are also called as control flow statements.
¾¾ Reduces time
w
¾¾ while statement
¾¾ do-while statement
All looping statements repeat a set of statements as long as a specified condition remains true. The
specified condition is referred as a loop control. For all three loop statements, a true condition is any
nonzero value and a zero value shows a false condition.
‘for ‘ loop
The for loop is a entry- controlled loop (first the test-expression is evaluated and if it is nonzero,
the body of the loop is executed otherwise the loop is terminated). and is the easiest looping statement
which allows code to be executed repeatedly.
in
Program -1
s.
C++ program to display numbers from 1 to 5 using for loop
s
#include <iostream>
{
using namespace std;
int main ()
p re Output:
1
ex
int i;
2
for(i = 1; i<=5; i ++ )
3
vi
cout <<i<<endl;
4
return 0;
5
al
}
.k
Program -2
C++ program to sum the numbers from 1 to 10 using for loop
w
#include <iostream>
w
int main ()
{
int i,sum=0;
for(i=1; i<=10;i++)
{
sum=sum+i; Output:
} The sum of 1 to 10 is : 55
cout<<”The sum of 1 to 10 is : “<<sum;
return 0;
}
Student Activity
1. The teacher asks the students to write a C++ program to display numbers from 10 to 1 using for
loop.
Evaluation
in
using namespace std;
int main()
s.
{
s
int i,fact = 1;
{
for(i = 1; i < 6; i++)
p re
ex
fact *= i;
}
vi
3. H
ow many times the loop will be executed ?
w
Teacher Activity 1
in
Introduction
s.
Looping statements repeat a set of statements as long as a specified condition remains true. In
s
C++, any non zero is treated as true including negative numbers and zero is treated as false . Here we
are going to study about the iteration or Looping statements while and do-while.
While loop
p re
A while loop is a control flow statement that allows the loop statements to be executed as long
ex
as the condition is true. The while loop is an entry-controlled loop because the test-expression is
evaluated before entering into a loop.
{
Body of the loop;
.k
}
Statement-x;
w
In while loop, the test expression is evaluated and if the test expression result is true, then the body
of the loop is executed and again the control is transferred to the while loop. When the test expression
w
Program
w
C++ program to find sum and average of 1 to 5 numbers using while loop
#include <iostream>
using namespace std;
int main ()
Output:
{
int i=1,avg,sum=0; The sum is : 15
while(i<=5) The average is : 3
{
sum=sum+i ;
i++;
}
avg=sum/5;
cout<<”The sum is : “<<sum<<endl;
cout<<”The average is :”<<avg;
return 0;
}
Teacher Activity 2
do-while loop
The do-while loop is an exit-controlled loop because the condition is evaluated at the bottom of
the loop after executing the body of the loop. This means that the body of the loop is executed at least
once, even when the condition evaluates false during the first iteration.
The general syntax is:
do
in
{
Body of the loop;
s.
} while(condition);
Program
s
C++ program to display number from 10 to 1 using do-while loop
{
#include <iostream>
using namespace std;
int main ()
p re
ex
int n = 10; Output:
do
{ 10 9 8 7 6 5 4 3 2 1
vi
cout<<n<<” “;
n--;
al
}while (n>0) ;
}
.k
Student Activity
w
1. The students are asked to write a C++ program to display numbers from 1 to 10 using while and do-
while loops.
w
2. Each student in the class is asked to write a C++ program to print their name 5 times using do-
while loop.
w
Evaluation
1. Write a C++ Program to find the sum of all numbers from 10 to 15 using while loop.
2. What will be the output of the following code:
int i = 5,total = 0;
do
{
total += i;
i++;
}while (i <= 10);
cout << total;
15 Jump statements
Learning Outcome
in
Teacher Activity 1
s.
Introduction
s
re
Generally a program executes its statements sequentially from beginning to end. However, in some
situations, the flow of control jumps from one part of the code to another segment of code. Such jumps
are called “control flow”. Here we are going to study about various jump statements.
p
Jump statements
ex
¾¾ goto statement
¾¾ break statement
.k
¾¾ continue statement
w
goto statement
w
The goto statement is a control statement which is used to transfer the control from one place to
another place without any condition in a program.
w
In the syntax above, label is an identifier. When goto label is encountered, the control of program
jumps to label: and executes the code below it.
Program
C++ program to display the first five odd numbers using goto statement
# include <iostream>
using namespace std;
int main()
{
int n=1;
jump:
{
if(n<10)
in
{
s.
cout<<n<<’\t’;
s
n+=2; Output:
goto jump;
}
p re 1 3 5 7 9
return 0;
ex
}
vi
}
al
Teacher Activity 2
.k
break statement
w
A break statement is a jump statement which terminates the execution of loop and the control is
transferred to resume normal execution after the body of the loop .
w
Program
w
if( i > 3)
{ Output:
break; Count : 1 Count : 2 Count :3 Count : 4
}}
return 0; }
continue statement
In is very similar to tha break statement Instead of terminating the loop (break statement),
continue statement forces the loop to continue or execute the next iteration.
Program
C++ program to display numbers from 1 to 10 except 6 using continue statement
in
#include <iostream>
s.
using namespace std;
int main()
s
{
{
for (int i = 1; i<= 10; i++)
p re
ex
if (i == 6)
Output:
continue;
1 2 3 4 5 7 8 9 10
vi
else
al
cout<<i<< “ “;
} }
.k
Student Activity
w
1. The teacher asks the students to write a C++ program to display odd numbers from 49 to 19 except
w
Evaluation
16 Functions
Learning Outcome
in
Understand the types of functions.
Teacher Activity 1
s s.
Introduction:
Example:
p re
The Teacher motivates the students by asking about daily life problems like functions of the bank.
In a bank, we have many functions like opening an account, closing the account. accepting deposit,
ex
granting loans, credit cash and so on.
A large program can be split into small sub-programs (blocks) called as functions where each sub-
program can perform some specific functionality. Functions reduce the size and complexity of a program.
vi
It makes easier to understand, test and check for errors. The functions which are available by default is
known as “Built in” function and user can create their own functions known as “User-defined” function.
al
Teacher Activity 2
.k
2. Reusability:
¾¾ F
ew lines of code may be repeatedly used in different context. Duplication of the same code
can be eliminated by using functions which improves the maintenance and reduce the program
size.
¾¾ Some functions can be called multiple times with different inputs.
Teacher Activity 3
in
Types of functions:
s.
Function can be classified into two types.
1. Pre-defined or Built-in or Library functions.
s
2. User defined functions.
re
C++ provides a rich collection of function ready to be used for various tasks. The tasks are
p
already written, debugged and compiled, their definitions alone are grouped and stored in files called
header files. Such ready to use sub programs called pre-defined or built-in functions.
ex
C++ also provides the facility to create new functions for specific need as per user requirement.
The name of the task and data required (arguments) are decided by the user and hence they are known
vi
as User-defined functions.
al
Student Activity
.k
1. The teacher asks the students to write the functions of school, hospital, medical shop etc.
w
w
Evaluation
w
1. Define function.
2. What are the types of functions?
3. What is built in function?
in
Use string and character functions for the manipulation of string and character data.
s.
Teacher Activity 1
s
Motivation:
The Teacher asks questions to motivate the students.
1. What is function?
p re
ex
2. What are the types of function?
3. What is built in function?
vi
Introduction:
The teacher introduces the lesson witha real time examples.
al
Header file provide function prototype and definitions for library functions. Data types and con-
.k
stants used with the library functions are also defined in them.
A header file can be identified by their file extension .h. It contains multiple built-in functions.
w
i) stdio.h – this header file defines the standard I/O predefined functions getchar( ), putchar( ),
w
ii) ctype.h – this header file defines various operations on characters. The various ctype functions
are isalnum( ), isalpha( ), isdigits( ),islower( ), isupper( ), tolower( ), toupper( ) etc.
iii) string.h – has several common functions for dealing with strings stored in array of characters.
The various string functions are strcpy( ), strlen( ), strcmp( ), strcat( ), strupr(), strlwr( ) etc.
iv) math.h – has several mathematical functions like cos( ), sqrt( ), sin( ), pow( ) etc.
Teacher Activity 2
The teacher explains the usage of mathematical and Character functions.
Program 1:
C++ code to find the square root of the given number.
#include<iostream>
#include<math.h>
using namespace std;
int main( )
{
int n;
cout<<”Enter a number:”;
cin>>n;
cout<<sqrt(n);
in
return(0);
}
s.
Output:
s
Enter a number: 49
Program 2:
7 p re
ex
C++ code to check whether a given character is a digit or not.
#include<iostream>
vi
#include<ctype.h>
using namespace std;
al
int main( )
.k
{
char ch;
w
cout<<”Enter a character:”;
w
cin>>ch;
cout<<”The return value of isdigit(ch) is:”<<isdigit(ch);
w
Output 1:
Enter a character: 3
The return value of
isdigit(ch) is: 1
Output 2:
Enter a character: A
The return value of
isdigit(ch) is: 0
Program 3:
C++ code to convert a lowercase string into its uppercase string.
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main( )
Output:
{
Enter a string in lowercase: computer
char s[50];
The uppercase string is: COMPUTER
cout<<”Enter a string in lowercase:”;
gets(s);
in
cout<<”The uppercase string is:”<<strupr(s);
s.
return(0);
}
s
Student Activity p re
1. The students are divided into two groups and one group discusses the gets() function and the
ex
other group the pow() function.
2. The students in groups discuss and share their information with others on how to write a C++
vi
Evaluation
.k
#include<iostream>
w
#include<stdio.h>
#include<string.h>
w
18 User Defined
Functions
Learning Outcome
After completion of this topic, the students will be able to
Implement modular programming for creating function.
Understand the function definition and prototype.
Understand return statement.
in
Teacher Activity 1
Motivation:
s.
The teacher asks questions from the previous topic.
s
Introduction:
re
We can define new functions to perform a specific task. These are called as “user defined” functions.
They are created by the user. A function can optionally define input parameters that enable callers to
p
pass arguments into the function. A function can also optionally return a value as output.
Function definition:
ex
Example:
int add (int a, int b)
w
{
int c;
w
c=a+b;
return(c);
w
Teacher Activity 2
Function Prototype:
A function prototype describes the function interface to the compiler by giving details such as
the number and the types of arguments and the types of return values. Like a variable declaration, a
function must be declared before it is used in the program. the declaration statement may be given
outside the main( ) function.
Example:
long fact ( int, double );
Teacher Activity 3
Accessing a Function:
The user - defined function should be called explicitly using its name and the required arguments
to be passed. The compiler refers to the function prototype to check whether the function has been called
correctly. If the argument type does not match exactly with the data type defined in the prototype, the
compiler will perform type conversion, if possible. If type conversion is impossible, it generates an error
message.
Example:
#include<iostream>
in
using namespace std;
int sum(int x, int y) // function prototype
s.
{
return (x+y);
s
}
int main( )
{
int a,b;
cout<<”enter a and b values:”;
cin>>a>>b;
p re
ex
cout<<”The sum is:”<<sum(a,b); // calling a function
}
vi
Teacher Activity 4
Return Statement:
al
The return statement is used to return from a function. It is categorized as a jump statement
because it terminates the execution of the function and transfer the control to the called statement.
.k
A return may or may not have a value associated with it. If return has a value associated with it, that
value becomes the return value for the calling statement. void function without parameter, the return
w
return expression/variable;
Example
w
return (a+b):
return s;
Student Activity
1. The students are asked to draw a concept map for return statement.
2. The students in group discuss about the user defined functions.
Evaluation
1. What is user defined function?
2. How to access a function?
3. Write a C++ program to multiply two numbers using user defined functions.
Learning Outcome
Teacher Activity 1
in
Motivation:
s.
The teacher asks the questions from the previous topic.
s
Introduction:
Teacher Activity 2
.k
Teacher explains the different forms of user defined function declarations with example.
i). A function without return value and without parameter
w
The name of the function is display(), its return data type is void and it does not have any param-
w
eter.
#include <iostream>
w
{
display( );
return(0);
}
ii) A function with return value and without parameter
The name of the function is display(), its return data type is int and it does not have any param-
eter.
#include <iostream>
using namespace std;
int display( )
{
int a,b,sum;
in
Output:
cout<<”Enter two numbers:”; Enter two numbers: 10 30
s.
cin>>a>>b; The sum is: 40
s
sum=a+b;
}
return sum;
int main( )
p re
ex
{
cout<<”The sum is:”<<display( );
vi
return(0);
al
}
.k
#include <iostream>
w
}
iv) A function with return value and with parameter
The name of the function is display(), its return data type is int and it has two parameters x and y
to receive two values.
#include <iostream>
using namespace std;
int display(int x, int y)
in
{
s.
int sum=x+y;
return sum; Output:
s
} Enter two numbers: 10 30
{
int main( )
p re The sum is: 40
ex
int a,b;
cout<<”Enter two numbers:”;
vi
cin>>a>>b;
int sum=display(a,b);
al
return(0);
}
w
Student Activity
w
w
1. The teacher asks the students individually write a program to multiply two numbers using func-
tion with four different forms of user defined function declaration.
Evaluation
1. Write a program to calculate area of rectangle using different forms of user defined function
declarations?
20 Recursive Function
Learning Outcomes
in
Teacher Activity 1
s.
Motivation:
s
The teacher motivates the students by asking questions of the previous topic
Introduction :
re
A function that calls itself is known as recursive function. And, this technique is known as recur-
sion.
p
ex
Program:
vi
#include <iostream>
using namespace std;
.k
int factorial(int);
int main()
w
{
int n,fact;
w
cout<<”Enter a number to find factorial: “;
w
cin >> n;
fact=factorial(n);
cout << “Factorial of “ << n <<” = “ << fact;
return 0;
}
int factorial (int n)
{
if (n > 1)
return n *factorial(n-1);
else
return 1;
}
Output:
Enter a number to find factorial: 5
Factorial of 5 = 120
Teacher Activity 2
Program:
Write a program to find the sum of first ‘n’ natural numbers. 1+2+3+……..+n.
#include <iostream>
using namespace std;
int sum(int);
int main()
in
{
int n,sum;
cout<<”Enter a number: “;
s.
cin >> n;
sum=sum1(n);
s
cout << “Sum of first “ << n <<” numbers = “ << sum;
}
return 0;
int sum1 (int n)
{
p
Output:
re
ex
if (n > 1) Enter a number : 10
return n+sum1(n-1);
Sum of first 10 numbers = 55
else
vi
return 1;
}
al
Student Activity
.k
1. The students form groups and discuss about the execution of recursive function.
w
w
Evaluation
w
21 Scope Rules of
variables
Learning Outcomes
After completion of this topic, the students will be able
To know the definition of scope.
To understand the types of scope variables and functions in a program.
in
Teacher Activity 1
Introduction:
s.
Scope refers to the accessibility of a variable. There are four types of scopes in C++.They are Local
s
Scope, Function Scope, File Scope and Class Scope.
¾¾
p
Inside a block which is called local variables.
re
A scope is a region or life of the variable and broadly speaking there are three places, where
variables can be declared,
Local Scope:
al
¾¾ A variable which is declared inside a block .A block of code begins and ends with only braces
{ }.
.k
¾¾ The local variables cannot be accessed from outside the block of its declaration.
Program
w
#include<iostream>
w
Teacher Activity 2
Function Scope:
¾¾ A Variable which is declared inside a function is called function variables.
¾¾ The life time of the function scope variable is the life time of the function block.
Program
#include<iostream>
using namespace std;
void add(int x,int y)
{
int s2=x+y; // Function variable //
in
cout<<”Function Variable=”<<s2;
s.
}
int main()
s
{
add(a,b);
int a=20,b=10;
p re
ex
return(0); }
Teacher Activity 2
vi
al
File Scope:
.k
¾¾ The variable which is declared outside of all functions is called file scope or global scope.
¾¾ The life time of a file scope is the life time of a program.
w
Program
w
#include<iostream>
w
Class Scope
A class is a new way of creating and implementing a user defined data type. Classes provide a
method for packing together data of different types. Data members are the data variables that represent
the features or properties of a class.
Student Activity
1. The students in groups discuss about the reason for the invalidity of the underlined statement in
the following program.
#include<iostream>
using namespace std;
int main()
{
in
int a,b;
s.
cin>>a>>b;
if (a>=b)
s
{
int c;
c=a+b;
p re
ex
}
cout<<c;
vi
}
al
.k
Evaluation
w
22 Single Dimensional
Array
Learning Outcomes
After completion of this topic, the students will be able to
Know the definition of arrays.
Understand the Types of Arrays.
Understand the memory allocation of single dimensional arrays.
in
Understand how to access single dimensional array elements.
s.
Teacher Activity 1
s
Introduction:
re
A single variable is used to store a single value that can be used anywhere in the memory. In some
p
situations, we need to store multiple values of the same type. In that case, it needs multiple variables of
the same data type. All the values are stored randomly anywhere in the memory. For example, to store
ex
the roll numbers of the 100 students, it needs 100 variables named as roll1, roll2, roll3,……. roll100 .
It becomes very difficult to declare 100 variables and store all the roll numbers. In C++, the concept of
vi
Array
al
¾¾ An Array is a collection of variables of the same type that are referenced by a common name.
w
¾¾ I n array the values are stored in a fixed number of elements of the same type sequentially in
memory.
w
Types of Arrays
w
Syntax:
<data type> <array_name> [<array_size>];
Example:
int num[10];
float sum[5];
Program
Write a C++ program to read the marks of 5 students and print the marks of all those students.
#include<iostream>
using namespace std;
int main()
{
in
int marks[5];
s.
cout<<”Read marks of 5 students”;
for(int i=0;i<5;i++)
s
cin>>marks[i];
cout<<”Print marks of 5 students\n”;
for(int i=0;i<5;i++)
p re
ex
cout<<marks[i]<<endl;
return 0;}
vi
Output
al
60 60
w
75 75
80 80
w
90 90
w
Teacher Activity 2
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
Teacher Activity 3
Program:
Write a C++ program to access the 2nd and 5thelements of given array.
#include<iostream>
using namespace std;
int main()
{
in
int num[5]={10,20,30,40,50};
cout<<num[1]<<endl;
s.
cout<<num[4];
return 0;
s
}
Output:
20
p re
50
ex
Student Activity
vi
1. The students are divided into two groups and one group writes a C++ program to read the marks
al
of 10 students and the other group to print the marks of all those students .
2. The students are asked to access the first and last elements of the given array.
.k
int marks[5]={50,75,80,90,35}
w
w
Evaluation
w
23 Two-Dimensional
Array
Learning Outcomes
After learning this topic the student will be able to
Know the definition of Two-dimensional arrays.
Understand the memory allocation of Two-dimensional arrays.
Understand how to access Two-dimensional array elements.
in
Teacher Activity 1
s.
Introduction
s
A single variable is used to store a single value that can be used anywhere in the memory. In some
re
situations we need to store multiple values of the same type. In that case,it needs multiple variables of
the same data type.All the values are stored randomly anywhere in the memory.
p
For example, to store 5 subject marks of the 100 students, it needs 500 variables .It becomes very
ex
difficult to declare and store all the marks of students.In C++ the concept of 2D array helps to store
multiple values in a single variable.
Two-dimensional Array
vi
The 2D array is organized as matrices which can be represented as the collection of rows and col-
al
umns.
Syntax:
.k
int num[3][2];
Program
w
Write a C++ program to read the marks of 3 students in 2 subjects and print it in matrix form.
w
#include<iostream>
using namespace std;
int main()
{ int marks[3][2];
cout<<”Read the marks “;
for(int i=0;i<3;i++)
for(int j=0;j<2;j++)
cin>>marks[i][j];
cout<<”Matrix Form of marks\n”;
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
cout<<marks[i][j]<<” “;
cout<<”\n”;
}}
Output
Read the marks
50
20
75
80
89
78
Matrix Form of marks
in
50 20
75 80
89 78
s s.
Teacher Activity 2
Example:
vi
num[0][0] num[0][1]
int num[3][2] ; num[1][0] num[1][1]
al
num[2][0] num[2][1]
.k
Teacher Activity 3
Program:
Write a C++ program to access the 2nd and 5th elements of given array.
#include<iostream>
using namespace std;
int main()
{
int num[3][2]={10, 20, 30, 40, 50, 60};
cout<<num[0][1]<<endl;
cout<<num[2][0];
}
in
Output:
s.
20
s
50
Student Activity
p re
ex
1. The students in pair discuss about the two dimensional array and write a C++ program to print
the below given matrix (2x3) using two dimensional array.
vi
5 4 5
al
2 6 7
.k
2. The students are asked to find out the total number of elements in an array float mark[4][3].
3. The students are asked to write a C++ program to access the first and last elements of given array
w
int value[2][2]={50,75,80,56 }
w
w
Evaluation
24
Introduction to Object
Oriented Programming
Techniques
Learning Outcomes
in
Understand the advantages and disadvantages of Object Oriented Programming.
s.
Teacher Activity 1
s
Introduction:
Do you know the first name of C++?
C with Classes
p re
Object-Oriented Program:
ex
Object-Oriented Programming (OOP) is the term used to describe a programming approach based
on classes and objects. The object-oriented paradigm allows us to organize software as a collection
vi
of objects that consist of both data and behaviour. This is in contrast to conventional functional
programming practice, that loosely connects data and behaviour.
al
.k
w
w
w
Teacher Activity 2
Programming Paradigms
Paradigm means organizing principle of a program. It is an approach to programming.There are
different approaches available for problem solving using computer. They are
1. Procedural programming
Procedural means a list of instructions were given to the computer to do something. Programs are
organized in the form of subroutines or sub programs. example. FORTRAN and COBOL.
2. Modular programming
Modular programming consists of multiple modules, each module has a set of functions of related
types. Data is hidden under the modules. It emphasis on algorithm rather than data. Example.
in
Pascal and C
3. Object Oriented Programming
s.
Object Oriented Programming paradigm emphasizes on the data rather than the algorithm. It
s
implements programs using classes and objects. Eg: C++, Python, java
re
Class: A Class is used to bind data and its associated function together into a single unit using the
encapsulation concept. Class is a user defined data type. Class represents a group of similar
objects.
p
ex
Objects: Represents data and its associated function together into a single unit. Objects are the basic
unit of OOP. Basically an object is created from a class. They are instances of class also called as
class variables An identifiable entity with some characteristics and behavior is called object.
vi
Teacher Activity 3
.k
The Object Oriented Programing has been developed to overcome the drawbacks of procedural
and modular programming. It is widely accepted that object-oriented programming is the most
w
¾¾ Software re-use: where a program can be composed from existing and new modules
1. Encapsulation : The mechanism by which the data and functions are bound together into a
single unit is known as Encapsulation.
2. Data Abstraction : Abstraction refers to showing only the essential features without reveal-
ing background details.
3. Modularity : Modularity is designing a system that is divided into a set of functional units.
4. Inheritance : Inheritance is the technique of building new classes (derived class) from an
existing Class (base class).
Advantages of OOP
Re-usability
Redundancy
Easy Maintenance
Security
Disadvantages of OOP
in
Size : OOPs are much larger than other programs.
Effort : OOPs require a lot of work to create.
s.
Speed : OOPs are slower than other programs, because of their size.
s
Student Activity p re
1. The students discuss about the advantages and disadvantages of OOP and write them down in
their note book.
ex
2. The students prepare matching cards for the main features of Object Oriented Programming
vi
1. Class – 1. Overloading
2. Data Abstraction – 2. User defined function
al
Evaluation
w
Animal
Name eat()
Size sleep()
Age run()
Colour sit()
Sex
in
Understand the Class Access Specifiers.
s.
Teacher Activity 1
s
Need for Class
re
Class is a way to bind the data and its associated functions together. Classes are needed to represent
real world entities, that not only have data type properties but also have associated operations. It is
used to create user defined data type.
p
ex
Declaration of a class
¾¾ A class is defined in C++ using the keyword class followed by the name of the class.
vi
¾¾ Th
e body of the class is defined inside the curly brackets and terminated either by a semicolon
or a list of declarations at the end.
al
¾¾ The class body contains the declaration of its members (Data member and Member functions).
.k
¾¾ The class body has three access specifiers (private, public and protected)
The General Form of a class definition
w
class class-name
w
{
private:
w
variable declaration;
function declaration;
protected:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
XII Std Computer Science 62
Teacher Activity 2
A public member is accessible from anywhere outside the class but within a program. You can set
and get the value of public data members even without using any member function.
in
The Private Members
s.
A private member cannot be accessed from outside the class. Only the class member functions can
access private members. Default member of the class is private.
s
re
The Protected Members
A protected member cannot be accessed from outside the class, however, they can be accessed in
p
inherited classes.
ex
Example.
vi
class student
al
{
.k
private:
w
char name[10]:
w
int rollno,mark1,mark2.total;
w
protected:
void accept();
void compute();
public:
void display();
};
Student Activity
1. The students are asked to specify the access specifier of the variables name,regno and total in the
following program code.
class student
{
char name[10];
int regno;
public:
int total;
void getdatat();
void display();
};
in
s.
Evaluation
s
re
1. Find out the errors of the underlined statement in the following code fragment
class student;
p
{
ex
Private
vi
char name[10];
al
int rollno,mark1,mark2,total;
protected:
.k
void accept();
w
void compute;
w
public:
w
void display(); };
in
Teacher Activity 1
s.
What are the class members?
Data members and member functions.
s
Definition of class members
re
Class members are classified as Data Members and Member functions.
Data members are the data variables that represent the features or properties of a class. Data mem-
bers are also called as attributes.
p
ex
Member functions are the functions that perform specific tasks in a class. Member functions are
called as methods.
vi
al
.k
w
w
Teacher Activity 2
Objects Creation and Accessing:
The class variables are called object. Objects are also called as instance of class. The members of
a class are accessed by using the object of the class followed by the dot operator and the name of the
in
member.
Syntax for accessing Class members
s.
Object_name . function_name(actual parameter);
s
Example
Stud . execute();
p re
Membner function
Dot operator
Object name
ex
the closing brace of the class declaration then it is called as Global object. These objects can be used by
any function in the program
w
If an object is declared with in a function then it is called local object. It cannot be accessed from
outside the function.
w
Eg.
class add
{
int a,b;
public:
int sum;
void getdata()
{
a=5;
b=10;
sum = a+b;
}
} a1; //global object
Student Activity
1. The students are asked to categorize the global object and local object in the following program
in
code and present their tasks to the class
class subtract
s.
{
int m1,m2;
s
public:
int sub;
void getdata()
m1=10;
{
p re
m2=5;
ex
sub = m1- m2;
}
} s1;
vi
int main()
{
al
subtract s2;
s1.getdata();
.k
s2.getdata();
cout<<s1.sub;
cout<<s2.sub;
w
return 0;
}
w
w
Evaluation
1. Identify class name,object name,data members and member functions in the following program code.
class student
{
private:
char name[10];
int rollno,total;
public:
void accept();
void display();
}s1,s2;
27 CONSTRUCTORS
Learning Outcomes
After learning this topic, the students will be able to
Understand the purpose and functions of constructors.
Construct C++ programs using classes with constructors.
Teacher Activity 1
in
Introduction to Constructors:
s.
The definition of a class only creates a new user defined data type. The instances of the class type
s
should be instantiated (created and initialized). Instantiating object is done using constructor. The
constructor function initializes the class object.
Declaration and Definition :
p re
When an instance of a class comes into scope, a special function called the constructor gets
executed. The constructor function name has the same name as the class name. The Constructors
ex
return nothing. It can be defined either inside or outside the class definition.
class sample
vi
{
int i,j ;
al
public :
sample( ) --------------- Constructor
.k
{
i=j=0;
w
}
};
w
Functions of Constructor:
w
Teacher Activity 2
Illustration of Constructor in a class
#include<iostream>
using namespace std;
class data
{
int i,j;
public:
data() ----------------------------- Constructor without parameter
{
cout<< ” Non-Parameterized Constructor ”;
i=0;
j=0;
}
data(int a, int b) --------------------- Constructor with parameters
in
{
cout<< ” Parameterized Constructor ”;
i=a;
s.
j=b;
}
s
void display() ----------------------- member function
{
cout<<i<<j;
}
};
int main()
p re
ex
{
data d1, d2(10,20);
d1.display();
vi
d2.display();
return 0;
}
al
Student Activity
.k
1. The students sit in groups and discuss about the purpose and Characteristics of Constructors. Each
w
Evaluation
w
28 DESTRUCTORS
Learning Outcomes
After learning this topic, the students will be able to
Understand the purpose and characteristics of destructors.
Construct C++ programs using classes with destructors.
in
Teacher Activity 1
Introduction to Destructors:
s.
When a class object goes out of scope, a special function called the destructor gets executed. The
s
destructor has the same name as the class tag but prefixed with a ~ (tilde). Destructor function return
re
nothing and it does not associated with any data type.
Declaration and Definition :
p
A destructor is a special member function that is called when the lifetime of an object ends and
destroys the object constructed by the constructor. Normally declared under public.
ex
class add
{
vi
int a, b ;
public :
add( ) ----------------- Constructor
al
{
a=b=0;
.k
}
~add() --------------- Destructor
w
{
cout<<”Destructor”;
w
}
};
w
Need of Destructors:
The purpose of the destructor is to free the resources that the object may have acquired during
its lifetime. A destructor function removes the memory of an object which was allocated by the
constructor at the time of creating an object.
Characteristics of Destructors:
¾¾ The destructor has the same name as that class prefixed by the tilde character ‘~’.
¾¾ The destructor cannot have arguments
¾¾ It has no return type
¾¾ Destructors cannot be overloaded
¾¾ In the absence of user defined destructor, it is generated by the compiler
¾¾ Th
e destructor is executed automatically when the control reaches the end of class scope to
destroy the object
¾¾ They cannot be inherited
Teacher Activity 2
The Teacher explains the Destructor in the following program.
#include<iostream>
using namespace std;
class simple Output:
{
int i,j; Constructor of class simple
public:
Destructor is executed to destroy
simple ( )
{ the object
in
i=j=0;
cout<<”Constructor of class simple”<<endl;
s.
}
~ simple ( ) ----------------------------- Destructor
{
s
cout<<” \n Destructor is executed to destroy the object”;
}
};
{
int main ()
p re
ex
simple s;
return 0;
}
vi
Student Activity
al
1. The students prepare concept map for the purpose and characteristics of Destructors.
.k
2. The students are asked to write the destructor for the following C++ code.
class test
w
{
int a,b,sum;
w
public:
test()
w
{
cout<<”Constructor”;
}
};
Evaluation
1. What is destructor?
2. When are destructor called?
3. How destructor is differs from normal member function?
in
Teacher Activity 1
s.
Introduction
Internet is a communication media which is easily accessible and open to all. Information
s
Technology is widespread through computers, mobile phones and internet. There is a lot of scope and
possibility for misuse of Information Technology.p re
Computer systems in general are vulnerable. They play an important role in the daily lives of
individuals and businesses. Special care must be taken explicitly in order to ensure that the valuable
data do not get into wrong hands. Hence, the data need to be protected. A cyber-crime is a crime
ex
which involves computer and network. This is becoming a growing threat to society and is caused
by criminals or irresponsible action of individuals who are exploiting the widespread use of Internet.
It presents a major challenge to the ethical use of information technologies. Cyber-crime also poses
vi
Ethics means “What is wrong and What is Right”. It is a set of moral principles that rule the behavior
.k
of individuals who use computers. An individual gains knowledge to follow the right behavior, using
morals that are also known as ethics. Morals refer to the generally accepted standards of right and
w
wrong in the society. Similarly, in cyberworld, there are certain standards such as
¾¾ Do not use pirated software
w
¾¾ Do not hack
Teacher Activity 2
Ethical Issues :
Cyber crime:
Cyber crime is a criminal activity that uses a computer, computer network or a network device.
Those who commit such crimes generally manipulate the computer system in an intelligent manner.
Example:
Illegal money transfer via the internet.
Morphing the image, text or video content.
Software piracy:
Software piracy is the copyright violation of software created originally by an individual or an
institution. It is also called “unauthorized copying of software”.
Example:
Duplicating and selling copyrighted programs.
Downloading software illegally through the network.
Hacking:
Hacking is intruding into a computer system to steal personal data without the owner’s permission
or knowledge. It is also gaining unauthorized access to a computer system and altering its contents. It
may be a criminal activity or may be a hobby.
Cracking:
Cracking means trying to get into a computer system in order to steal or corrupt data. Crackers
may send official email requesting some sensitive information. A cracker is a malicious or criminal
hacker.
in
Example: Using a password cracking algorithm to gain access to a computer system.
s.
Teacher Activity 3
s
Cyber security:
p re
Cyber attacks cause significant damage to a computer system or for stealing important informa-
tion from an individual or an organization. Cyber security is a collection of various technologies,
processes and measures that reduces the risk of cyber attacks and protects the organizations and indi-
viduals from computer based threats.
ex
Firewall:
Firewall is a computer network security based system that monitors and controls incoming and
al
outgoing network traffic based on predefined security rules. A firewall commonly establishes a block
between a trusted internal computer network and entrusted computers outside the network.
.k
Encryption is the process of translating the plain text data into random data called ciphertext.
Decryption is the reverse process of converting the ciphertext back to a plain text.
w
Student Activity
1. The students sit in groups and do the sketch noting in a chart about the various cyber crimes and
Computer Ethics , and present them one by one to the class in their turn.
Evaluation
1. Write any five ethics that you have to follow while using internet.
30 Tamil Computing
Learning Outcomes
After learning this topic, the students will be able to
Know how to use modern technology through the internet.
Know the uses of Tamil in Social media.
in
Teacher Activity 1
s.
Tamil in Internet:
s
re
¾¾ Internet is the best information technological device through which we get information.
Internet today plays a vital role in every man’s life.
p
¾¾ I n 2017 a Singapore based organisation KPMA along with Google reported that, Tamil topped
the list among the most widely used languages in India where 42% are using the internet in
ex
Tamil.
¾¾ A
s per study, among the Indian language users of the internet, 74% of people will be using
vi
Tamil by 2021 and it will be in the top usage of the internet in India.
al
¾¾ Google, Bing and Yahoo are the top search engines used by the users.
w
¾¾ T
o use the search engine Google, we can use https://www.google.com and for Yahoo, we can use
w
https://in.yahoo.com.
Teacher Activity 2
E-Governance
Getting government services through the internet is known as e-governance. The Government of
Tamilnadu has been giving its services through the internet.
Web Address and its E-governance.
1. http://www.tn.gov.in/ta Official Website of Govt. of Tamilnadu
2. http://www.aed.tn.gov.in/ Department of Agricultural Engineering
E-library
E-libraries are portal or website of collection of e-books. Tamil E-library services provide thousands
of Tamil books as e-books mostly at free of cost. It is the most useful service to Tamil people who live
far away from their homeland.
Web Address and its E-library
1. http://www.textbooksonline.tn.nic.in/ Tamilnadu School Textbooks
2. http://tamildigitallibrary.in/ Tamil Digital Library
3. http://www.chennailibrary.com/ Chennai Library
in
4. http://www.thamizhagam.net/parithi/parithi.html Thamizhagam
s.
Teacher Activity 3
s
Tamil typing and interface software p re
Tamil is mostly used to type documents in word processors and search information on the internet.
Typing Tamil using Tamil interface software is a familiar one among the different methods of typing
Tamil in both computers and smartphones.
ex
Thamizpori (தமிழ்பொறி) is a Tamil Tranlation Application having more than 30000 Tamil words
.k
equalent to English words. Using this application, we can translate small English sentences into Tamil.
Google also gives an online translation facility, using this online facility we can translate from Tamil to any
w
Programming languages to develop software in computers and smart phones are available only
in English. Now, efforts are taken to develop programming languages in Tamil. Based on Python
programming language, the first Tamil programming language “Ezhil” (எழில்) is designed. With the
help of this programming language, we can write simple programs in Tamil.
Tamil Operating System
An operating system is needed to access electronic systems such as computer and smart phone.All
operating systems used in computers and smart phones are offered in Tamil environment. Windows
Tamil Environment interface should be downloaded and installed from the internet. It displays all
window elements such as Taskbar, desktop elements, names of icons and commands in Tamil.
Student Activity
in
1. The teacher provides website address to each student and the students perform the task of
downloading the material through the web site address given to them.
s s.
Evaluation
p re
1. Type a short paragraph about yourself in WordPad by using Tamil font.
ex
vi
al
.k
w
w
w