0% found this document useful (0 votes)
7 views24 pages

To DTi N

Uploaded by

aqkss188
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

To DTi N

Uploaded by

aqkss188
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

GRADE X

Chapter #01: Problem Solving And Algorithm Designing

Short Question
1.Why is there need of index in an array?
Indexing in arrays provides a way to access specific elements efficiently. Instead of
iterating through the entire array, you can directly locate an element using its
index. This is especially useful when dealing with large datasets or when you need
to perform frequent element retrieval operations.

2.Define Algorithm. Write its three advantages?


An algorithm is a step-by-step procedure for solving a problem. It's a set of
instructions that, when followed, will produce a desired output. There are two
common methods to represent algorithm designs; pseudocode and flowcharts.

Advantages of algorithms:

1. Efficiency: Algorithms are designed to be efficient, often providing optimal


solutions or near-optimal solutions to problems.
2. Clarity: Well-written algorithms are clear and easy to understand, making it
easier to implement and maintain code.
3. Reusability: Algorithms can be reused in different contexts, saving time and
effort in problem-solving.

3.What are good qualities of an algorithm?

Ans. QUALITIES OF A GOOD ALGORITHM:


Good qualities of an algorithm include:
 Efficiency: Solves problems quickly and uses minimal resources.
 Correctness: Produces the correct output for all valid inputs.
 Clarity: Easy to understand and follow.
 Generalizability: Applicable to a wide range of inputs.
 Robustness: Handles unexpected inputs or errors gracefully.
 Scalability: Handles increasing input sizes efficiently.

4.What are the differences between algorithm and flowchart?

5.What is the difference between tree and graph data structure?

Graphs are collections of linked


Tree data structures are hierarchical, non-linear
1. nodes in non-linear network
collections of linked nodes.
models.

A good example of hierarchical data is a family


A good example of a network
2. tree where each level of depth would represent a
graph is a of roads within a city.
hierarchy such as grandparents, parents etc.
Graph data structures do not have
The first node of a tree is the root node.
3. root nodes and there are no
Everything else flows hierarchical from this node.
parent-child relationships.

6.What is the difference between queue and stack data structure?

Descriptive Question

1.Define problem solving. Explain its step

Problem-solving is the process of identifying a problem, gathering information,


developing solutions, and implementing the most effective solution. It involves a
systematic approach to overcome challenges and achieve desired outcomes.

Steps in problem-solving:
1. Identify the problem: Clearly define the issue or challenge you are facing.
2. Gather information: Collect relevant data, facts, and perspectives to
understand the problem better.
3. Generate solutions: Brainstorm various possible solutions or approaches to
address the problem.
4. Evaluate solutions: Assess the pros and cons of each solution, considering
factors like feasibility, effectiveness, and potential consequences.
5. Select the best solution: Choose the solution that is most likely to achieve
the desired outcome and address the problem effectively.
6. Implement the solution: Put the chosen solution into action and monitor
its progress.
7. Evaluate the results: Assess the effectiveness of the solution and make
adjustments as needed.

2.Define flowchart and explain its five symbols.

A flowchart is a graphical representation of a sequence of operations or steps in


a process. It uses various symbols connected by arrows to illustrate the flow of
control from one step to the next.

Five common flowchart symbols and their meanings:

1. Start/End: Represents the beginning or end of a process. It is usually a


rounded rectangle.

2. Process: Represents a step or activity in the process. It is typically a


rectangle.
3. Decision: Represents a point in the process where a decision is made. It is a
diamond shape.

4. Input/Output: Represents the input or output of data. It is a parallelogram.

5. Flowline: Represents the direction of flow between steps. It is an arrow.

Define data structure. Explain linear data structure and its types.
A data structure is a specialized way of organizing and storing data in a
computer's memory so that it can be accessed and modified efficiently. It
provides a blueprint for how data elements are related to each other and how
they can be accessed and manipulated.

Linear Data Structures

Linear data structures are those where data elements are arranged in a sequential
manner, one after the other. This means that each element has a unique position
or index within the structure.

Types of Linear Data Structures:

1. Arrays:
o A collection of elements of the same data type, stored in contiguous
memory locations.
o Elements are accessed using their index.
o Can be fixed-size or dynamic (can change size during execution).
o Examples: integer array, character array.
2. Linked Lists:
o A collection of elements (nodes) connected by pointers.
o Each node typically contains a data element and a pointer to the next
node.
o Can be singly linked, doubly linked, or circularly linked.
o Dynamic in nature, allowing for efficient insertions and deletions.
3. Stacks:
o A LIFO (Last-In-First-Out) data structure.
o Elements are added and removed from the top (the most recently
added element).
o Operations: push (add), pop (remove), peek (view the top element).
o Used for: function calls, expression evaluation, undo/redo
operations.
4. Queues:
o A FIFO (First-In-First-Out) data structure.
o Elements are added to the rear and removed from the front.
o Operations: enqueue (add), dequeue (remove).
o Used for: task scheduling, breadth-first search.
Chapter #02: BASICS OF PROGRAMMING IN C++

Short Question
1.Define Computer Program?
A computer program is like a set of instructions that tells a computer what to do.
It's like a recipe for a cake, where the ingredients and steps are the instructions.
The computer follows these instructions to perform a specific task, such as
playing a game, doing calculations, or creating art.

2.write down the rules of naming variable in c++?


rules for naming variables in C++:
 Start with a letter: The first character must be a letter (a-z, A-Z) or an
underscore (_).
 Use letters, numbers, and underscores: You can use letters, numbers, and
underscores for the rest of the name.
 No spaces: There can't be any spaces in the name.
 Avoid keywords: Don't use keywords (like "int", "float", "if", "else") as
variable names.
 Be descriptive: Choose names that clearly indicate what the variable
represents. For example, "age" is better than "x".

3.Define errors and its types?


Errors are mistakes or problems that happen in a computer program. They can
cause the program to behave unexpectedly or stop working altogether.
 Syntax errors: These are mistakes in the structure or grammar of the code, like
forgetting a semicolon or mismatching parentheses.
 Runtime errors: These occur when the code runs but encounters a problem,
like trying to divide by zero or accessing an array element that doesn't exist.
 Logical errors: These are mistakes in the logic or design of the code, resulting
in incorrect output or behavior.

4.What are strings in C++?

Strings in C++ are sequences of characters, like words or sentences. They're


used to store and manipulate text data. Think of them as a container that
holds a series of letters, numbers, symbols, or even spaces. You can use strings
to display messages, read input from the user, or perform various text-related
operations.

5.Define the Following :

Reserved words in C++ are special keywords that have predefined meanings and
cannot be used as variable names. They are essential for the structure and
functionality of the language.

 Data types: int, float, double, char, bool


 Control flow: if, else, for, while, do, switch, case, break, continue
 Operators: new, delete, size of, & (address of), * (dereference)
 Modifiers: public, private, protected
 Other: namespace, using, return, void

These words have specific purposes and cannot be used for other purposes within
your code. They are the building blocks of C++ and help you write well-structured
and functional programs.

Data types in C++ are like labels that tell the computer what kind of information a
variable hold. They determine how the data is stored and what operations can be
performed on it. Some common data types include:

 int: Used for whole numbers (e.g., 1, 2, 3, -4)


 float: Used for decimal numbers (e.g., 3.14, 2.5)
 double: Used for larger decimal numbers (e.g., 12345.6789)
 char: Used for single characters (e.g., 'a', 'B', '!')
 bool: Used for true or false values (e.g., true, false)

6.Difference between declaring and initialize variable?

Declaring Variable Initialize variable


Declaring a variable is like creating a Initializing a variable is like putting
container or a box with a specific label. something into the container or box. It
It tells the computer that you'll be assigns an initial value to the variable.
using a variable with a particular name For example, int age = 25; both
and data type. For example, int age; declares and initializes the age variable
declares an integer variable named with the value 25.
age.
Creates a variable with a specific name Assigns an initial value to a declared
and data type. variable.
Reserves memory space for the Can be done at declaration or later in
variable. the code.
Does not assign a value. Ensures that the variable has a
meaningful value before it's used.

Descriptive Question

1.Define translators? Explain all its types

Translators are software tools that convert human-readable code into a language
that computers can understand. They bridge the gap between programmers and
machines.

There are three main types of translators:


1. Assemblers: These translators convert assembly language (a low-level
language) into machine code. Assembly language is closer to machine code
than high-level languages, but it's still more readable.
2. Compilers: These translators convert high-level languages (like C++, Java,
Python) into machine code. They break down the high-level code into
smaller steps and then translate each step into machine code.
3. Interpreters: These translators execute high-level code directly, line by line.
Instead of creating a complete machine code program, they interpret each
line and execute it immediately. This can make the development process
faster, but it can also be slower at runtime compared to compiled
languages.

2.Write short note of high-level language and low-level language?

High-level languages are like human languages that computers can understand.
They use words and phrases that are easy for people to read and write, making
programming more accessible. Unlike low-level languages, which are closer to
machine code, high-level languages abstract away the complexities of hardware.
This makes it easier for programmers to focus on solving problems without
worrying about the underlying details of how the computer works.

Low-level languages are like a foreign language that computers can understand
directly. They are closer to machine code, which is the language that computers
can execute. Unlike high-level languages, which use English-like keywords, low-
level languages use a more abstract syntax that is specific to the hardware of a
particular computer. This gives programmers more control over the hardware but
also makes it more difficult to learn and use.

3.Define IDE and write its components?


An IDE (Integrated Development Environment) is a software application that
helps programmers write, test, and debug code more efficiently. It's like a
toolbox for programmers, providing a variety of tools in one place.

Here are some of the key components of an IDE:

Code editor: This is where you write your code. It often has features like syntax
highlighting, auto-completion, and code formatting to make programming
easier.

Compiler or interpreter: This tool translates your code into a language that the
computer can understand.

Debugger: This helps you find and fix errors in your code. It allows you to step
through your code line by line and examine the values of variables.

Build automation: This helps you automate the process of building your
software, which involves compiling, linking, and packaging your code.

Version control integration: This allows you to track changes to your code over
time and collaborate with other programmers.Project management tools: These
help you organize your projects and keep track of tasks and deadlines.
Chapter #03: INPUT/OUTPUT HANDLING IN C++

Short Question
1. Write down the syntax and purpose of the following:

Cin

cin in C++ is like a way for your computer program to ask the user for
information. It's like a question mark that waits for the user to type something.

Syntax
cin >> variable;

cin: This is the keyword that tells the computer to expect input from the user.
>>: This is the extraction operator. It takes the input from the user and puts it
into the variable.
variable: This is a name you give to the place where the input will be stored.

Cout

cout in C++ is like a way for your computer program to talk to you. It's like a
speaker that says something on the screen.

Syntax
cin >> variable;

cout: This is the keyword that tells the computer to display something on the
screen.
<<: This is the insertion operator. It takes the expression and puts it into the
cout stream, which means it displays it on the screen.
expression: This is anything you want to display, like a number, word, or even
a sentence.

2. Define comments in C++. Also define its types.


Comments in C++ are lines of text that are ignored by the compiler. They are used
to explain code, make it more readable, and document how it works.

There are two main types of comments in C++:


Single-line comments: These comments start with two forward slashes (//) and
continue until the end of the line. For example:

// This is a single-line comment


int x = 5;

Multi-line comments: These comments start with a slash-asterisk (/) and end
with an asterisk-slash (/). They can span multiple lines. For example:

/* This is a multi-line comment.


It can span multiple lines. */
int y = 10;

3. What is statement terminator?


Ans: STATEMENT TERMINATOR (;):
In C++, statement terminator used to end the statement. Statements are
terminated with semicolon (;) symbol. Every statement in C++ must be
terminated otherwise an error message will occur.

4. What are operators? Write down the name of operators used in C++.
Ans: OPERATORS IN C++:
Operators are the symbols which tell the computer to execute certain
mathematical or logical operations. A mathematical or logical expression is
generally formed with the help of an operator. C++ Programming offers a
number of operators which are classified into the following categories.

1. Arithmetic Operators
2. Increment Operators
3. Decrement Operators
4. Relational Operators
5. Logical/Boolean Operators
6. Assignment Operators
7. Arithmetic Assignment Operators
5. Define escape sequences,write purpose each of them.

Escape Sequences
In computer programming, escape sequences are special character combinations
used to represent characters that are difficult or impossible to represent directly.
These sequences typically start with a backslash () followed by one or more
characters.

Escape
Explanation with Example
Sequence
Newline. Position the cursor at the beginning of the next
\n line.
Example: cout << "\n";
Horizontal tab. It move the cursor to the next tab stop.
\t
Example: cout << "\t";
Backslash. Insert a backslash character in a string.
\\
Example: cout << "\\";
Alert. Produces a beep sound or visible alert.
\a
Example: cout << "\a";
Backspace. It moves the cursor backspace.
\b
Example: cout << "\b";
Carriage Return. Moves the cursor to the beginning of the
\r
current line. Example: cout << "\r";
Single Quotation. It is used to print apostrophe sign (').
\'
Example: cout << "\'";
Double Quotation. It is used to print quotation mark (").
\"
Example: cout << "\" ";
Descriptive Question

Define operators and its types?

What is Operators in C++ ?


Operators are symbols or keywords used to perform specific operations on
operands (data values) in C++. They are the building blocks of expressions and
control the flow of program execution.
Types of Operators in C++
C++ offers a diverse range of operators to handle various operations:
1. Arithmetic Operators:
o Addition (+): Adds two operands.
o Subtraction (-): Subtracts the second operand from the first.
o Multiplication (*): Multiplies two operands.
o Division (/): Divides the first operand by the second.
o Modulo (%): Returns the remainder of the division.
C++

int a = 5, b = 3;
int result = a + b; // 8
result = a - b; // 2
result = a * b; // 15

2. Relational Operators:
o Equal to (==): Checks if two operands are equal.
o Not equal to (!=): Checks if two operands are not equal.
o Greater than (>): Checks if the first operand is greater than the
second.
o Less than (<): Checks if the first operand is less than the second.
o Greater than or equal to (>=): Checks if the first operand is greater
than or equal to the second.
o Less than or equal to (<=): Checks if the first operand is less than or
equal to the second.
C++

int x = 10, y = 7;
bool is_equal = x == y; // false

3. Logical Operators:
o Logical AND (&&): Returns true if both operands are true.
o Logical OR (||): Returns true if at least one operand is true.
o Logical NOT (!): Reverses the logical value of an operand.
C++

bool condition1 = true, condition2 = false;


bool and_result = condition1 && condition2; // false

Use code with caution.

4. Bitwise Operators:
o Bitwise AND (&): Performs bitwise AND on corresponding bits of two
operands.
o Bitwise OR (|): Performs bitwise OR on corresponding bits of two
operands.
o Bitwise XOR (^): Performs bitwise XOR on corresponding bits of two
operands.
o Bitwise NOT (~): Inverts all bits of an operand.
o Left shift (<<): Shifts bits of an operand to the left.
o Right shift (>>): Shifts bits of an operand to the right.
C++

int num1 = 10, num2 = 15;


int and_result = num1 & num2; // 2

5. Assignment Operators:
o Assignment (=): Assigns a value to a variable.
o Addition assignment (+=): Adds a value to a variable and assigns the
result.
o Subtraction assignment (-=): Subtracts a value from a variable and
assigns the result.
o *Multiplication assignment (=): Multiplies a value by a variable and
assigns the result.
o Division assignment (/=): Divides a variable by a value and assigns
the result.
o Modulo assignment (%=): Calculates the modulo of a variable by a
value and assigns the result.
o Left shift assignment (<<=): Performs left shift on a variable and
assigns the result.
o Right shift assignment (>>=): Performs right shift on a variable and
assigns the result.
o Bitwise AND assignment &=): Performs bitwise AND on a variable
and a value, assigns the result.
o Bitwise OR assignment (|=): Performs bitwise OR on a variable and a
value, assigns the result.
o Bitwise XOR assignment (^=): Performs bitwise XOR on a variable
and a value, assigns the result.
C++

int x = 5;
x += 3; // x becomes 8
x -= 2; // x becomes 6

6. Conditional Operator (?:):


o Evaluates a condition and returns one of two values based on the
result.
C++

int a = 10, b = 20;


int max = (a > b) ? a : b; // max becomes 20

7. Increment/Decrement Operators:
o Pre-increment (++x): Increments the operand before using its value.
o Post-increment (x++): Increments the operand after using its value.
o Pre-decrement (--x): Decrements the operand before using its value.
o Post-decrement (x--): Decrements the operand after using its value.

Chapter #04: CONTROL STRUCTURE C++

Short Question

1.Explain the purpose of Default in C++?


Default in C++ is a keyword used to initialize variables to their default values. This
means that if you don't explicitly assign a value to a variable when you declare it,
it will automatically be given a default value based on its data type.

2.What are control structures?


Ans. CONTROL STRUCTURE / STATEMENTS:
Control structures control the flow of execution in a program or function. Control
structure are used to repeat any block of code, transfer control to specific block of
code and make a choice by selection. There are three basic control structures in
C++ programming.

1. Selection / Decision making Control Structure


2. Loops / Iteration Control Structure
3. Jumps

3.Write down the function of for loop?

The for loop in C++ is a control flow statement used to execute a block of code
repeatedly. It's particularly useful for iterating over a sequence of values or
performing a task a specific number of times.

Function
for (initialization; condition; increment/decrement)
{
statement(s);
}

4.Write down the syntax and the purpose of the following:

break
The break statement allows you to exit a loop or a switch statement from any
point within its body, bypassing its normal termination expression. It can be used
within any C++ structure.

If-else
If-else in C++ are used to make decisions in your code. They allow you to execute
different blocks of code based on whether a certain condition is true or false.

Return
The return statement returns the flow of the execution to the function from
where it is called. This statement does not mandatory need any conditional
statements. As soon as the statement is executed the flow of the program stops
immediately and return the control from where it was called.

Exit
The exit function, declared in <stdlib.h>, terminates a C++ program. The value
supplied as argument to exit is returned to the operating system as the program's
return code or exit code.

Continue
The continue statement is just the opposite of the break statement. Continue
forces the next iteration of the loop to take place, skipping the remaining
statements of its body.

Goto

In C++ programming, the goto statement is used for altering the normal sequence
of program execution by transferring control to some other parts of the program.

5.What is the purpose of jump statements in c++ ?


These statements change the normal execution of program and jumps over the
specific part of program.
Following are the jumps statements used in C++.

1. break
2. continue
3. goto
4. return
5. exit()

6.Write down the differences between for, while and do-while loop.
Ans: DIFFERENCES BETWEEN for, while AND do-while LOOP:
S.NO. for loop while loop do-while loop
It is post-test loop because
It is pre-test loop because It is pre-test loop because
condition is tested at the end of
1. condition is tested at the condition is tested at the
loop which executes loop at
start of loop. start of loop.
least once.
It is known as entry It is known as entry It is known as exit controlled
2.
controlled loop. controlled loop. loop.
If the condition is not true If the condition is not true Even if the condition is not true
3. first time then control will first time then control will for the first the control will
never enter in a loop. never enter in a loop. never enter in a loop.
There is no semicolon; There is no semicolon; There is a semicolon; after the
4. after the condition in the after the condition in the condition in the syntax of the
syntax of the for loop. syntax of the while loop. do-while loop.

7.What are loops or iteration and define its types?


Ans: LOOP / ITERATION CONTROL STRUCTURE:
Iteration or loop in computer programming, is a process wherein a set of
instructions or structures are repeated in a sequence a specified, number of times
until a condition is true. When the set of instructions is executed again, it is called
an iteration. A loop statement allow us to execute a statement or a group of
statements multiple times. C++ provides the following types of loops to handle
looping requirements.

1. for loop
2. while loop
3. do-while loop

Descriptive Question
Write a program to input a number and find out it is even/odd and draw its flow
chart.

#include <iostream>
using namespace std;
int main () {
int num; cout << "Enter an integer: ";
cin >> num;
if (num % 2 == 0)
{
cout << num << " is even.";
}
else
{
cout << num << " is odd.";

}
return 0;
}

Write a program to calculate sum of any 10 numbers and draw its


flowchart.

#include <iostream>

using namespace std;

int main() {
int num, sum = 0;
for (int i = 1; i <= 10; i++) {
cout << "Enter number " << i << ": ";
cin >> num;
sum += num;
}
cout << "Sum of the 10 numbers is: " << sum << endl;
return 0;
}

write a program to generate multiple table and draw its flowchart.


#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
for (int i = 1; i <= num; i++) {
cout << "Table of " << i << endl;
for (int j = 1; j <= 10; j++) {
cout << i << " x " << j << " = " << i * j ;
}
cout;
}
return 0;}

You might also like