A Quick Look at C++

A simple and basic C++ code example. Explore your logical understanding of programming wither you are a beginner or it is your first C++ encounter.
👁 274
statistics
calculate
Questions #: 18
Time: 15 minutes
Pass Score: 80.0%
Style
Mode

Read through this program and answer the following questions

1  //**************************************************************
2 // Given the length and width of a rectangle, this C++ program
3 // computes and outputs the perimeter and area of the rectangle.
4 //**************************************************************

5
6 #include <iostream>
7 using namespace std;
8
9 int main()
10 {
11 double length;
12 double width;
13 double area;
14 double perimeter;
15
16 cout << "Program to compute and output the perimeter and " << "area of a rectangle." << endl;
17
19 length = 6.0;
20 width = 4.0;
21 perimeter = 2 * (length + width);
22 area = length * width;
23 cout << "Length = " << length << endl;
24 cout << "Width = " << width << endl;
25 cout << "Perimeter = " << perimeter << endl;
26 cout << "Area = " << area << endl;
27 return 0;
28 }

 

In general, this progrm

POINTS (1)

Correct Answer

Explanation

Sample Run: (When you compile and execute this program, the following five lines are displayed on the screen)

Program to compute and output the perimeter and area of a rectangle.
Length = 6
Width = 4
Perimeter = 20
Area = 24
POINTS (1)

Correct Answer

Explanation

The output of the program is generated by executing the following statements

cout << "Program to compute and output the perimeter and " <<  "area of a rectangle." << endl;
cout << "Length = " << length << endl;
cout << "Width = " << width << endl;
cout << "Perimeter = " << perimeter << endl;
cout << "Area = " << area << endl;
POINTS (1)

Correct Answer

Explanation

Explain how this happens

cout << "Program to compute and output the perimeter and " <<  "area of a rectangle."  << endl;

This is an example of a C++ (1) transparent statement. It causes the computer to evaluate the (2) transparent after the pair of symbols << and display the (3) transparent on the screen

drag and drop the selected option to the right place
output
result
expression
POINTS (1)

Correct Answer

Explanation

Arithmetic expression or a string?

length + width

is an example of 

POINTS (1)

Correct Answer

Explanation

"Program to compute and output the perimeter and " is an example of a string

POINTS (1)

Correct Answer

Explanation

endl

POINTS (1)

Correct Answer

Explanation

cout << "Length = " << length << endl;

What does the second length evaluate to?

(write a whole number without decimal points)

Missing
POINTS (1)

Correct Answer

Explanation

There is no way to output length value as 6.0?

POINTS (1)

Correct Answer

Explanation

return 0;

returns zero to the program itself which continues running

POINTS (1)

Correct Answer

Explanation

Main function

A C++ program can execute without a main function

POINTS (1)

Correct Answer

Explanation

Anything comes after // is not executable

POINTS (1)

Correct Answer

Explanation

#include <iostream>

#include <iostream>

allows us to use the (predefined object) cout to generate output and the (manipulator) endl.

POINTS (1)

Correct Answer

Explanation

using namespace std;

using namespace std;

This statement is useless.  You can remove it and the program still compiles.

POINTS (1)

Correct Answer

Explanation

int main()

int main()

This is the (1) transparent of the function main. The next line consists of a (2) transparent . This marks the beginning of the (body) of the function main. The (3) transparent (at the last line of the program) matches this (4) transparent and marks the end of the body of the function main.

drag and drop the selected option to the right place
heading
right brace
left brace
POINTS (1)

Correct Answer

Explanation

Stream insertion operator

POINTS (1)

Correct Answer

Explanation

Various parts of a C++ program

Match certain program sections

  • (1) transparent lines from 1 to 4
  • (2) transparent lines from 11 to 14
  • (3) transparent lines from 19 to 22
  • (4) transparent lines from 23 to 26
drag and drop the selected option to the right place
Assignment statements
Variable declarations
Comments
Output statements
POINTS (1)

Correct Answer

Explanation

So length, width, area, and perimeter are all __________

Missing
POINTS (1)

Correct Answer

Explanation

Views:
Trials:
Avg score:
0
sin cos tan
sin-1 cos-1 tan-1 π e
xy x3 x2 ex 10x
y√x 3√x √x ln log
( ) 1/x % n!
7 8 9 + MS
4 5 6 M+
1 2 3 × M-
0 . EXP ÷ MR
± RND C = MC

Document Actions