Chapter # 3 class 10

 Q#1: Use \a and \r both escape sequences in a program.

Ans:

#include <iostream>

int main()

{

 cout<<”COMPUTER\rSCIENCE”;

cout<<”COMPUTER\aSCIENCE”;

}

Q#2: How many types of comments statements are used in C++?

Ans: In C/C++ there are two types of comments:

1. Single line comment

2. Multi-line comment

Single line Comment

Represented as // double forward slash It is used to denote a single line comment.

Multi-line comment

Represented as /* any_text */ start with forward slash and asterisk (/*) and end with asterisk

and forward slash (*/).

It is used to denote multi-line comment.

Q#3: Difference between arithmetic operator and relational operator.

Ans: Arithmetic operators are used to perform mathematical operations like division, multiplication,

addition, subtraction and remainder/modulus method.

While the relational operators are used to perform comparison operations. Simply we can say, it is

used to test the relation between two values.

Q#4: Write a program in C++ and use all arithmetic assignment operators.

Ans:

#include<iostream.h>

#include<conio.h>

void main()

{

 int a=27;

 cout<<"a is "<<a<< endl;

a+=4;

cout<<"a is now "<<a<< endl;

a-=10;

cout<<"a is now "<<a<< endl;

a*=4;

cout<<"a is now "<<a<< endl;

a/=10;

cout<<"a is now "<<a<< endl;

}

Q#5: What is the difference between assignment operator and equal to operator? 

Ans: 

Assignment Operator (=) = is an Assignment Operator in C, C++ and other programming languages, It is Binary Operator which operates on two operands. = assigns the value of right side expression’s or variable’s value to the left side variable. 

Equal To Operator (==) == is an Equal To Operator in C and C++ only, It is Binary Operator which operates on two operands. == Compares value of left and right side expressions, return 1 if they are equal other wise it will return 0. 

Q#6: What is the basic difference between \n and \t? 

Ans: ‘\n’ line feed or new line. It is used to move the cursor the next line. 

for eg:-. 

cout << "Hello " << '\n'<<"world"; 

output:- Hello World 

‘\t’ is a horizontal tab. It is used for giving tab space horizontally in your output. 

for eg:- 

cout << "Hello " << '\t'<<"world"; 

output:- Hello world

Q#7: Get the output of following program: 

Ans: #include<iostream>

using namespace std; 

int main(void)

{

 int a=27;

 cout<<"a is "<<a<< endl;

 cout<<"a is now "<<a++<< endl;

 cout<<"a is now "<<a<< endl;

 cout<<"a is now "<<a<< endl;

 return 0;

}

Ans:

Out Put:

a is 27

a is now 27

a is now 28

a is now 28

10 Year Questions

Q#1: What is meant by Arithmetic assignment operator?                                                 (2023)
Ans: 
In arithmetic assignment operators, the arithmetic operator is combined with the assignment operator. The assignment operator comes to the right of an arithmetic operator. This operator is also known as Compound Assignment Operator. Example: (+=, -=, *=, /=)

 

Q#2: Differentiate between Arithmetic operators and relational operators.                   (2022)
Ans:

ARITHMETIC OPERATORS

RELATIONAL OPERATORS

The arithmetic operators perform operations which include addition, subtraction, multiplication, division, exponentiation, and modulus.

A relational operator tests or defines a kind of relation between two entities.

 

The arithmetic operators are addition “+” operator, subtraction “-” operator, multiplication “*” operator, division “/” operator, and exponentiation “^” operator.

The relational operators are greater than ">" operator, less than "<" operator, equal to "=" operator, not equal to "! =" operator, greater than equal to ">=" operator and less than equal to "<=" operator.

 

 

Q#3: Write the uses of any three escape sequences. \t, \n, \r, \b, \a                              (2022)
Ans:

Escape Sequence

Explanation with example

\t

“t” stands for Horizontal tab. It is used to shift the cursor to a couple of spaces to the right in the same line. Example: cout<<”\t”;

\n

“n” stands for new line or line feed. It inserts a new line and cursor moves the beginning of the next line. Example: cout<<”\n”;

\a

“a” means Alert or alarm. It causes a beep sound in computer. Example: cout<<”\a”;

 

Q#4: Describe comment statement. How many types of comment statements are used in C++?                                                                                                                                               (2022)
Ans:
Those statement that are ignored by the compiler are called comment statement. These statements do not execute. Through comments, the programmers give special remarks to the statement for their convenience. In C++ there are two types of comment statement.

1.      Single Line Comment

2.      Multi Line Comment

 

Q#5: Explain increment operator (++) and write the names of two ways of its usage.   (2022)
Ans:
It is used to add 1 to the value of a variable. Increment operator is represented by ++ (double plus sign). This operator can be applied only to a single variable.

The two ways to use increment operator are:

1.      Prefix Increment Operator:     You can apply the operator before the variable name. It can be written like ++a.

2.      Postfix Increment Operator:   You can apply the operator after the variable name. It can be written like a++.

 

Descriptive-Answer Question

 

Q#1: Describe any four escape sequence characters.                                                         (2023)

Ans:

Escape Sequence

Explanation with example

\t

“t” stands for Horizontal tab. It is used to shift the cursor to a couple of spaces to the right in the same line. Example: cout<<”\t”;

\n

“n” stands for new line or line feed. It inserts a new line and cursor moves the beginning of the next line. Example: cout<<”\n”;

\a

“a” means Alert or alarm. It causes a beep sound in computer. Example: cout<<”\a”;

\b

“b” stands for backspace. It moves the cursor backspace. Example: cout<<”\b”


Comments

Popular posts from this blog

Fundamentals Of Computer

Problem Solving Steps