Programming Fundamentals 1 - Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write a C++ statement for the expression: area = πr^2

#include <cmath> const double PI = 3.14159; double area = PI * pow (r, 2);

Write a C++ statement that will calculate the square root of 9 and store the result in a variable named rootOf9

#include <cmath> double rootOf9 = sqrt(9);

What is not a valid comment statement?

*/ comment 3 /*

When saving a C++ source file, save it with an extension of:

.cpp

What is the result of coding, compiling, and executing the following statements? int a = 400; a += 5 * 5; // a = a + 25; // a + 400 + 25; cout << a;

425

What is the result of the following expression? 10 + 5 * 3 - 20

5

What is the result of the following expression? 17 % 3 * 2 - 12 + 15

8

This is a variable whose content is read only and cannot be changed during the program's execution.

Constant variable

What is the result of coding, compiling, and executing the following code? double var = 47.6; // int var = 47 var++; cout << var;

Output for double: 48.6 // Output for int: 48

Variables of the bool data type are useful for:

True/false condition

What must be declared before they can be used in C++?

Variables

To display the output on the next line, you can use this escape sequence in the cout statement:

\n

Write two different ways to increase the value of a variable named count by 1.

count ++, count += 1 // count = count +1

Every C++ application program must have:

main function // int main(){

Character literals are enclosed in _______; string literals are enclosed in _________.

single quotes (' ') double quotes (" ")

The primitive date types only allow a(n) ________ to hold a single value.

variable

What is the result of coding, compiling, and executing the following code? int x = 5, y = 20; x += 32; // x = x + 32; y /= 4; // y = y/4; cout << "x = " << x << ", y = " << y;

x = 37, y = 5

What will be displayed after the following statements have been executed? const double x = 99.0; y = 54.3; cout << "x = " << x;

x = 99.0

What is the result of coding, compiling, and executing the following code? int x = 78; int y = 2 + x++; cout << "y = " << y << "and x= " << x;

y = 80 and x= 79

What will be the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = static_cast<double> (y/x);

z = 8.0


Ensembles d'études connexes

Properties of Water - Science - Grade 9

View Set

World War I Review Terms (Period 7)

View Set

Human Anatomy Body System Structure & More

View Set

Chapter 17: Immunization and Immune Testing

View Set

South U Ch 18 Endocrine Rodriguez

View Set

PSYC 3206: Chapter 1, SmartBook Questions

View Set

Mastering A+P: Chapter 11: Appendicular Musculature

View Set