Docsity

CPSC 206 Fall '07 Quiz Extra Credit: Structured Programming in C, Quizzes of Computer Science

Toggle sidebar
bg1
CPSC 206 Structured Programming in C, Fall ’07 RGW Quiz EXTRA CREDIT November 16, 2007
*************************************************************
* READ THE INSTRUCTIONS BELOW NOW *
* DO NOT LOOK AT THE EXAM UNTIL INSTRUCTED TO DO SO *
*************************************************************
Last name, First Name ____________KEY KEY KEY____________________
Last 4 digits of UIN ___________ Write your section number: _____________
The value of individual problems (eg. 10) is shown as [10] next to the problem number.
Do not look at your neighbor’s answers, or share your answers with your neighbor!
If you have a question about a problem, write your question, the answer you are
assuming, and continue. Do NOT ask a question aloud in class during the Quiz!
Verbosity is discouraged. Written answers should be in good English. Neatness counts
and we reserve the right to assign lower grades for sloppiness, much lower!
This is an open book Quiz. But cell phones, text messaging devices, calculators, PDAs,
CD players, radio, and headphones are NOT allowed!
You have 20 minutes to take this quiz. It is two-page, 30 points, and VI questions. It will
replace your lowest Quiz grade.
Remember:
Aggies do not lie, cheat, or steal and do not tolerate those who do!
I have obeyed the Aggie code of honor in my answers on this quiz.
Signature: _______________________________
Date: _______________________________
pf3

Partial preview of the text

Download CPSC 206 Fall '07 Quiz Extra Credit: Structured Programming in C and more Quizzes Computer Science in PDF only on Docsity!

* READ THE INSTRUCTIONS BELOW NOW *

* DO NOT LOOK AT THE EXAM UNTIL INSTRUCTED TO DO SO *

Last name, First Name ____________KEY KEY KEY____________________

Last 4 digits of UIN ___________ Write your section number: _____________

The value of individual problems (eg. 10) is shown as [10] next to the problem number.

Do not look at your neighbor’s answers, or share your answers with your neighbor!

If you have a question about a problem, write your question, the answer you are

assuming, and continue. Do NOT ask a question aloud in class during the Quiz!

Verbosity is discouraged. Written answers should be in good English. Neatness counts

and we reserve the right to assign lower grades for sloppiness, much lower!

This is an open book Quiz. But cell phones, text messaging devices, calculators, PDAs,

CD players, radio, and headphones are NOT allowed!

You have 20 minutes to take this quiz. It is two-page, 30 points, and VI questions. It will

replace your lowest Quiz grade.

Remember:

Aggies do not lie, cheat, or steal and do not tolerate those who do!

I have obeyed the Aggie code of honor in my answers on this quiz.

Signature: _______________________________

Date: _______________________________

I.[5] Consider the following function from the lab-09-solution.c:

void quit( void ) { FILE *fp; NODE *ptr = top; fp = fopen( file_name, "w" ); for ( ptr = ptr - > link; ptr != NULL; ptr = ptr - > link ) fprintf( fp, "%s", ptr - > line ); exit( EXIT_SUCCESS ); }

Mark the code to show how you would modify it to simply quit and not write the text to

disk, which saves the file edits.

II. [5] Consider the following function from the lab-09-solution.c demonstrated in class.

void delet( const char s ) { / printf( "Entered delet\n" ); / int count; char err_msg[] = "** Error. Command is: "; if(sscanf( s, "%d", &count)!=1) printf("%s d x\n", err_msg); else { NODE ptr = current->link; int delete_count = count; while (count > 0 && ptr != NULL) { printf("%s", ptr->line); current->link = ptr->link; / delete the line */ ptr->link = avail; avail = ptr; ptr = current->link; --count; } if (count < delete_count) printf("\ndeleted %d lines\n", delete_count-count); else printf("\nnothing deleted\n"); } }

Write a C statement to update the bottom pointer in case the line it points to is deleted

in the while loop. Use an arrow to show the place to insert it in the function definition.

if (bottom == ptr) bottom == current;

III. [5] Consider the struct defintion of a node in the text being edited.

typedef struct node { char line[ MAX_LENGTH ]; /* text of line */ struct node link; / pointer to next line */ } NODE;

How would you modify this to add a “line number” that is associated with each line

during editing, but not saved to disk?

Insert in the struct node definition, the declaration: int line_number;

_____________________________________________________________________