Question

In: Computer Science

C++ EXERCISES (a) Given int a = 5, b = 2, c = 4, and d...

C++ EXERCISES

(a) Given int a = 5, b = 2, c = 4, and d = 5; determine the value of the expression:

d % b * c > 5 || c % b * d < 7.   

(b) Which repetition statement is preferred for user data input and its validation?             

(c) Write a for statement to populate an array, double val[NUMCOUNT], for the following case: Use a counter named double count that has an initial value of 16.2, a final value of 0.4, and a decrement of 0.2 and populate the val[] array with the value of count.

What is the size, NUMCOUNT, of the array val[]?

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

For the given statement d % b * c > 5 || c % b * d < 7

Let's debug it one by one.

according to operator precedence , it will execute like below

first : d % b * c > 5

second : c % b * d < 7

after that OR of these two statements will be the final result.

Now resolve first one

d%b*c here * will execute first and % after that.

=d % b * c > 5

=5%2*4>5

=5%8>5

=0>5

=false

now let's see second statement.

c % b * d < 7

again lets see the value of

c % b * d<7

it will be

=4%2*5<7

=4%10<7

=0<7

=true

Hence final result will be or of these two output

that is false OR true= true

Hence it will result = 1

c++ output confirmation

2)

Do While loop is preferred for user input and validation.

suppose there is a requirement that ask a user number that should be greater than 0

than these can be handle easily with the help of while loop as below

do{

cin>>number;

}while(number<=0)

Above code will keep asking for number until positive number is not entered.

3)

In order to get the size, Following calculation can be used.

Starting value is : 16.2

Ending value is : .4

Difference is : 16.2-.4 = 15.8

so the value of NUMCOUNT willl be = 15.8/.2+1

= 79+1

=80

extra one is added due to zero base index.

And the for loop would be as below

#include <iostream>
using namespace std;

int main(void) {
   //initialize num count
   int NUMCOUNT=77;

   //declare array of double
   double val[NUMCOUNT];

   //index for subscripting
   int index=0;

   //loop for
   for(double count=16.2;count>=0.4;count-=.2){
       val[index] = count;
       index++;
   }
   return 0;
}


Related Solutions

Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2 d. 17/13 2. Solve for x: 5(x+3) = 35 a. 2 b. 7 c. 4 d. -4 3. Acid rain occurs primarily as a result of a. operating a nuclear power plant b. burning coal or oil containing sulfur c. by-products created by operating an oil refinery d. the use of Freon and other refrigerants 4. The "ozone holes" at the polar region arise...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c b) a % b c) b **c d) b *= c 27. Given the following var_1 = 2.0 var_2 = "apple" var_3 = 'orange' var_4 = 4 Predict the output of the following statements or indicate that there would be an error. a) print (var_1) b) print (var_2) c) print ("var_3") d) print (var_1 / var_4) e) print (var_4 + var_3) f) print (var_2...
Given A*B*C and A*C*D, prove the corollary to Axion B-4.
Given A*B*C and A*C*D, prove the corollary to Axion B-4.
a = [4, −9, 4] b = [7, 2, 3] c = [5, −8, 9] d...
a = [4, −9, 4] b = [7, 2, 3] c = [5, −8, 9] d = [1, −3, 2] e = [6, −2, −5, 9] f = [4, −3, 7, 5] g = [1, 3, −1, 5] h = [7, −5, 5] i = [5, 13, −7, 11] Express the hyperplane implicitly or explicitly given the following a) a and h b) f and i c) e, f, and g d) The hyperplane containing b, c and d can...
Suppose A*B*A′ holds(B is between A and A')  and D ∈ Int(∠ABC). Prove that C ∈ Int(∠A′BD)....
Suppose A*B*A′ holds(B is between A and A')  and D ∈ Int(∠ABC). Prove that C ∈ Int(∠A′BD). (a) Prove that C ∈ H(D,line A′B). (b) Prove that C ∈ H (A′, line←→BD). Use point A. (c) Deduce that C∈Int (∠A′BD).
A, B, C, D are all matricies A = 2x3 1 2 −3 −1 4 5...
A, B, C, D are all matricies A = 2x3 1 2 −3 −1 4 5 , B = 2x3 3 0 −1 1 2 1 , C = 2x2 2 5 1 2 , D = 3x3 1 −1 1 2 −1 2 4 −3 4 Find each of the following or explain why it does not exist. 1) A + B, 2) 2A − 3B, 3) A + C, 4) A − C, 5) AC, 6) CA, 7)...
give a) Domain b) VA c) HA* d) OA* e) y-int f) x-int for each 2)...
give a) Domain b) VA c) HA* d) OA* e) y-int f) x-int for each 2) f(x) = 4 /3x - 9 3) g(x) = (x -1)(x + 4) /(x + 1)(x - 5) 4) h(x) = x ^2 + 4x/ x + 6 5) j(x) = x ^2 - 4 /(x + 2)(x - 3)
Atomicity of phosphorus is (a) 1 (b) 2 (c) 3 (d) 4
Atomicity of phosphorus is ________.(a) 1(b) 2(c) 3(d) 4
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT