Fall 2003   Test #1

CSE1320                                                                                          Sections 501

Thursday, September 25, 2003                                                          Dr. Tiernan

 

Name:                                                                                              Section:                                             

Student ID:                                                                                      Keyword:                                         

 

Instructions:

 

1.   Fill in your name, student ID, and section above.  Choose some keyword for yourself that I can use to anonymously post grade information.  If you do not choose a keyword, I cannot post your grade information if needed.

 

2.   This is a OPEN book, closed notes, NO CALCULATOR test.

 

3.   The test is worth a total of 100 points.  The value for each question is given either at the top of that section of questions or in curly braces to the right hand side of the question.  There are extra credit questions at the end of the test worth an additional 10 points total.

 

4.   NO CHEATING!

 

 


Multiple choice questions are worth three {3} points each.  Please circle the letter indicating your choice for the answer.

 

 

1)         Which of the following would NOT tell you something about an integer type?

 

A)        INT_MIN

B)        CHAR_BIT

C)        FLOAT_MIN

D)        LONG_MAX

 

 

2)         The use of curly braces in a C program would NOT mean:

 

A)        compound statement

B)        grouping in an arithmetic statement

C)        block

D)        function body

 

 

3)         Which of the following is not a type conversion in C?

 

A)        Changing a lowercase letter to an uppercase letter

B)        Using a float variable as a double to add in a statement which contains both types

C)        Converting a short variable into an int before performing arithmetic

D)        Using (int) before a variable of type double

 

 

4)         Which of the following is not a string function in C?

 

A)        strchr

B)        strtok

C)        strdup

D)        strncmp

 

 

5)         Name  and describe the following C operators.                           {9 points total ; 3 each}

 

*                                                                                                                                                    

&                                                                                                                                                  

<<                                                                                                                                                

 

 

 

 


6)         Write a code fragment to do the following:                                                                    {12}

Declare an array of 64 doubles named square and initialize it to all zeroes in the declaration.  Then write a counted loop to calculate the squares of the first ten positive integers (> 0) and assign them to the first ten elements in the array square.  After this is complete, write a conditional loop that prints each value in the array until it finds a value equal to 0 and then stops.  Print the values in exponential notation.

 

 

 


7)         Given the following code fragment, fill in                                                                      {12}

Hex 2-byte address

             Value

Variable name

408

 

 

40A

 

 

40C

 

 

40E

 

 

410

 

 

412

 

 

414

 

 

416

 

 

418

 

 

41A

 

 

41C

 

 

41E

 

 

420

 

 

422

 

 

424

 

 

426

 

 

428

 

 

42A

 

 

42C

 

 

the memory diagram on the right with the

appropriate values  and variable names if

short takes 2 bytes, char takes 2 bytes, int

takes 4 bytes, float takes 6 bytes, double

takes 8 bytes, and addresses take 4 bytes.

 

 

char hi[4] = “Hi!”;

 

short temp = 88;

 

int store[2];

 

double Pinocchio;

 

short *stempy = &temp;

 

double *nose= &Pinocchio;

 

char *howdy = hi;

 

Pinocchio = temp * temp;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8)         Given the code below, if the user enters the values C3 and 80, what will the value of result be in hexadecimal?          {8}

 

int op1, op2, result;

 

scanf( “%x %x”, &op1, &op2);

result = op1 ^ op2;

 

 

The value of result in hexadecimal is:                                                    

 

 


9)         Given the following values in memory locations A00 to A0A, declare an array

A00

14

A02

9897

A04

5.3

A06

-10.6

A08

1400

A0A

3299

named tigger containing all the values and write assignment statements which would store the given values into the appropriate memory locations.  (i.e. you are writing the code that put this stuff in memory in the first place.)            {8}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10)       Using the array tigger you declared above in question 9, do the following:             {11}

 

            Write a loop that goes through every value in the array tigger using only pointer arithmetic.  For each value, if it is greater than 1000, subtract 1000 from the number repeatedly until the number is less than 1000, else if the number is less that 10, add 10 to that number.

 

 

 

 

 

 


11)       Write an entire function as follows:                                                                                 {12}

 

The function should be named shoop, should have a double array and an integer variable num as input and should return pointer to integer as its output type.  The value of num is the number of elements in the double array.  Inside the function, declare an integer pointer nundub  and then use that pointer to allocate enough space for num integers.  Use array notation to assign the floating point values from the input array to the integer elements of nundub.  Don’t forget to cast.  Return the value of nundub (i.e. the address it contains) at the end of the function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

12)      

            Convert the sum of 44210 and 348 to binary.                                                                      {7}

 

 

 

 

 

 

 

 

 

 

 

 

210

29

28

27

26

25

24

23

22

21

20

 

 

 


 

13)       Write a main routine to do the following:                                                                         {9}

 

Declare an array large enough to hold one line of text.  Use gets to read in a line of text from the keyboard and store it in the array.  Use the string functions to find the location of the first letter ‘c’ (lowercase only) in the string.  Set a pointer to point to that location in the string and then print the end of the string starting from that letter ‘c’.

 

 

 

 

 

 

 

 

 


Extra Credit questions  - Worth two {2} points each unless stated otherwise.

 

 

XC1)   Write a prototype declaration for the following:

 

An integer return type function with an input of char and an input array of ten floats.

 

 

 

 

 

 

 

 

XC2)   Which of the following is a true difference between strings and character arrays?

 

A)        The bounds on character arrays are checked and strings are not.

B)        Strings must be terminated by an end-of-string marker.

C)        Strings can only hold letters, not digits or punctuation.

D)        Values in strings can be initialized at declarations and char arrays cannot.

 

 

XC3)   Write an original question that you think would be worth 6 points if I gave it to everyone else on the next test.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

XC4)   Which of the following would be considered cheating in CSE at UTA?                  {4}

 

A)        Using existing source code as the basis of a program if the instructor tells you to do so.

B)        Working with a classmate to figure out why there are errors in your programs

C)        Handing your completed lab assignment code to a classmate who has not started yet.

D)        Discussing the lab assignment and talking about how many modules to create.