CS 1620 Assignment #2 Spring 2001

How to handin.
Due: Wednesday Jan 31, 2001 @ midnight

Marks will be awarded for comments, style, readability, compiling and working correctly.
  1. Write a program that prompts the user to enter three integer numbers then prints them using the following different formats:
    1. Print all the numbers on the same line.
    2. Print all the numbers on the same line but in reverse order.
    3. Print each number on one line.
    4. Print each number on one line but in reverse order.

    Sample input and results are show below:

      Enter three numbers: 14 -67 890
    
      Your three numbers are: 14 -67 890
    
      Your three numbers in reverse order are: 890 -67 14
    
      Your three numbers are:
      14
      -67
      890
      
      Your three numbers in reverse order are:
      890
      -67
      14
    

  2. Given the following program. Compile and run it on three different days, then explain your results.
    #include <iostream>
    
    using namespace std; 
    
    int main()
    {
       int a, b, c, d;
    
       cout << "a = " << a <<";   "<< "b = " << b << endl;
       cout << "c = " << c <<";   "<< "d = " << d << endl;   
    
       return 0;
    }
    

  3. There are several syntax errors in the following program.
    First, compile the program as given below, then correct all the errors and run the program.
    #include <iostraem>
    
    using namespace std; 
    
    int main()
    {
       int weight-kg; 
       float height_ms
    
       cout << 'Enter your weight in kg:" << endl;  
       cin >> weight
       cout << 'Enter your height in meters:' << end1;  
       cin << Height_ms;
    
       return 0;
    }
    

  4. C++ supports three different sizes of integer: short int, int, and long int. The size is machine dependent and varies from computer to computer. Each computer has its internal limits.
    Write a program that determines the exact size, in bytes, of short int, int, and long int on the machine that you are using in the lab. (Use the operator sizeof that I will explain in class).
    Also, use the predefined constants INT_MIN and INT_MAX to print the smallest (most negative) and largest values (most positive) of type int. In order to use the predefined constants INT_MIN and INT_MAX you have to add to your program the directive #include <climits>
    The output of your program should be as follows:
      There are X bytes in the data type short
      There are Y bytes in the data type int
      There are Z bytes in the data type long 
      The maximum value that can stored in an int is: 1222222222222
      The minimum value that can stored in an int is: -333333333333
    
    where X, Y, Z, 1222222222222, and -333333333333 are the answers that you get when you run your program.

Assignment List | Prev | Next | Computer Science 1620
Department of Mathematics & Computer Science
University of Lethbridge Home Page