Program Design (II): Quiz2 May 18, 2009 Part1. True/False Questions (30pts) Part2. Multiple Choice Questions (40pts)

Similar documents
Cpt S 122 Data Structures. Course Review Midterm Exam # 1

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Ch 11. C File Processing (review)

Lecture 8. Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Chapter 11 File Processing

Lecture6 File Processing

Cpt S 122 Data Structures. Data Structures

MARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100

ENG120. Misc. Topics

Chapter 12. Files (reference: Deitel s chap 11) chap8

Lecture 9: File Processing. Quazi Rahman

UNIT IV-2. The I/O library functions can be classified into two broad categories:

File Processing. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

C File Processing: One-Page Summary

Files and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Fundamentals of Programming. Lecture 15: C File Processing

Cpt S 122 Data Structures. Data Structures Trees

CSCI 171 Chapter Outlines

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

Introduction to file management

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

C mini reference. 5 Binary numbers 12

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

C: How to Program. Week /June/18

V.S.B ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY I IT-II Semester. Sl.No Subject Name Page No. 1 Programming & Data Structures-I 2

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

System Software Experiment 1 Lecture 7

Preprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.

PROGRAMMAZIONE I A.A. 2017/2018

LAB 13 FILE PROCESSING

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Standard C Library Functions

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

LAB 13 FILE PROCESSING

Advanced C Programming and Introduction to Data Structures

Name CPTR246 Spring '17 (100 total points) Exam 3

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

CS PROGRAMMING & ATA STRUCTURES I. UNIT I Part - A

Data Structure Advanced

CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS

STRUCTURES & FILE IO

CP2 Revision. theme: dynamic datatypes & data structures

Programming Fundamentals

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

Linked List. April 2, 2007 Programming and Data Structure 1

Computer programming

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CSI 402 Lecture 2 Working with Files (Text and Binary)

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 12

Intermediate Programming, Spring 2017*

12 Abstract Data Types

Heap Arrays. Steven R. Bagley

C Basics And Concepts Input And Output

Code No: R Set No. 1

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

What is recursion. WAP to find sum of n natural numbers using recursion (5)

Chapter 20: Binary Trees

CAAM 420 Notes Chapter 2: The C Programming Language

UNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.

211: Computer Architecture Summer 2016

File (1A) Young Won Lim 11/25/16

C programming basics T3-1 -

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

15. Stacks and Queues

CS 241 Data Organization Binary Trees

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

Documentation. Programming / Documentation Slide 42

CS240: Programming in C

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Input / Output Functions

File I/O. Arash Rafiey. November 7, 2017

Pointers and File Handling

Chapter 8 File Processing

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Introduction to Computer and Program Design. Lesson 6. File I/O. James C.C. Cheng Department of Computer Science National Chiao Tung University

MATLAB. Data and File Management

CSI 402 Lecture 2 (More on Files) 2 1 / 20

Organization of a file

fopen() fclose() fgetc() fputc() fread() fwrite()

ECE551 Midterm Version 1

Computer Programming Unit v

C-Refresher: Session 10 Disk IO

CS 261 Fall Mike Lam, Professor. Structs and I/O

Heap Arrays and Linked Lists. Steven R. Bagley

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

Data Structures Question Bank Multiple Choice

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Transcription:

Class: No. Name: Part1. True/False Questions (30pts) 1. Function fscanf cannot be used to read data from the standard input. ANS: False. Function fscanf can be used to read from the standard input by including the pointer to the standard input stream, stdin, in the call to fscanf. 2. You must explicitly use fopen to open the standard input, standard output and standard error streams. ANS: False. These three streams are opened automatically by C when program execution begins. 3. A program must explicitly call function fclose to close a file. ANS: False. The files will be closed when program execution terminates, but all files should be explicitly closed with fclose. 4. If the file position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file. ANS: False. Function rewind can be used to reposition the file position pointer to the beginning of the file. 5. Function fprintf can write to the standard output. 6. Data in sequential-access files are always updated without overwriting other data. ANS: False. In most cases, sequential file records are not of uniform length. Therefore, it is possible that updating a record will cause other data to be overwritten. 7. It is not necessary to search through all the records in a random-access file to find a specific record. 8. Records in random-access files are not of uniform length. ANS: False. Records in a random-access file are normally of uniform length. 9. Function fseek may only seek relative to the beginning of a file. ANS: False. It is possible to seek from the beginning of the file, from the end of the file and from the current location in the file. 10. A self- referential structure is used to form dynamic data structures. 11. Function malloc is used to dynamically allocate memory. 12. A stack is a specialized version of a linked list in which nodes can be inserted and deleted from anywhere of the list. ANS: False. A stack is a specialized version of a linked list in which nodes can be inserted and deleted only from the start of the list. 13. A NULL pointer normally indicates the end of a data structure. 14. A queue is referred to as a FILO data structure. ANS: False. A queue is referred to as a FIFO data structure. 15. The pointer to the next node in a linked list is referred to as a link. 16. Function free is used to reclaim dynamically allocated memory. 17. A queue is a specialized version of a linked list in which nodes can be inserted only at the start of the list and deleted only from the end of the list. 18. A stack is referred to as a LIFO data structure because the first node inserted is the last node removed. ANS: False. A stack is referred to as a LIFO data structure because the last node inserted is the first node removed. 19. The nodes of a binary tree contain two link members. 20. The first node of a tree is the root node. Part2. Multiple Choice Questions (40pts) 1. Which of the following is false? a) Storage of data in memory variables is temporary; all such data is lost when a program terminates. b) Computers store files on primary storage devices, typically disk storage devices. c) Files are used for permanent retention of data (typically large amounts of data). d) Storage of data in memory arrays is temporary; all such data is lost when a program terminates. 2. Which statement is true? a) The smallest data item in a computer is called a byte. b) Digits, letters and special symbols are referred to as memory words. 1

c) Fields are composed of records. d) Bytes are composed of bits. 3. Function reads one character from a file. a) fgetcharacter b) fgetc c) fgetchar d) fgetbyte 4. Function feof. a) forces an end-of-file condition b) determines whether the end-of-file indicator is set for a file c) sets the end-of-file indicator for a file d) flushes the contents of the file from the current position to the end 5. If an error occurs while opening a file in any mode, fopen. a) causes program termination b) returns NULL c) issues the message can t open file d) diagnoses the error, waits five minutes and retries Ans: (b) 6. Function fscanf is equivalent to function scanf, except that fscanf. a) can have only a single argument. b) can read only from standard streams. c) can read only from open streams. d) receives as an argument a file pointer for the file from which the data is read. 7. The rewind statement causes. a) the disk to stop spinning, then spin in reverse until it repositions to the beginning of the file b) the contents of the file to be erased c) a program s file position pointer to be repositioned to the beginning of the file (i.e., byte 0) d) works with tape files but not disk files 8. Which of the following is false? (a) Data can be inserted in a randomly accessed file without destroying other data in the file (b) There is more than one way to implement randomly accessed files. (c) Randomly accessed files cannot be accessed directly without searching through other records. (d) Data stored previously can be updated or deleted without rewriting the entire file. 9. What is the significance of the 1 in the following statement? fwrite( &number, sizeof( int ), 1, fptr ); (a) It specifies that the file is to be opened for updating. (b) It specifies the number of elements in the array that should be written to disk. (c) It specifies the byte size of the element being written to disk (d) none of these 10. Which statement is true? a) fseek searches for a record by its record key. b) fseek sets the file position pointer to a specific byte location in the file. c) fseek moves the read-write head on the disk to the location on disk that corresponds to a specific location in a file. d) fseek must immediately follow each call to fread or fwrite. 2

11. represent waiting lines; insertions are made at the back (also called the tail) and deletions are made from the front (also called the head) of a. a) Linked lists b) Queues c) Stacks d) Binary trees 12. facilitate high-speed searching and sorting of data, efficient elimination of duplicate items and compiling expressions into machine language. a) Linked lists b) Queues c) Stacks d) Binary Trees 13. A self-referential structure contains a member that points to. (a) integer, a structure of the same structure type (b) pointer, an integer (c) integer, an integer (d) pointer, a structure of the same structure type 14. Function malloc takes as an argument the number of bytes to be allocated, and returns a pointer of type to the allocated memory. a) NULL b) void c) void * d) NULL * 15. If no memory is available malloc returns a pointer. a) self b) NULL c) void d) NULL * 16. Not returning dynamically allocated memory when it is no longer needed can cause a system to run out of memory prematurely. This is called a(n). a) outage b) memory hole c) memory access violation d) memory leak 17. is not an advantage of linked lists when compared to arrays. (a) Dynamic memory allocation (b) Efficient insertion and deletion (c) Direct access to any list element (d) Efficient use of memory 18. Which of the following statements about stacks is incorrect? (a) stacks can be implemented using linked lists. (b) stacks are first in, first-out (FIFO) data structures. (c) new nodes can only be added to the top of the stack. 3

(d) the last node (the bottom) of a stack has a null (zero) link. 19. A queue receives the following commands (in pseudo-code): enqueue 4, 6, 8, 3, 1 dequeue 3 elements enqueue 3, 1, 5, 6 dequeue 2 elements What number is at the front of the queue? (a) 3 (b) 4 (c) 5 (d) 6 ANS: (a) 20. Select the incorrect statement. Binary trees (regardless of the order in which the values are inserted into the tree) (a) always have multiple links per node. (b) can be sorted efficiently. (c) always have the same shape for a particular set of data. (d) are nonlinear data structures. Part3. Questions and Answers (30pts) 1. Write a single statement to accomplish each of the following. Assume that each of these statements applies to the same program. (10pts) a) Write a statement that opens the file "oldmast.dat" for reading and assigns the returned file pointer to ofptr. ANS: ofptr = fopen( "oldmast.dat", "r" ); b) Write a statement that opens the file "newmast.dat" for writing (and creation) and assigns the returned file pointer to nfptr. ANS: nfptr = fopen( "newmast.dat", "w" ); c) Write a statement that reads a record from the file "oldmast.dat". The record consists of integer accountnum, string name and floating-point currentbalance. ANS: fscanf( ofptr, "%d%s%f", &accountnum, name, &currentbalance ); d) Write a statement that writes a space-separated record to the file "newmast.dat". The record consists of the integer accountnum, string name and floating-point currentbalance. ANS: fprintf( nfptr, "%d %s %f", accountnum, name, currentbalance ); 2. Please write four functions GetNode, FreeNode, PrintList, and FreeList that can manage the following list data structure. Note: If we call PrintList(rootList); The output should be 100-->235-->440-->888 Node *GetNode() Node *pnode; pnode = (Node*) malloc(sizeof(node)); if(pnode) pnode->nextnode = NULL; return pnode; 4 void FreeNode(Node *ptr) free(ptr);

void PrintList(Node *ptrroot) void FreeList(Node *ptrroot) while(ptrroot!= NULL) Node* ptemp; printf("%d%s", ptrroot->data, ptrroot->nextnode? "-->" : ""); while(ptrroot!= NULL) ptrroot = ptrroot->nextnode; ptemp = ptrroot->nextnode; FreeNode(ptrRoot); printf("\n"); ptrroot = ptemp; 3. Please write down the following binary tree s preorder, inorder, and postorder traversal sequences. (10pts) inorder: A B C D E F G H I preorder: F B A D C E G I H postorder: A C E D B H I G F 5