CBSE Class 11 C ++ | Sample paper-1

{1} All questions are required.
{2} C ++ programming language

Q.1 [A] Explain the functional components of the computer? 2
There are several basic components that help the operating cycle of a computer, and these are called functional components of a computer. They are:
1) Input system
2) Memory organization
3) Output system
See: Computer functional components

[B] Write differently between application and system software. 2

Software:
1) This is software that directly allows the user to interact with the hardware components of a computer system.
2) System software can be called the main software of a computer system as it handles the bulk of the hardware operation.
3) This System Software can be further divided into:
Operating System
Language Processor

Software:
1 ) It is the main software used to carry out a specific action and task.
2) This is specialized software designed to perform simple and single tasks.
3) They are of two types:
General purpose application software
Special application software

See: Software Concepts

[C] Define a hybrid computer? 1
Hybrid computers use both analog and digital technologies to ensure the speed of an analog computer and the accuracy of a digital computer. These computers accept digital or analog signals, but extensive digital-to-analog and analog-to-digital data conversion needs to be done. Hybrid computers are used as a cost-effective tool for complex simulations.

[D] What function the operating system plays for memory management. 1
In a computer, the processor and I / O devices interact with memory. When a program needs to be executed, it is loaded into main memory before execution completes. Common memory management techniques used by the operating system are:
Partitions: Shared memory is divided into different partitions of the same size or different sizes. This helps to fit the number of programs into memory.
Virtual memory: is a method used by the operating system by which the user can load programs that are larger than the main memory of the computer.

Q.2 [ A] Record the differences between logical and syntax errors 2
Logical errors. These types of errors that provide incorrect output but do not appear to contain errors are called logical errors … These errors depend solely on the logical thinking of the programmer.
Syntax errors: Errors that occur when the rules for writing C / C ++ syntax are violated are called syntax errors. This compiler error indicates what needs to be fixed before the code can be compiled.

int val, n = 1000;

cin & gt; & gt; val;
res = n + val & gt; 1500? 100: 200;
cout & lt; & lt; res;

i) If input 1000 .: 100
II) If the input is 200 .: 200

[C] Write the equivalent C ++ 2 expressions
(1) p = 2 (l + b)
Expression: p = 2 * (l + b);

(2) z = 2 (p / q) 2
Expression: z = 2 * pow ((p / q), 2)) or 2 * p / q * p / q

(3) s = 1 / 2mv 2
Expression: 1/2 * m * v * v; or s = 1/2 * m * pow (v, 2);

(4) x = -b +? (B 2 -4ac) / 2a
Expression: x = -b + sqrt (b * b-4 * a * c) / 2 * a; or x = -b + sqrt (pow (b, 2) -4 * a * c) / 2 * a;

[D] Specify the difference between the key word and identifier. 2

Identifiers :
1) Identifiers are used as a general terminology for naming variables, functions and arrays.
2) These are user-defined names consisting of an arbitrary long sequence of letters and numbers with a letter or underscore (_) as the first character. Identifier names must be distinct in spelling and case from any keywords.
3) There are certain rules to follow when naming identifiers c:
They must begin with a letter or an underscore (_).
They should only contain letters, numbers or underscores. Other special characters are not allowed.
It shouldn`t be a keyword.
It must not contain spaces.
The length should be no more than 31 characters, since only the first 31 characters are significant.

Q.4 [A] Draw flowchart that outputs the least of the three data if not. 2

[B] Rewrite the next program after removing syntax errors. 2

# include & lt; iostream.h & gt;
Void main ()
{

const MAX = 0; // Error

int a, b;

cin & lt; & lt; a & gt; & gt; b; // Error

if (a & gt; b)

MAX = a;

for (x = 0 ; x & lt; MAX; x ++) // x undefined error.

cout & lt; & lt; x;

}

void main ()

{

const int MAX = 0;

int a, b;

cin & gt; & gt; a & gt; & gt; b;

if (a & gt; b)

MAX = a;

for ( int x = 0; x & lt; MAX; x ++) // х - undefined character

cout & lt; & lt; x;

[C] Write a program in c ++ for printing Fibonacci series : 0, 1, 1, 2, 3, 5, 8. . 3

# include & lt; iostream & gt;

using std :: cout;

void fib ( int n)

{

int a = 0, b = 1, c;

if (n & gt; = 0)

cout & lt; & lt; a & lt; & lt; "" ;

if (n & gt; = 1)

cout & lt; & lt; b & lt; & lt; "" ;

for ( int i = 2; i & lt; = n; i ++) {

c = a + b;

cout & lt; & lt; c & lt; & lt; "" ;

a = b;

b = c;

}

}

  
// Driver code

int main ()

{

int n;

cout & lt; & lt; "Enter the value of n" ;

cin & gt; & gt; n;

fib (n);

return 0;

}

[D] Write a program in

# include & lt; iostream & gt;

using namespace std;

 

int fact ( int n)

{

  if ( n == 1 || n == 0)

return 1;

return n * fact ( n - 1);

}

 

int main ()

{

int n;

cout & lt; & lt; "Enter the number" ;

cin & gt; & gt; n;

cout & lt; & lt; "factorial of n is" & lt; & lt; fact (n);

return 0;

}

Q.5 [A] Write a c ++ program to replace every space in a line with a hyphen. 2

# include & lt; iostream & gt;
# include & lt; string.h & gt;

using namespace std;

 

void replace ( char * str, int len)

{

for ( int i = 0; i & lt; len; i ++) {

if (str [i] == `` )

str [i] = `_` ;

}

cout & lt; & lt; str;

}

 

int main ()

{

char str [] = "geeks for geeks" ;

int len = strlen (str);

replace (str, len);

return 0;

}

[B] Find the total number of elements and the total size of the following array: 2
(I) Int student [20] (II) swim A [4] [5]

i) total number of items = 20
total size = 20 * 2 = 40 bytes
ii) total number of items = 4 * 5 = 20
total size = 4 * 4 * 5 = 80 bytes

[C] Rewrite the following program after removing syntax errors 2

# include & lt; iostream.h & gt;
main ()
{

int sum [2, 4];

for (i = 0 ; i & lt; 2; i ++)

for (j = 0; j & lt; = 3; i ++) {

cout & lt; & lt; sum;

}

[D] Check the output for the following program: 4

# include & lt; iostream.h & gt;
main ()
{

int a [5] = {5, 10, 15, 20, 25};

int i, j, k = 1, m;

i = ++ a [1];

j = a [2] ++;

m = a [i ++

};
cout & lt; & lt; i & lt; & lt; j & lt; & lt; k & lt; & lt; m;
}

[E] Write a c ++ program to find the sum of the rows and columns of a matrix. 3

# include & lt; iostream & gt;

using namespace std;

# define MAX 10

 

int sum ( int a [] [MAX], int n)

{

int i, j;

int sum = 0;

for (i = 0 ; i & lt; n; i ++) {

for (j = 0; j & lt; n; j ++) {

if (i == 0 || j == 0 || i == (n - 1) || j == (n - 1))

sum = sum + a [i] [j];

}

}

  cout & lt ; & lt; sum;

return 0;

}

 

int main ()

{

int a [10] [10];

int n, i, j;

cout & lt; & lt; "enter the dimension of matrix" ;

cin & gt; & gt; n;

cout & lt; & lt; "enter the elements" ;

for (i = 0 ; i & lt; n; i ++)

for (j = 0; j & lt; n; j ++)

cin & gt ; & gt; a [i] [j];

sum (a, n);

return 0;

}

[F] Give the correct array declaration for the following: — 2
(i) Declare an integer array A that can contain 30 values.
(ii) declare a two-dimensional array named MIN, 4 * 5 an integer.
(i) int A [30];
(ii) int MIN [4] [5];

Q.6 [A] What are the 3 steps using functions . 3
Three steps to use a function correctly:
i) Function declaration: the function prototype is declared so that the compiler can know about the parameters and return types
ii) Function definition: the whole body and Functionality The functions are designed and recorded inside the function block.
iii) Function call: Finally, after the function is defined and declared, it is called inside the driver / main function to perform the desired functionality.

[B] Find the output of the following program: 2

# include & lt; iostream.h & gt;

void Execute ( int & amp; x, int y = 200)

{

int temp = x + y;

x + = temp;

if (y! = 200)

cout & lt; & lt; temp & lt; & lt; x & lt; & lt; y;

}
main ()
{

int a = 50, b = 20;

Execute (a, b);

cout & lt; & lt; a & lt; & lt; b;

}

Output:

(i) a = 120
(II) B = 20

[C] Write a function in C ++ taking 2 parameters x and n of integer type with result type float to find the sum of the following series: —
1 + x / 2! + Х 2/3! + ………………… .. + x n / (n + 1)! 3

# include & lt; iostream & gt;
# include & lt; math.h & gt;

 

int fact ( int z)

{

  if ( z == 1)

return 1;

return x * fact ( x - 1);

}

 

double sum ( int x, int n)

{

double i, total = 1.0;

for (i = 1 ; i & lt; = n; i ++)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    total = total + ( pow (x, i) / fact (i + 1)); 

return total; 

}

 
// Driver code

int main ()

{

int x; 

int n; 

cout & lt; & lt;  "" enter x and n ";

  cin

  & gt; & gt ; x & gt; & gt; n printf ( "%. 2f " , sum (x, n));

  return 0;

}

<