Computer Science ( C++ )

profileBALB123
assignment_6.pdf

         CPSC  120  –  Assignment  6                                                                                        Due:    03/27/2014  23:59pm  

 

Student  Name:               CWID:  

 

  1  .  Determine  the  value,  true  or  false,  Of  each  of  the  following  Boolean  expressions,  assuming  that  the   value  of  the  variable  count  is  0  and  the  value  of  the  variable  limit  is  10.  Give  your  answer  as  one  of  the  values   true  or  false.  

a. (count==0)    &&    (limit  <  20)   b. (  count==0)  ||    (limit  <  20)   c. (limit  >  20)    ||    (count  <  5)   d. !(count  ==  12)   e. (count  ==  1)    &&    (x  <    y)   f. (count  <10)    ||    (x  <    y)     g. !(    ((count  <10)  ||  (x  <    y)  )    ||  (limit  <  20)   h. ((limit/count)  >  7)    ||    (limit  <  20)   i. (limit  <  20)    ||    ((limit/count)    >  7)   j. ((limit/count)  >  7)    &&    (limit  <  0)   k. (limit  <  0)    &&    ((limit/count)  >  7)   l. (5    &&    7)    +    (16)          

2.    In  college  Algebra  we  see  numeric  intervals  given  as  

         2  <  x  <  3  

In    C++    this  interval  does  not  have  the  meaning  you  may  expect.  Explain  and  give  the  correct    C++  Boolean   expression  that  specifies  that  x  lies  between  2  and  3.  

3.  Does  the  following  sequence  produce  division  by  zero?  

j  =  -­‐1;  

If  ((j  >  0)    &&    (1/(j  +  1)    >    10))  

         cout    <<    j    <<    “\n”;  

4.  Given  the  following  declaration  and  output  statement,  assume  that  this  has  been  embedded  in  a  correct   program  and  is  runnable.  What  is  the  output?  

enum  Direction  {  N,    S,    E,    W  };  

cout    <<  W    <<  “  ”  <<  E  <<  ”  ”  <<  S  <<  “  “  <<  N  <<  “\n”;  

5.    .  Given  the  following  declaration  and  output  statement,  assume  that  this  has  been  embedded  in  a  correct   program  and  is  runnable.  What  is  the  output?  

enum  direction  {  N  =  5,  S  =  7,  E  =  1,  W  };  

cout  <<  W  <<  “    “    <<  E  <<  “  ”  <<  S  <<  “  “  N  <<  “\n”;  

 

6.  What  is  the  output  of  the  following  (when  embedded  in  a  complete  program)?  

Int    count  =  3;    

While    (count-­‐-­‐      >  0){  

                 cout  <<    count    <<  “  \n“;}  

7.  What  is  the  output  of  the  following  (when  embedded  in  a  complete  program)?  

Int    count  =  3;    

While    (-­‐-­‐count    >    0){  

               cout    <<    count    <<  “\n  “;}  

 

8.  Using  While  loop,  Write  a  program  which  outputs  the  ASCII  table  

9.  Using  While  loop,  Write  a  program  that  outputs  even  numbers  between  0  and  100  

10.  Using  While  loop,  Write  a  program  that  outputs  prime  numbers  between  0  and  100  

11.  Using  While  loop,  Write  a  program  that  outputs  numbers  from  0-­‐100  ascending    

12.  Using  While  loop,  Write  a  program  that  outputs  numbers  from  0-­‐100  Descending