Fall 2003 Final
Exam
CSE1320 Section
501
Tuesday, December 9, 2003 Dr.
Tiernan
Name: Section: 501
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, OPEN 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 and short answers are worth varying points each. Please circle the letter indicating your choice for the answer.
1. In C++, the operators >> and << are called {2}
A) istream and ostream operators
B) extraction and insertion
C) bit shift port and bit shift starboard
D) greater only than and less only than
2. Which of the following allows the program to specify a number of bytes to retrieve from a file that has been opened for reading? {2}
A) fscanf
B) fgets
C) fread
D) getc
3. Which of the following would be passing a reference parameter in C++? {2}
A) int borgle (int nod);
B) int borgle (int *nod);
C) int borgle (int& nod);
D) int borgle (int nod) const;
4. Which of the following is NOT related to dynamic memory allocation in any language we studied in this class? {2}
A) free
B) new
C) calloc
D) array
5. Describe the following briefly: {6 points total ; 2 each}
queue
container
class
template
Given the function below, answer the following questions.
(Assume elemstruct is a typedef for the underlying struct for an element which contains two pointers to type elemstruct, before and after, and elemtype is a typedef for the data value in the struct)
elemstruct *doto( elemstruct *now, elemstruct element, elemtype newvalue)
{
element.value = newvalue;
element.after = now;
now->before = &element;
return &element;
}
6. What abstract data type is being manipulated? {3}
7. What would be a more meaningful name for the function doto? {3}
8. Write the corresponding function to undo what function doto does to the ADT. {6}
9. What does the OS do with the parameters that are typed in on the command line following the name of the C executable? {4}
Given the following functions, answer the questions below:
int zed (int z)
{
if (z < 1)
return pow( 2, z );
else if !z // Line A
return pow( 2, z ); // Line B
else
return so( z );
}
int so (int s)
{
if !(s - 1) // Line C
return s;
else
return s + (s - 1) + so (s - 1); // Line D
}
10. Rewrite the test at Line A so that is easier to understand but still gives the same results. (Just rewrite the whole line here but change how the test is written) {4}
11. Rewrite Line B such that it returns the same answer but without using any library function. calls. {4}
l2. Rewrite the test at Line C so that is easier to understand but still gives the same results. {4}
13. What values will be returned for the following function calls? {10; two (2) points each}
|
call |
result of that function call |
|
zed(5) |
|
|
so(8) |
|
|
zed(0) |
|
|
so(0) |
|
|
zed(-3) |
|
14. Explain in words what the function so calculates with respect to the input value s. {4}
Given the code fragment below, answer the questions which follow:
#IFDEF TWEETY
float bird = 100;
int cat = 0;
char *cname = “Sylvester”;
#ELSE
float bird = 0;
int cat = 1;
char *cname=”Mudd”;
#ENDIF
float granny, spike;
int act = 8;
if (cname == “Mudd”)
printf(“Sylvester %d Tweety! Call Spike!”, act);
else
printf(“Tweety %d birdseed! Granny loves Sylvester.”, act);
15. If the program starts with the line #DEFINE BIRDSEED and there are no other DEFINE statements, what will the output be? [Just write the output in the space below] {4}
16. If the program starts with the line #DEFINE TWEETY, what will the output be? {4}
17. Given a file variable named using that is open for both reading and writing, write the command or commands that would move the file pointer to the 2nd byte from the end of the file. {6}
Given the class definition below, answer the following questions
class Bergy {
public:
Bergy();
bool iscool(int f) ;
float meas_ht( int hd, int ad, float an) ;
bool setlong( int d, m, s);
bool setlat( int d, m, s);
int *getlong () const { return long };
int *getlat () const { return lat };
void printloc ();
private:
int temp;
float ht;
int longit[3]; //[0] degrees, [1] minutes, [2] seconds
char longc; // N or S
int lat[3];
char latc; //E or W
}
18. Write the function definition for iscool that returns true if the input value is freezing or lower in Fahrenheit (32°) and false otherwise. {6}
[Remember, other than the function header this is pretty much straight C coding.]
19. Write the function definition for printloc such that it prints the latitude and longitude in degrees, minutes, seconds format (ex. Location is 32°50’27”N 97°3’2”W) {8}
[Don’t forget to use the C++ commands for output]
struct berg {
int temp;
float ht;
int longit[3]; //[0] degrees, [1] minutes, [2] seconds
char longc; // N or S
int lat[3];
char latc; //E or W
}
20. Write a function named halfway such that it takes two locations of the struct type above and returns a point halfway in between the two given locations on a straight line. Remember that latitude is 0° 0’ 0” at the equator and is measured North and South 180° and longitude is 0° 0’ 0” at Greenwich, England and is measured East and West 180°. {16}
Extra Credit questions
XC1. Given the declaration below, allocate space using the variable such that three elements of the pointer’s base type can be stored. {3}
struct splurge {
int eeny;
long meeny;
float moe;
double catch;
struct splurge *tiger;
} *toe;
XC2. Match the following library functions to their descriptions {5 points total ; 1 each }
A) time() C) localtime() E) clearer()
B) ctime() D) ferror()
returns a long int containing time information
determines if an error has occurred
returns a structure containing time information
resets
an error flag
returns a string containing time information
XC3. At this point, what seems like the most useful thing you learned in this class?
{ ANY ANSWER will receive TWO (2) POINTS}