Lab 5 Pre-Lab Assignment

Show all work!!!!

  1. Convert the base 10 number 118 to base 2.

     

     

  2. Find the 8-bit two's complement representation of each of the following (your answers to #1 will help):

    1. 118

    2. -118

     

     

  3. Convert the base 10 number 599 to base 9 two different ways:
    1. Using the subtraction method

       

       

    2. Using the division method

       

       

  4. Find the base 10 value of each of the following 8-bit two's complement numbers:

    1. 11100110

       

       

    2. 01110100

     

     

  5. Convert the base 8 number 32758 to
    1. base 10

       

       

    2. base 2 (using the special relationship between base 8 and base 2)

       

       

  6. What is the largest positive base 10 integer (unsigned -- all places are used for the number with no sign) that can be represented in four base 7 digits?

     

     

     

  7. The 8-bit two's complement representation of 107 is 01101011 and the representation of 52 is 00110100.
    1. Find the 8-bit sum (two's complement) of 107 and 52.
                 0 1 1 0 1 0 1 1
               + 0 0 1 1 0 1 0 0
               ------------------
      					<---- your answer
               __________________
      
      
    2. Convert your answer to base 10.

       

       

       

    3. Your answer to part (b) (which would be the computer's answer) is NOT 159 (the base 10 sum of 107 and 52). What happened?

       

       

       

  8. Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of the program is to let a student know if he/she made the Dean's list (the gpa must be 3.5 or above). Write an if... else... statement that prints out the appropriate message (either "Congratulations -- you made the Dean's List" or "Sorry you didn't make the Dean's List").

     

     

     

     

     

     

  9. Complete the following program to determine the raise and new salary for an employee by adding if ... else statements to compute the raise. The input to the program includes the current annual salary for the employee and a number in the range 1 - 10 indicating the performance rating (10 is the best; 1 the worst rating). An employee with a rating of 7 or greater will receive a 5% raise and all others will receive a 2% raise. An employee receiving a rating of 10 will receive an extra $500.
    // ***********************************************************
    // File:  Salary.java
    //
    // Compute the raise and new salary for an employee
    // ***********************************************************
    import cs1.Keyboard;
    
    public class Salary
    {
       public static void main (String[] args)
       {
          double currentSalary;  // current annual salary
          int rating;            // performance rating
          double raise;          // dollar amount of the raise
    
          // Get the current salary and performance rating
          System.out.print ("Enter the current salary: ");
          currentSalary = Keyboard.readDouble();
          System.out.print ("Enter the performance rating: ");
          rating = Keyboard.readInt();
    
          // Compute the basic raise -- Use if ... else ...
    
    
    
    
    
    
    
    
    
    
           // Add an extra $500 to the raise if the performance rating is 10
           // (use an if with no else!)
    
    
    
    
    
    
    
    
    
          // Print the results
          System.out.println ("Amount of your raise: $" + raise);
          System.out.println ("Your new salary: $" + currentSalary + raise);
       }
    }