Kerala Plus One Computer Science Chapter Wise Questions and Answers Chapter 5 Introduction to C++ Programming
Plus One Introduction to C++ Programming One Mark Questions and Answers
Question 1.
IDE means _____________
Answer:
Integrated Development Environment
Question 2.
We know that C++ is a high-level language. From the following which statement is true.
(a) C++ contains English like statements.
(b) C++ contains mnemonics
(c) C++ contains only 0 and 1
(d) None of these
Answer:
(a) C++ contains English like statements.
Question 3.
C++ is a ______ language.
(a) High level
(b) Low level
(c) Middle level
(d) None of these
Answer:
(a) High level
Question 4.
C++ was developed at ___________
(a) AT & T Bell Laboratory
(b) Sanjose Laboratory
(c) Kansas University Lab
(d) None of these
Answer:
(a) AT & T Bell Laboratory
Question 5.
C++ is a successor of ___________ language
(a) C#
(b) C
(c) java
(d) None of these
Answer:
(b) C
Question 6.
The most adopted and popular approach to write programs is __________
Answer:
Structured programming
Question 7.
From the following which uses OOP concept
(a) C
(b) C++
(c) Pascal
(d) Fortran
Answer:
(b) C++
Question 8.
______________ is the smallest individual unit
Answer:
Token
Question 9
Pick the odd one out
(a) float
(b) void
(c) break
(d) Alvis
Answer:
(d) Alvis, the others are keywords.
Question 10.
Reserved words for the compiler is ____________
(a) Literals
(b) Identifier
(c) Keywords
(d) None of these
Answer:
(c) Keywords
Question 11.
Pick an identifier from the following
(а) auto
(b) age
(c) float
(d) double
Answer:
(b) age
Question 12.
Pick the invalid identifier
(a) name
(b) Date of birth
(c) age
(d) joining time
Answer:
(b) Date of birth, because it contains space.
Question 13.
Pick the octal integer from the following
(a) 217
(b) 0 X 217
(c) 0217
(d) None of these
Answer:
(c) 0217, an octal integer precedes 0
Question 14.
Pick the hexadecimal integer from the following
(a) 217
(b) 0 × 217
(c) 0217
(d) None of these
Answer:
(b) 0 × 217, a hexadecimal integer precedes 0×
Question 15.
From the following pick a character constant
(a) ‘A’
(b) ‘ALL’
(c) ‘AIM’
(d) None of these
Answer:
(a) ‘A’, a character enclosed between single quote
Question 16.
Non graphic symbol can be represented by using ___________
Answer:
Escape Sequence
Question 17.
Manish wants to write a program to produce a beep sound. Which escape sequence is used to get an alert (sound)
(a) \a
(b) \d
(c) Vs
(d) None of these
Answer:
(a) \a.
Question 18.
Ajo wants to print a matter in a new line. Which escape sequence is used for this?
(a) \a
(b) \n
(c) \s
(d) None of these
Answer:
(b) \n
Question 19.
To represent null character is used ______
(a) \n
(b) \0
(c) \f
(d) As
Answer:
(b) \0
Question 20.
State True/ False a string is automatically appended by a null character.
Answer:
True
Question 21.
From the following pick a string constant
(a) ‘a’
(b) “abc”
(c) ‘abc’
(d) None of these
Answer:
(b) “abc”, a character constant must be enclosed between double quotes.
Question 22.
C++ was developed by __________
(a) Bjarne Stroustrup
(b) James Gosling
(c) Pascal
(d) None of these
Answer:
(a) Bjarne stroustrup
Question 23.
From the following which is not a character constant.
(а) ‘c’
(b) ‘e’
(c) ‘d’
(d) “c”
Answer:
(d) “c”, It is a string constant the others are character constant.
Question 24.
From the following which is a valid declaration.
(a) int 91;
(b) int x;
(c) int 9x;
(d) int “x”;
Answer:
(b) int x;
Question 25.
Symbols used to perform an operation is called ____________
(a) Operand
(b) Operator
(c) Variable
(d) None of these
Answer:
(b) Operator
Question 26.
Consider the following
C = A + B. Here A and B are called
(a) Operand
(b) Operator
(c) Variable
(d) None of these,
Answer:
(b) Operand
Question 27.
The execution of a program starts at ________ function
Answer:
main()
Question 28.
The execution of a program ends with ________ function
Answer:
main()
Question 29.
______ is used to write single line comment
(a) //
(b) /*
(c) */
(d) None of these
Answer:
(a) //
Question 30.
const k = 100 means
(a) const float k = 100
(b) const double k = 100
(c) const int k = 100
(d) const char k = 100
Answer:
(c) const int k = 100
Question 31.
Each and every statement in C++ must be end with ________
(а) Semicolon
(b) Colon
(c) full stop
(d) None of these
Answer:
(a) Semicolon
Question 32.
From the following select the input operator
(а) >>
(b) <<
(c) >
(d) <
Answer:
(a) >>
Question 33.
From the following select the output operator
(a) >>
(b) <<
(c) >
(d) <
Answer:
(b) <<
Question 34.
From the following which is known as a string terminator.
(а) ‘\0’
(b) ‘\a’
(c) ‘As’
(d) ‘\t’
Answer:
(a) ‘\0’
Question 35.
Adeline wrote a C++ program namely sum.cpp and she compiled the program successfully with no error. Some files are generated. From the following which file is a must to run the program
(a) sum.exe
(b) sum.obj
(c) sum.vbp
(d) sum.htm
Answer:
(a) sum.exe
Question 36.
Adeline wrote a C++ program namely sum.cpp and she compiled the program successfully with no error. Some files are generated namely sum.obj and sum.exe. From this which file is not needed to run the program
Answer:
sum.obj is not needed and can be deleted.
Question 37.
From the following which is ignored by the compiler
(a) statement
(b) comments
(c) loops
(d) None of these
Answer:
(b) comments
Question 38.
To write a C++ program, from the following which statement is a must
(a) sum()
(b) main()
(c) #include<iostream>
(d) #include<iomanip>
Answer:
(b) main(). A C++ program must contains at least one main() function
Question 39.
State True / False
Comment statements are ignored by the compiler
Answer:
True
Question 40.
More than one input/output operator in a single statement is called _______
Answer:
Cascading of I/O operator
Question 41.
Is 0X85B a valid integer constant in C++? If yes why?
Answer:
Yes. It is a hexadecimal number.
Plus One Introduction to C++ Programming Two Mark Questions and Answers
Question 1.
Mr. Dixon declared a variable as follows
int 9age. Is it a valid identifier. If not briefly explain. the rules for naming an identifier.
Answer:
It is not a valid identifier because it violates the rule
The rules for naming an identifier is as follows:
- It must be start with a letter(alphabet)
- Under score can be considered as a letter
- White spaces and special characters cannot be used.
- Key words cannot be considered as an identifier
Question 2.
How many bytes used to store ‘\a’.
Answer:
To store ‘\a’ one byte is used because it is an escape sequence. An escape sequence is treated as one character. To store one character one byte is used.
Question 3.
How many bytes used to store “\abc”.
Answer:
A string is automatically appended by a null character.
- Here one byte for \a (escape sequence).
- One byte for character b.
- One byte for character c.
- And one byte for null character.
- So a total of 4 bytes needed to store this string.
Question 4.
How many bytes used to store “abc”.
Answer:
A string is automatically appended by a null character.
- Here one byte for a.
- One byte for character b.
- One byte for character c.
- And one byte for null character.
- So a total of 4 bytes needed to store this string.
Question 5.
Consider the following code
int main()
{
cout<<“welcome to C++”;
}
After you compile this program there is an error called prototype error. Why it is happened? Explain.
Answer:
Here we used the output operator cout<<. It is used to display a message “welcome to C++” to use this operator the corresponding header file <iostream> must be included. We didn’t included the header file hence the error.
Question 6.
In C++ the size of the string “book” is 5 and that of “book\n” is 6. Check the validity of the above statement. Justify your answer.
Answer:
A string is automatically added by a null character(\0). The null character is treated as one character. So the size of string “book” is 5. Similarly, a null character (\0) is also added to “book\n”. \n and \0 is treated as single characters. Hence the size of the string “book\n” is 6.
Question 7.
Pick the odd man out. Justify
TOTSAL, TOT_SAL, totsal5, Tot5_sal, SALTOT, tot.sal
Answer:
tot.sal. Because it contains a special character dot(.). An identifier cannot contain a special character. So it is not an identifier. The remaining satisfies the rules of naming identifier. So they are valid identifiers.
Question 8.
Write a C++ statement to print the following sentence. Justify.
“\ is a special character”
answer:
cout<<“\\ is a special character”
\\ is treated as an escape sequence.
Question 9.
A student type a C++ program and saves it in his personal folder as Sample.cpp. After getting the output of the program, he checks the folder and finds three files namely Sample.cpp, Sample.obj and Sample.exe. Write the reasons for the generation of the two files in the folder.
Answer:
After the compilation of the program sample.cpp, the operating system creates two files if there is no error. The files are one object file (sample.obj) and one executable file(sample.exe). Now the source file(sample.cpp) and object file(sample.obj) are not needed and can be deleted. To run the program sample.exe is only needed.
Question 10.
Mention the purpose of tokens in C++. Write names of any four tokens in C++. (2)
Answer:
Token: It is the smallest individual units similar to a word in English or Malayalam language. C++ has 5 tokens.
- Keywords
- Identifier
- Literals (Constants)
- Punctuators
- Operators
Question 11.
The following are some invalid identifiers. Specify its reason.
- Sum of digits
- 1 year
- First jan
- For
Answer:
- Sum of digits → space not allowed hence it is invalid
- 1 year → First character must be an alphabet hence it is invalid
- First.jan → special characters such as dot (.) not allowed hence it is invalid.
- For → It is valid. That is it is not the keyword for
Question 12.
Some of the literals in C++ are given below. How do they differ?(5, ‘5’, 5.0, “5”)
Answer:
- 5 – integer literal
- ‘5’ – Character literal
- 5.0 – floating point literal
- “5”- string literal
Question 13.
Identify the invalid literals from the following and write reason for each:
- 2E3.5
- “9”
- ‘hello’
- 55450 (2)
Answer:
1. 2E3.5 → The mantissa part (3.5) will not be a floating point number. Hence it is invalid
3. ‘hello’ → It is a string hence it must be enclosed in double quotes instead of single quotes. It is invalid.
Question 14.
Which one of the following is a user defined name?
(a) Keyword
(b) Identifier
(c) Escape sequences
(d) All of these
Answer:
(b) Identifier
Question 15.
Identify whether the following are valid identifiers or not? If not give the reason.
- Break
- Simple.interest (2)
Answer:
- Break – It is valid( break is the keyword, not Break);
- Simple.interest – It is not valid, because dot(.) is used.
Question 16.
Identify the invalid literals from the following and write a reason for each:
- 2E3.5
- “9”
- ‘hello’
- 55450 (2)
Answer:
1. Invalid, because exponent part should not be a floating point number
2. valid
Plus One Introduction to C++ Programming Three Mark Questions and Answers
Question 1.
Rose wants to print as follows
\n is used for New Line. Write down the C++ statement for the same.
Answer:
#include<iostream>
using namespace std;
int main()
{
cout<<“\\n is used for New Line”;
}
Question 2.
Alvis wants to give some space using escape sequence as follows
Welcome to C++. Write down the C++ statement for the same
Answer:
#include<iostream>
using namespace std;
int main()
{
cout<<“Welcome to \t C++”;
}
Question 3.
We know that the value of pi = 3.14157, a constant (literal). What is a. constant? Explain it.
Answer:
A constant or a literal is a data item its value doe not change during execution.
1. 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 0 × 100, 0x1 A, etc
2. 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
3. Character literal:
A valid C++ character enclosed in single
Question 4.
Write a program to print the message “TOBACCO CAUSES CANCER” on screen.
Answer:
#include<iostream>
using namespace std;
int main()
{
cout<<” TOBACCO CAUSES CANCER”;
}
Question 5.
You are supplied with a list of tokens in C++ program, Classify and Categorise them under proper headings.
Explain each category with its features. tot_mark, age, M5, break, (), int, _pay, ;, cin.
Answer:
Question 6.
Write a program to print the message “SMOKING IS INJURIOUS TO HEALTH” on screen.
Answer:
#include<iostream>
using namespace std;
int mainO
{
cout<<” SMOKING IS INJURIOUS TO HEALTH”;
}
Plus One Introduction to C++ Programming Five Mark Questions and Answers
Question 1.
Consider the following code
The new line character is \n. The output of the following code does not contain the \n. Why it is happened? Explain.
Answer:
\n is a character constant and it is also known as escape sequence. This is used to represent the non graphic symbols such as carriage return key(enter key), tab key, backspace, space bar, etc. It consists of a backslash symbol and one more characters.
Question 2.
You are about to study the fundamentals of C++ programming Language. Do a comparative study of the basics of the new language with that of a formal language like English or Malayalam to familiarize C++? Provide sufficient explanations for the compared items in C++ Language.
Answer:
1. 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.
2. Token:
It is the smallest individual units similar to a word in English or Malayalam language. C++ has 5 tokens
- 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 - Identifier: These are user defined words. Eg: variable name, function name, class name, object name, etc…
- Literals (Constants): Its value does not change during execution
eg: In maths % = 3.14157 and boiling point of water is 100. - Punctuators: In English or Malayalam language punctuation mark are used to increase the readability but here it is used to separate the tokens.
eg:{,}, (,), …….. - Operators: These are symbols used to perform an operation(Arithmetic, relational, logical, etc…).