Print Name  ___________________

                                                                                                                  Signature   ___________________

Decisions Lab
Individual Assignment
10  Points


Set Netscape Margins [ Left = 1; Right = .2; Top = .6; Bottom = .6; Select Document Title, Location,  Page Number, Page Total Black Text l]


1] Each of the following blocks of code may or may not produce any output. Record any output to the right of the block of code. See Examples. If syntax corrections need to be made in order to make the code compile corretly, use a pen or different colored ink to make the corrections.!

If in doubt, plug it into the computer and test the block of code!


Assume the following declarations, at the top of main, for all.
int
   A = 10,
   B = 5,
   Temp;

Example 1
   A = 10,   <-- Correct , should be ;!
   B = 5;
cout << "Ex1: A = " << A << "     B = " << B << endl;
if (A <= B)
   B = A;
 cout <<  "A = " << A << "     B = " << B << endl;
Ex1: A = 10     B = 5

A = 10     B = 5


Example 2
   A = 10;
   B = 5;
cout << "Ex2: A = " << A << "     B = " << B ;
cout << "     Temp = " << Temp << endl;
if (A > B)
   B = A;
else
   B = A - 5;
 cout <<  "A = " << A << "     B = " << B << endl;
Ex2: A = 10     B = 5     Temp = ???
 
 

A = 10     B = 10


Example 3
   A = 10;
   B = 5;
cout << "Ex3: A = " << A << "     B = " << B << endl;
if (A > B)
   cout << "A > B\n";
else if (A == B);
   cout << "A = B\n";
else
   cout << "A < B\n";

Ex3: A = 10     B = 5
A > B
 

 


A = 10;
B = 5;
cout << "#1: A = " << A << "     B = " << B << endl;
if (A <= B)
   B = A;
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#2: A = " << A << "     B = " << B << endl;
if (A <= B)
  B = A;
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#3: A = " << A << "     B = " << B << endl;
if (A <= B)
   {
      B = A;
      cout << "A = " << A << "     B = " << B << endl;
   }

A = 10;
B = 5;
cout << "#4: A = " << A << "     B = " << B ;
cout << "     Temp = " << Temp << endl;
if (A < B)
Temp = A;
A = B;
B = Temp;
cout << "#4: A = " << A << "     B = " << B ;
cout << "     Temp = " << Temp << endl;

A = 10;
B = 5;
Temp = 2;
cout << "#5: A = " << A << "     B = " << B ;
cout << "     Temp = " << Temp << endl;
if (A < B)
if (A < B)
{
Temp = A;
A = B;
B = Temp;
}
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#6: A = " << A << "     B = " << B << endl;
if (A < B)
     if ((A < B)  ||  (B – A < 0))
       {
          A = A + B;
          B = B + 1;
          cout << “A = " << A << "     B = " << B << endl;
       }
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#7: A = " << A << "     B = " << B << endl;
if ((A < B) && (B - A < 0))
   {
      A = A + B;
      B = B - 1;
      cout <<  "A = " << A << "     B = " << B << endl;
   }
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#8: A = " << A << "     B = " << B << endl;
if (A = B)
   {
      A = A + B;
      B = B - 1;
      cout <<  "A = " << A << "     B = " << B << endl;
  }
cout <<  "A = " << A << "     B = " << B << endl;

A = 10;
B = 5;
cout << "#9: A = " << A << "     B = " << B << endl;
if (A > 0) ;
   Sum = Sum + A;
cout <<  "A = " << A << "     B = " << B << endl;

A = B = 18;
cout << "#10: A = " << A << "     B = " << B << endl;
if (A % 5 == 0)
   cout << "A = " << A << endl;
cout << " 14 % 2" = " << 14 % 2 << endl;
cout << " 14 % 3" = " << 14 % 3 << endl;
cout << " 14 % 4" = " << 14 % 4 << endl;
cout << " 14 % 5" = " << 14 % 5 << endl;
cout << " 14 % 20" = " << 14 % 20 << endl;
cout <<  "A = " << A << "     B = " << B << endl;

A = B = 18;
cout << "#11: A = " << A << "     B = " << B << endl;
if (A / 5 == 3)
   cout <<  "A = " << A << endl;
cout << " 1 / 2 " = " << 1 / 2  << endl;
cout << " 3 / 4 " = " << 3 / 4  << endl;
cout << " 4 / 2 " = " << 4 / 2  << endl;
cout << " 7 / 2 " = " << 7 / 2  << endl;
cout << " 99 / 30 " = " << 99 / 30  << endl;

2] Anticipate the intended logic. Correct all of the errors in each of the following program fragments. Assume the following declarations, at the top of main, for all.
int
   A = 10,
   B = 5,
   Count,
   Sum;

if A = 10
   cout <<  "A = " << A < < endl

A = 7;
if 3 < A < 10
   {
      A = A + 1;
      cout <<  "A =  << A < < endl;
   }

Count = 0;
Sum = 0;
A = 50;
if (A < 0)
   Count = Count + 1
else if A = 0
   Count = Count - 1;
Sum = Sum + A;
cout <<  "A =  << A << "   Count =  << A << "Sum =  << A << endl;


3] Those Labs labeled "Individual Assignment" are to be done separately by each individual. Using a pen,  each individual is to print  his/her name at the top of this document in the space provided and sign it.  Those Labs labeled "Team Assignment" may be done as a team or individually. Using a pen,  each individual on the team is to print print his/her name at the top of this document in the space provided and sign it. Submit only one copy of team assignments!

Include the following in your wire-band binder:

A] Divider

B] Copy of this assignment sheet. Using an ink pen, print your name and sign this lab at the top.