0% found this document useful (0 votes)
21 views

Computer Science I

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Computer Science I

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NIRMALA MEMORIAL FOUNDATION JUNIOR COLLEGE OF COMMERCE AND SCIENCE,

KANDIVALI(E)

CLASS/STREAM: F. Y. J. C. / SCIENCE ACADEMIC YEAR: 2022-23

COMPUTER SCIENCE (PAPER-I)

QUESTION BANK FOR 1ST SEMESTER EXAM

Q.1 Select the correct alternative and re-write the sentence.

1. C++ is object-oriented programming language.


i) procedure oriented ii) event driven
iii) object oriented iv) web based

2. Which of the following is a correct variable in C++?


i) VAR_1234 ii) $var_name
iii) 7VARNAME iv) 7var_name

3. Size of char data type is 1 byte.


i) 1 ii) 2
iii)4 iv) 8

4. insertion operator is used with cout.


i) insertion ii) increment
iii) extraction iv) decrement

5. float data type store decimal value.


i) int ii) char
iii) float iv) Boolean

6. Collection of characters is known as string.


i) string ii) void
iii) pointer iv) function

7. pointer variable stores memory address of another variable.


i) function ii) pointer
iii) array iv) string

8. Constant can be declared using const keyword.


i) void ii) const
iii) extern iv) return

9. Collection of similar data items is known as array.


i) function ii) pointer
iii) array iv) string
10. Reserved words in C++ are called as keywords.
i) identifier ii) variable
iii) keywords iv) constant

1. Write a C++ program to generate Fibonacci series upto 15 terms.


#include <iostream.h>
#include <Conio.h>
Void Main ( )
{
clrscr ( );
int a = 0, b = 1, c;
cout << a << “/n” << b << “/n”;
for (int n = 2; n < 15; n++)
{
c=a+b
cout << C << “/n”;
a=b
b = c;
}
getch ( );
}

2. Write a C++ program to calculate factorial of a number using while loop.


#include <iostream.h>
#include <Conio.h>
Void Main ( )
{
clrscr ( );
int n, fact = 1;
cout << “enter a number”;
cin >> n
while (n > 0)
{
fact = fact * n
n--;
}
cout << “factorial =” << fact;
getch ( );
}
3. Write a C++ program to check whether the number is positive, negative or zero.
#include <iostream.h>
#include <Conio.h>
Void Main ( )
{
clrscr ( );
int n;
cout << “enter a number”;
cin >> n;
if (n > 0)
cout << “The number is positive”;
else (n < 0)
cout << “The number is negative”;
else,
cout << “The number is zero”;
getch ( );
}

4. Write a C++ program to find greatest among three numbers.


#include <iostream.h>
#include <Conio.h>
Void Main ( )
{
clrscr ( );
int n1, n2, n3
cout << “enter three numbers”;
cin >> n1 >> n2 >> n3;
if (n1 >= n2 and n1 >= n3)
cout << n1 << “is the greatest”;
else if (n2 >= n1 and n2 >= n3)
cout << n2 << “is the greatest”;
else,
cout << n3 << “is the greatest”;
getch ( );
}
5. Write a C++ program to check whether the number is even or odd.
#include <iostream.h>
#include <Conio.h>
Void Main ( )
{
clrscr ( );
int n
cout << “enter a number”;
cin >> n;
if n%2 = 0
cout << “The number is even”;
else,
cout << “The number is odd”;
getch ( );
}

6. Write a C++ program to perform addition of two numbers using user-defined sum ()
function.
#include <iostream.h>
#include <Conio.h>
int sum (int, int)
Void Main ( )
{
clrscr ( );
int a, b;
cout << “enter two number”
cin >> a >> b
int c = Sum(a, b)
cout << “Addition =” << C;
getch ( )
}
int sum (int m, int n)
return (m + n);
}

7. Define variable. List rules to define variable name.


1. variable name must only contain alphabets, digits, and underscore.
2. A variable name must start with an alphabet or an underscore only. It cannot start with a digit.
3. No whitespace is allowed within the variable name.
4. A variable name must not be any reserved word or keyword.
8. Write a short note on operators in C++.
Operators are symbols that perform operations on variables and values. For example, + is an operator

used for addition, while - is an operator used for subtraction.

Operators in C++ can be classified into 6 types:

1. Arithmetic Operators

2. Assignment Operators

3. Relational Operators

4. Logical Operators

5. Bitwise Operators

6. Other Operators

9. Explain data types in C++.


In C++, a data type is a classification of types of data that determines the types of operations
that can be performed on the data. There are several built-in data types in C++, including:

1. Integral types: These are used to store integers. There are several integral types in
C++, including char, short, int, long, and long long.
2. Floating-point types: These are used to store real numbers. The two floating-point
types in C++ are float and double.
3. Boolean type: This is used to store a value that is either true or false. The boolean type
in C++ is bool.
4. Void type: This is a special type used to represent the absence of a value. The void
type is used in function declarations to indicate that the function does not return a
value.

10. What is array? How to initialize array? How to access array elements?
1. An array is a finite set of homogenous data elements.
2. Its elements are stored in a contiguous memory location.
3. The size of the array should be mentioned while declaring it.
4. Array elements are always counted from zero (0) onward.
5. Array elements can be accessed using the position of the element in the array.
6. The array can have one or more dimensions.
The initializer for an array is a comma-separated list of constant expressions enclosed in braces
({}). The initializer is preceded by an equal sign (=). You do not need to initialize all elements in an
array.
You can access an array element by referring to its index number

11. Define pointer. Explain pointer with the help of suitable example.
A pointer is a variable that stores the address of another variable. Unlike other variables that hold
values of a certain type, pointer holds the address of a variable. For example, an integer variable
holds (or you can say stores) an integer value, however an integer pointer holds the address of a
integer variable.

12. Define function. Explain two of each mathematical and string functions.
A function is defined as a relation between a set of inputs having one output each. In simple words, a
function is a relationship between inputs where each input is related to exactly one output. Every
function has a domain and codomain or range. A function is generally denoted by f(x) where x is the
input. The general representation of a function is y = f(x).
These functions are also classified into various types, which we will discuss here. Check Relations and
Functions lesson for more information.
An example of a simple function is f(x) = x2. In this function, the function f(x) takes the value of “x” and
then squares it. For instance, if x = 3, then f (3) = 9. A few more examples of functions are: f(x) = sin x,
f(x) = x2 + 3, f(x) = 1/x, f(x) = 2x + 3, etc.

You might also like