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.

download Export
search_insights Statistics
stylus_note White Board
Quran
calculate Calculator
dictionary Dictionary
fullscreen Full Screen

QUESTION OF
Views #: 634
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

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

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

1 pts
volume_mute
Program to compute and output the perimeter and area of a rectangle.
Length = 6
Width = 4
Perimeter = 20
Area = 24
note_alt Add notes
flag Flag

Correct Answer

Explanation

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

1 pts
volume_mute
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;
note_alt Add notes
flag Flag

Correct Answer

Explanation

Explain how this happens

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

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

Please drag and drop the selected option in the right place or type it instead
output
result
expression
note_alt Add notes
flag Flag

Correct Answer

Explanation

Arithmetic expression or a string?

1 pts
volume_mute
length + width

is an example of 

note_alt Add notes
flag Flag

Correct Answer

Explanation

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

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

endl

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

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

1 pts

What does the second length evaluate to?

(write a whole number without decimal points)

Missing
note_alt Add notes
flag Flag

Correct Answer

Explanation

There is no way to output length value as 6.0?

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

return 0;

1 pts
volume_mute

returns zero to the program itself which continues running

note_alt Add notes
flag Flag

Correct Answer

Explanation

Main function

1 pts
volume_mute

A C++ program can execute without a main function

note_alt Add notes
flag Flag

Correct Answer

Explanation

Anything comes after // is not executable

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

#include <iostream>

1 pts
volume_mute
#include <iostream>

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

note_alt Add notes
flag Flag

Correct Answer

Explanation

using namespace std;

1 pts
volume_mute
using namespace std;

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

note_alt Add notes
flag Flag

Correct Answer

Explanation

int main()

1 pts
int main()

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

Please drag and drop the selected option in the right place or type it instead
heading
right brace
left brace
note_alt Add notes
flag Flag

Correct Answer

Explanation

Stream insertion operator

1 pts
volume_mute
note_alt Add notes
flag Flag

Correct Answer

Explanation

Various parts of a C++ program

1 pts

Match certain program sections

  • (1) lines from 1 to 4
  • (2) lines from 11 to 14
  • (3) lines from 19 to 22
  • (4) lines from 23 to 26
Please drag and drop the selected option in the right place or type it instead
Assignment statements
Variable declarations
Comments
Output statements
note_alt Add notes
flag Flag

Correct Answer

Explanation

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

1 pts
Missing
note_alt Add notes
flag Flag

Correct Answer

Explanation

Keywords
Year 10