Question
a) All programs can be written in terms of three types of control structures:___ ,___ and___ . b) The selection statement _____is used to execute
a) All programs can be written in terms of three types of control structures:___ ,___
and___ .
b) The selection statement _____is used to execute one action when a condition is true
or a different action when that condition is false.
c) _____Repeating a set of instructions a specific number of times is called repetition.
d) When it is not known in advance how many times a set of statements will be repeated,
a(n)____ value can be used to terminate the repetition.
2. Write four different C++ statements that each add 1 to integer variable x.
ANS:
3. Write C++ statements to accomplish each of the following:
a) In one statement, assign the sum of the current value of x and y to z and postincrement
the value of x.
b) Determine whether the value of the variable count is greater than 10. If it is, print
"Count is greater than 10."
c) Predecrement the variable x by 1, then subtract it from the variable total.
d) Calculate the remainder after q is divided by divisor and assign the result to q. Write
this statement two different ways.
4. Write C++ statements to accomplish each of the following tasks.
a) Declare variables sum and x to be of type int.
b) Set variable x to 1.
c) Set variable sum to 0.
d) Add variable x to variable sum and assign the result to variable sum.
e) Print "The sum is: " followed by the value of variable sum.
5. Write single C++ statements or portions of statements that do the following:
a) Input integer variable x with cin and >>.
b) Input integer variable y with cin and >>.
c) Set integer variable i to 1.
d) Set integer variable power to 1.
e) Multiply variable power by x and assign the result to power.
f) Preincrement variable i by 1.
g) Determine whether i is less than or equal to y.
h) Output integer variable power with cout and <<.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started