Plus One Computer Science Notes Chapter 8 Arrays

Kerala Plus One Computer Science Notes Chapter 8 Arrays

Summary
An array is a collection of elements with same data type Or with the same name we can store many elements, the first or second or third, etc can be distinguished by using the index(subscript). The first element’s index is 0, the second element’s index is 1, and so on.

Declaring arrays:
Suppose we want to find the sum of 100 numbers then we have to declare 100 variables to store the values. It is laborious work. Hence the need for array arises.
Syntax: data_type array_name[size];
To store 100 numbers the array declaration is as follows
int n[100]; By this we store 100 numbers. The index of the first element is 0 and the index of last element is 99.

Memory allocation for arrays:
The amount of memory requirement is directly related to its type and size,

  • int n[100]; It requires 2Bytes(for each integer) × 100 = 200 Bytes.
  • float d[100]; It requires 4Bytes(for each float) × 100=400 Bytes.

Array initialization:
Array can be initialized in the time of declaration. eg: int age[4] = {16, 17, 15, 18};

Accessing elements of arrays:
Normally loops are used to store and access elements in an array.
eg:
int mark[50], i;
for(i=0;i<50;i++)
{
cout<<“Enter value for mark”<<i+1;
cin>>mark[i];
}
cout<<“The marks are given below:”;
for(i=0;i<50;i++)
cout<<mark[i];

Array operations:
Traversal:
Accessing all the elements of an array is called traversal.

Sorting:
Arranging elements of an array in an order(ascending or descending)
1. Bubble sort:
It is a simple sorting method. In this sorting considering two adjascent elements if it is out of order, the elements are interchanged. After the first iteration the largest(in the case of ascending sorting) or smallest(in the case of descending sorting) will be the end of the array. This process continues.

2. Selection sort:
In selection sort the array is divided into two parts, the sorted part and unsorted part. first smallest element in the unsorted part is searched and exchanged with the first element. Now there is 2 parts sorted part and unsorted part. This process continues.

Searching:
It is the process of finding the position of the given element.
1. Linear search:
In this method each element of the array is compared with the element to be searched starting from the first element. If it finds the position of the element in the array is returned.

2. Binary search:
It uses a technique called divide and conquer method. It can be performed only on sorted arrays. First we check the element with the middle element. There are 3 possibilities. The first possibility is the searched element is the middle element then search can be finished.

The second possibility is the element is less than the middle value so the upper bound is the middle element. The third possibility is the element is greater than the middle value so the lower bound is the middle element. Repeat this process.

Two dimensional (2D) arrays:
Some occasions we have to store 6 different marks of 50 students. For this we use 2D arrays. An array with two subscripts is used.
eg: int mark[r][c]; Here r is the row and c is the column.

Declaring 2D arrays:
Syntax: datatype array_name[rows][columns];
The elements of this array is referred as mark[0][0], mark[0][1], mark[r – 1][c – 1].
eg: int m[5][5]; This array can store 5 × 5 = 25 elements.

Matrices as 2D arrays:
Matrix is a concept in mathematics that can be represented by 2D array with rows and columns. A nested loop(a loop contains another loop) is used to store and access elements in an array.

Multi-dimensional arrays:
3 Dimensional(3D) array is an example of this.
Syntax: data_type array_name[size1 ][size2][size3];
eg: int m[5][5][5]; This array can store 5 × 5 × 5 = 125 elements.

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 7 Control Statements

Kerala Plus One Computer Science Notes Chapter 7 Control Statements

Summary
These are classified into two decision making and iteration statements

Decision making statements:
if statement:
Syntax: if (condition)
{
Statement block;
}
First the condition is evaluated if it is true the statement block will be executed otherwise nothing will be happened.

if…else statement:
Syntax: if (condition)
{
Statement block1;
}
else
{
Statement block2;
}

Nested if:
An if statement contains another if statement completely then it is called nested if.
if (condition 1)
{
if (condition 2)
{
Statement block;
}
}
The statement block will be executed only if both the conditions evaluated are true.

The else if ladder:
The syntax will be given below
if (expression1)
{
statement block1;
}
else if (expression 2)
{
statement block 2;
}
else if (expression 3)
{
statement block 3;
}
……..
else
{
statement block n;
}
Here firstly, expression 1 will be evaluated if it is true only the statement blockl will be executed otherwise expression 2 will be evaluated if it is true only the statement block2 will be executed and so on. If all the expression evaluated is false then only statement block n will be executed

switch statement:
It is a multiple branch statement. Its syntax is given below.
switch(expression)
{
case value: statements;break;
case value: statements;break;
case value: statements;break;
case value: statements;break;
case value: statements;break;
………
default: statements;
}
First expression evaluated and selects the statements with matched case value. If all values are not matched the default statement will be executed.

Conditional operator:
It is a ternary operator hence it needs three operands. The operator is “?:”.
Syntax:
expression ? value if true : value if false. First evaluates the expression if it is true the second part will be executed otherwise the third part will be executed.

Iteration statements:
If we have to execute a block of statements more than once then iteration statements are used.

while statement:
It is an entry controlled loop. An entry controlled loop first checks the condition and execute(or enters in to) the body of loop only if it is true. The syntax is given below
Loop variable initialised
while(expression)
{
Body of the loop;
Update loop variable;
}
Here the loop variable must be initialised before the while loop. Then the expression is evaluated if it is true then only the body of the loop will be executed and the loop variable must be updated inside the body. The body of the loop will be executed until the expression becomes false.

for statement:
The syntax of for loop is
for(initialization; checking ; update loop variable)
{
Body of loop;
}
First part, initialization is executed once, then checking is carried out if it is true the body of the for loop is executed. Then loop variable is updated and again checking is carried out this process continues until the checking becomes false. It is an entry controlled loop.

do-while statement:
It is an exit controlled loop. Exit control loop first execute the body of the loop once even if the condition is false then check the condition.
do
{
Statements
} while(expression);
Here the body executes at least once even if the condition is false. After executing the body it checks the expression if it false it quits the body otherwise the process will continue.

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 6 Data Types and Operators

Kerala Plus One Computer Science Notes Chapter 6 Data Types and Operators

Summary
Concepts of data types:
The nature of data is different, data type specifies the nature of data we have to store.

C++ data types:
Plus One Computer Science Notes Chapter 6 Data Types and Operators 1

Fundamental data types:
It is also called built in data type. They are int, char, float, double and void
1. int data type:
It is used to store whole numbers without fractional (decimal point) part. It can be either negative or positive. It consumes 4 bytes (32 bits) of memory. i.e. 232 numbers. That is 231 negative numbers and 231 positive numbers (0 is considered as +ve) So a total of 232 numbers. We can store a number in between -231 to + 231-.

2. char data type:
Any symbol from the keyboard, eg: ‘A’, ‘?’, ‘9’ and so on. It consumes one byte( 8 bits) of memory. It is internally treated as integers, i.e. 28 = 256 characters. Each character is having a ASCII code, ‘a’ is having ASCII code 97 and zero is having ASCII code 48.

3. float data type:
It is used to store real numbers i.e. the numbers with decimal point. It uses 4 bytes(32 bits) of memory. eg: 67.89, 89.9 E-15.

4. double data type:
It is used to store very large real numbers. It uses 8 bytes(64 bits) of memory.

5. void data type:
void means nothing. It is used to represent a function returns nothing.

  1. User defined Data types: C++ allows programmers to define their own data type. They are Structure(struct), enumeration (enum), union, class, etc.
  2. Derived data types: The data types derived from fundamental data types are called Derived data types. They are Arrays, pointers, functions, etc

Variables:
The named memory locations are called variable. A variable has three important things

  1. variable name: A variable should have a name
  2. Memory address: Each and every byte of memory has an address. It is also called location (L) value.
  3. Content: The value stored in a variable is called content. lt is also called Read(R) value.

Operators:
An operator is a symbol that performs an operation. The data on which operations are carried out are called operands. Following are the operators
1. lnput(>>) and output(<<) operators are used to perform input and output operation.
eg: cin>>n;
cout<<n;

2. Arithmetic operators:
It is a binary operator. It is used to perform addition(+), subtraction(-), division (/), multiplication(*) and modulus(%- gives the remainder) operations.
eg: If x = 10 and y = 3 then
Plus One Computer Science Notes Chapter 6 Data Types and Operators 2
x/y = 3, because both operands are integer. To get the floating point result one of the operand must be float.

3. Relational operator:
It is also a binary operator. It is used to perform comparison or relational operation between two values and it gives either true(1) or false(O). The operators are <, <=, >, >=, == (equality)and !=(not equal to)
eg: If x = 10 and y = 3 then
Plus One Computer Science Notes Chapter 6 Data Types and Operators 3

4. Logical operators:
Here AND(&&) , OR(||) are binary operators and NOT (!) is a unary operator. It is used to combine relational operations and it gives either true(1) orfalse(O). If x = 1 and y = 0 then
Plus One Computer Science Notes Chapter 6 Data Types and Operators 4
Both operands must be true to get a true value in the case of AND (&&) operation. If x = 1 and y = 0 then
Plus One Computer Science Notes Chapter 6 Data Types and Operators 5
Either one of the operands must be true to get a true value in the case of OR(||) operation. If x = 1 and y = 0 then

!x!y
01

5. Conditional operator:
It is a ternary operator hence it needs three operands. The operator is”?:”.
Syntax:
expression ? value if true : value if false. First evaluates the expression if it is true the second part will be executed otherwise the third part will be executed.
eg: If x = 10 and y = 3 then x>y ? cout<<x : cout<<y;
Here the output is 10

6. sizeof():
This operator is used to find the size used by each data type. eg: sizeof(int) gives 2.

7. Increment and decrement operator:
These are unary operators.

  • Increment operator (++): It is used to increment the value of a variable by one i.e., x++ is equivalent to x = x + 1.
  • Decrement operator (- -): It is used to decrement the value of a variable by one i.e., x – – is equivalent to x = x – 1.

8. Assignment operator (=):
lt is used to assign the value of a right side to the left side variable.eg. x = 5; Here the value 5 is assigned to the variable x.

Expressions:
It is composed of operators and operands

Arithmetic expression:
It is composed of arithmetic operators and operands. In this expression the operands are integers then it is called Integer expression. If the operands are real numbers then it is called Floating point expression. If the operands are constants then it is called constant expression.

Relational expression:
It is composed of relational operators and operands

Logical expression:
It is composed of logical operators and operands

Statements:
Statements are smallest executable unit of a programming language. Each and every statement must be end with semicolon(;).

Declaration statement:
Each and every variable must be declared before using it. eg: int age;

Assignment statements:
Assignment operator is used to assign the value of RHS to LHS. eg: x = 100

Input statements:
lnput(>>) operator is used to perform input operation. eg: cin>>n;

Output statements:
output(<<) operator is used to perform output operation. eg: cout<<n;

Cascading of I/O operations:
The multiple use of input or output operators in a single statement is called cascading of i/o operators. eg: To take three numbers by using one statement is as follows
cin>>x>>y>>z;
To print three numbers by using one statement is as follows
cout<<x<<y<<z;

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 5 Introduction to C++ Programming

Kerala Plus One Computer Science Notes Chapter 5 Introduction to C++ Programming

Summary
It is developed by Bjarne Stroustrup. It is an extension of C Language.

Character set:
To study a language first we have to familiarize the character set. For example to study English language first we have to study the alphabets. Similarly here the character set includes letters(A to Z & a to z), digits(0 to 9), special characters(+, -, ?, *, /, …..) white spaces(non printable) etc..

Token:
It is the smallest individual units similar to a word in English or Malayalam language. C++ has 5 tokens
1. Keywords:
These are reserved words for the compiler. We can’t use for any other purposes eg: float is used to declare variable to store numbers with decimal point. We can’t use this for any other purpose

2. Identifier:
These are user defined words. Eg: variable name, function name, class name, object name, etc…

3. Literals (Constants):
Its value does not change during execution
(a) Integer literals:
Whole numbers without fractional parts are known as integer literals, its value does not change during execution. There are 3 types decimal, octal and hexadecimal.
eg:

  • For decimal 100, 150, etc
  • For octal 0100, 0240, etc
  • For hexadecimal 0x100, 0x1A, etc

(b)Float literals:
A number with fractional parts and its value does not change during execution is called floating point literals. eg: 3.14157, 79.78, etc.

(c) Character literal-: A valid C++ character enclosed in single quotes, its value does not change during execution. eg: ‘m’, ‘f ’ etc

(d) String literal:
One or more characters enclosed in double quotes is called string constant. A string is automatically appended by a null character(‘\0’)
eg: “Mary’s”, ’’India”, etc.

4. Punctuators:
In English or Malayalam language punctuation mark are used to increase the readability but here it is used to separate the tokens. eg: {,}, (,).

5. Operators:
These are symbols used to perform an operation(Arithmetic, relational, logical, etc…)

Integrated Development Environment(IDE):
It is used for developing programs

  1. It helps to write as well as editing the program.
  2. It helps to compile the program and linking it to other (header files and other user) programs
  3. It helps to run the program

Turbo C++ IDE:
Following is an C++ IDE
Plus One Computer Science Notes Chapter 5 Introduction to C++ Programming 1
(a) Opening the edit window:
Method I: File → Click the menu item New
Method II: Press Alt and F simultaneously then press N

(b) Saving the program:
Click File → Save or Press Function key F2 or Alt + F and then press S. Then give a file name and press ok.

(c) Running/executing the program:
Press Alt + R then press R OR Click Run → press R, OR Press Ctrl + F9

(d) Viewing the output:
Press Alt + F5

(e) Closing Turbo C++ IDE:
Click File → then press Quit menu Or Press Alt + X

Geany IDE
Plus One Computer Science Notes Chapter 5 Introduction to C++ Programming 2
Step 1: Take Geany Editor and type the program (source code)
Step 2: Save the file with extension .cpp
Step 3: Compile the program by Click the Compile Option
Step 4: After successful compilation, Click Build option
Step 5: Then click on Execute option

Plus One Computer Science Notes

Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving

Kerala Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving

Summary
Problem solving using computers:
It has no intelligent quotient. Hence they are slaves and human beings are the masters. It can’t take its own decisions.
They can perform tasks based upon the instructions given by the humans (programmers).

Approaches in problem solving:
Top down design:
Larger programs are divided into smaller ones and solve each tasks by performing simpler activities. This concept is known as top down design in problem solving

Bottom up design:
Here also larger programs are divided into smaller ones and the smaller ones are again subdivided until the lowest level of detail has been reached. We start solving from the lowest module onwards. This approach is called Bottom up design.

Phases in Programming:
1. Problem identification:
This is the first phase in programming. The problem must be identified then only it can be solved, for this we may have to answer some questions.

During this phase we have to identify the data, its type, quantity and formula to be used as well as what activities are involved to get the desired out put is also identified for example if you are suffering from stomach ache and consult a Doctor.

To diagnose the disease the Doctor may ask you some question regarding the diet, duration of pain, previous occurrences etc, and examine some parts of your body by using stethoscope X-ray, scanning etc.

2. Deriving the steps to obtain the solution:
There are two methods, Algorithm and flowchart, are used for this.
(a) Algorithm:
The step-by-step procedure to solve a problem is known as algorithm. It comes from the name of a famous Arab mathematician Abu Jafer Mohammed Ibn Musaa Al-Khowarizmi, The last part of his name Al-Khowarizmi was corrected to algorithm.

(b) Flowchart:
The pictorial or graphical representation of an algorithm is called flowchart.
Flow chart symbols are explained below
(i) Terminal (Oval):
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 1
It is used to indicate the beginning and ending of a problem.
(ii) Input/Output (parallelogram):
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 2
It is used to take input or print output.
(iii) Processing (Rectangle):
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 3
It is used to represent processing. That means to represent arithmetic operation such an addition, subtraction,multiplication and, etc.
(iv) Decision (Rhombus):
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 4

It is used to represent decision making. It has one entry flow and two exit flows but one exit path will be executed at a time.
(v) Flow lines (Arrows):
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 5
It is used to represent the flow of operation
(vi) Connector:
Plus One Computer Science Notes Chapter 4 Principles of Programming and Problem Solving 6

3. Coding:
The dummy codes (algorithm) or flowchart is converted into program by using a computer language such s Cobol, Pascal, C++, VB, Java, etc.

4. Translation:
The computer only knows machine language. It does not know HLL, but the human beings HLL is very easy to write programs. Therefore a translation’ is needed to convert a program written in HLL into machine code (object code).

During this step, the syntax errors of the program will be displayed. These errors are to be corrected and this process will be continued till we get “No errors” message. Then it is ready for execution.

5. Debugging:
The program errors are called ‘bugs’ and the process of detecting and correcting errors is called debugging. In general there are two types of errors syntax errors and logical errors. When the rules or syntax of the language are not followed then syntax errors occurred and it is displayed after compilation.

When the logic of a program is wrong then logical errors occurred and it is not displayed after compilation but it is displayed in the execution and testing phase.

6. Execution and Testing:
In this phase the program will be executed and give test data for testing the purpose of this is to determine whether the result produced by the program is correct or not. There is a chance of another type of error, Run time error, this may be due to inappropriate data.

7. Documentation:
It is the last phase in programming. A computerized system must be documented properly and it is an ongoing process that starts in the first phase and continues till its implementation. It is helpful for the modification of the program later.

Plus One Computer Science Notes