0% found this document useful (0 votes)
32 views5 pages

Sheet 1 Model Answer

The document contains a study sheet for a structured programming course. It includes brief answers to questions about C++ fundamentals like header files, namespaces, the main function, and data types. It also has questions about variables, operators, comments and other basic concepts to test understanding.

Uploaded by

bedoamr75
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)
32 views5 pages

Sheet 1 Model Answer

The document contains a study sheet for a structured programming course. It includes brief answers to questions about C++ fundamentals like header files, namespaces, the main function, and data types. It also has questions about variables, operators, comments and other basic concepts to test understanding.

Uploaded by

bedoamr75
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/ 5

Ministry of High Education Course Name: Structured Programming

Egyptian Russian University Course Code: CS102


Faculty of Artificial Intelligence

Sheet1
1. Answer in brief.

a. Why does the inclusion of the line "#include <iostream>" important in C++
programs that perform input or output?
Answer: The line "#include <iostream>" is important in C++ programs that perform
input or output because it tells the compiler to include the necessary service for stream
input/output. The iostream library provides functionality for reading input from the user
and displaying output on the screen.

b. What does the line "using namespace std;" indicate in a C++ program, and why
is it commonly used?
Answer: The line "using namespace std;" indicates that the program will use the
standard namespace. Namespaces are used to avoid naming conflicts in large programs.
By using the standard namespace, we can access the standard library (std) without
explicitly specifying it for each identifier. It is commonly used to simplify the code and
make it more readable.

c. What is the significance of the "int main ()" function in a C++ program?
Answer: The "int main ()" function is the entry point of a C++ program. It is where the
program execution starts. The "int" indicates that the function will return an integer
value, and "main" is the name of the function. Any code inside the curly braces of the
main function will be executed when the program runs.

d. Why is it necessary for every C++ program to have a main function?


Answer: It is necessary for every C++ program to have a main function because it
serves as the starting point for program execution. The operating system calls the main
function when the program is launched, and the program's execution begins from there.

e. What is the purpose of the "return 0;" statement in the main function of a C++
program?
Answer: The "return 0;" statement in the main function of a C++ program indicates
that the program finished successfully. It is a convention to return 0 to denote
successful execution. Other return values can indicate different error codes or statuses.

1
2. Fill in the blanks.
1. In C++, everything is __case_____ sensitive.
2. A ___statement____ is a unit of code that does something and is a basic
building block of a program.
3. An ___expression____ is a statement that has a value, such as a number, a
string, or the sum of two numbers.
4. The ___%____ operator takes the remainder of two numbers.
5. The five arithmetic operators in C++ are __+_, __-_, _*___, ___/__, and ___
%__.
6. The operator % is used to find the remainder in ___ordinary_____ division.
3. Select the appropriate option.
1. Which category of data types is the fundamental building block for
structured data types?
a) Simple data type b) Structured data type
c) Pointers d) None of the above

Answer: a) Simple data type

2. Which data type is used to represent a single text character or small


integer?
a) int b) double
c) char d) bool

Answer: c) char

3. What is the size of the "int" data type in memory?


a) 1 byte b) 2 bytes
c) 4 bytes d) 8 bytes

Answer: c) 4 bytes

4. Which data type is used to represent Boolean values (true or false)?


a) int b) double
c) bool d) char

Answer: c) bool

5. What is the range of values that can be represented by the "unsigned int"
data type?
a) -128 to 127 b) -32768 to 32767
2
c) 0 to 255 d) 0 to 4294967295
Answer: d) 0 to 4294967295

6. Which data type is used to represent doubly precise floating-point numbers?


a) int b) double
c) char d) bool

Answer: b) double

7. How many bytes of memory does the "bool" data type occupy?
a) 1 byte b) 2 bytes
c) 4 bytes d) 8 bytes

Answer: a) 1 byte

8. How many categories of simple data types are there in C++?


a) 1 b) 2
c) 3 d) 4

Answer: c) 3

9. What is a variable in programming?


a) A named location in memory b) A reserved word in C++
c) A mathematical calculation d) An input/output operation

Answer: a) A named location in memory

10. What operator is used for assignment in C++?


a) = b) +
c) * d) /

Answer: a) =

11. What is the preferred way to declare and initialize a variable in a single
statement?
a) int x b) x = 4 + 2
c) int x = 4 + 2 d) initialize (x, 4 + 2)

Answer: c) int x = 4 + 2

3
12. Which characters are allowed in variable names?
a) Letters, numbers, and underscores b) Symbols such as $ or %
c) Spaces d) Capital letters only

Answer: a) Letters, numbers, and underscores

13. What is a constant in programming?


a) A named location in memory b) A reserved word in C++
c) A value that can change during program execution
d) A value that remains fixed and cannot be changed

Answer: d) A value that remains fixed and cannot be changed

14. How are single-line comments denoted in C++?


a) // b) /* */
c) # d) //

Answer: a) //

15. How does the compiler treat comments in the code?


a) It executes the comments as part of the program.
b) It ignores everything from // to the end of the line.
c) It ignores everything between /* and */ delimiters.
d) It displays the comments as output.

Answer: c) It ignores everything between /* and */ delimiters.

4
5

You might also like