CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

Similar documents
CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

CS 61B, Midterm #3 and solutions, Spring 1996

CS 170, Spring 2000 Midterm #1 Professor M. Clancy

Linked List using a Sentinel

CS 61B, Spring 1999 MT3 Professor M. Clancy

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

Computer Science Spring 98 Midterm Examination Professor L. Rowe

Review Questions for Final Exam

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CS 61B, Summer 2001 Midterm Exam II Professor Michael Olan

Student Name and ID CS 32, WINTER 2015, PRACTICE MIDTERM I.

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

Midterm Exam. Sample Solutions

Midterm Exam 2 CS 455, Spring 2011

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

CS 162, Lecture 25: Exam II Review. 30 May 2018

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Pointers, Dynamic Data, and Reference Types

A Previous CS 310 Final Exam

Hong Kong University of Science and Technology COMP151: Object Oriented Programming

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Linked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

C:\Temp\Templates. Download This PDF From The Web Site

Assignment of Objects

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

CSC 210, Exam Two Section February 1999

Chapter 17: Linked Lists

Structured Data. CIS 15 : Spring 2007

Come and join us at WebLyceum

CS 61C, Midterm #2, Spring 1997 CS 61C. Spring 1997 Midterm #2. Professor Brian Harvey

Data Structures and Algorithms

Intermediate Programming, Spring 2017*

CS 106X Sample Final Exam #2

C++ Templates. David Camp

Midterm Review. PIC 10B Spring 2018

2. It is possible for a structure variable to be a member of another structure variable.

CS 311 Data Structures and Algorithms, Spring 2009 Midterm Exam Solutions. The Midterm Exam was given in class on Wednesday, March 18, 2009.

Student Name and ID. Problem Maximal Possible Points Received Total Score 150

CSCE 110 PROGRAMMING FUNDAMENTALS

ComS 228 Exam 1. September 27, 2004

Part I: Short Answer (12 questions, 65 points total)

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Do not write in this area A.1 A.2 A.3 A.4 A.5 A.6 B.1 B.2 B.3 TOTAL. Maximum possible points:

CS212 - COMPUTATIONAL STRUCTURES AND ALGORITHMS

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

Exam 3 Chapters 7 & 9

Programming Assignment #2

CS61B, Fall 1995 Midterm #2 K. Yelick

Lab 2: ADT Design & Implementation

CIS 190: C/C++ Programming. Classes in C++

LECTURE 03 LINKED LIST

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

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

IUE Faculty of Engineering and Computer Sciences Spring Semester

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Midterm Practice TA: Brian Choi Section Webpage:

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

COS 126 Midterm 1 Written Exam Fall 2011

PRACTICE MIDTERM EXAM #2

C++ Programming. Classes, Constructors, Operator overloading (Continued) M1 Math Michail Lampis

CSE 333 Midterm Exam 5/10/13

CS536 Spring 2011 FINAL ID: Page 2 of 11

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Ch. 17: Linked Lists. Introduction to Linked Lists

CMSC 202 Midterm Exam 1 Fall 2015

Review Questions II KEY

Come and join us at WebLyceum

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

CS 455 Final Exam Spring 2017 [Bono] May 10, 2017

2 2

Object Oriented Programming COP3330 / CGS5409

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS 247 Software Engineering Principles Midterm Examination **Solutions** Spring 2017

CS 61B, Spring 1998 exam #1 Professor P. N. Hilfinger

CSE 333 Midterm Exam Sample Solution 5/10/13

CSCE 110 PROGRAMMING FUNDAMENTALS

Physics 234: Computational Physics

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

IS0020 Program Design and Software Tools Midterm, Fall, 2004

CS 115 Exam 3, Spring 2010

Example Final Questions Instructions

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

CS 2604 Homework 1 Greatest Hits of C++ Summer 2000

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

CS 106X, Lecture 14 Classes and Pointers

Array Elements as Function Parameters

University of Toronto

Chapter 17: Linked Lists

Transcription:

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy Problem 0 (1 point, 1 minute) Put your login name on each page. Also make sure you have provided the information requested on the first page. Problem 1 (4 points, 10 minutes) A program to print a calender as in programmang assignment 2 includes the following code. for(int month=jan; month<=dec; month++) { PrintHeading (month, year); PrintDates (month, year); The PrintDates function includes the following code. int firstday = DayOfWeek (month, 1, year); for (int k=1; k<=firstday; k++) { cout <<" "; for (int date=1; date <=NumDaysIn (month, year); date++) { cout <<setw(3) <<date; if (IsEndOfWeek (date, firstday)) { cout <<endl; Suppose that when the program is run, a calendar is printed in which every month starts on a Sunday as shown below. January 1996 S M T W T F S 29 30 31 February 1996 S M T W T F S CS 61B, Spring 1996Midterm #1Professor M. Clancy 1

29 March 1996 29 30 31... Part a Which of the following functions is most likely to contain the bug? Circle the name of the probably buggy function below, and briefly describe a flaw in the function that could produce the incorrect output. function most likely to contain the bug PrintHeading PrintDates NumDaysIn IsEndOfWeek DayOfWeek flaw in the function that would cause the incorrect output Part b List the emacs or gdb commands you would type after starting gdb to verify your guess from part a. Problem 2 (4 points, 10 minutes) Each of the C++ program segements below is part of a.cc file that #includes the intlists.h file on the next page. The last statement given in each program segment is incorrect in some way. For each segment, do the following: if the g++ compiler would generate an error message for the last statement in the segment, describe the error message; if the g++ compiler would not generate an error message for the segment, write "no g++ msg" and describe what's wrong with the segment in your own words. file and statement in a main program: g++ error message List list2 = new List; in an incorrect version of intlists.cc: ListNode* ptr = new ListNode; in an incorrect version of intlists.cc: void Print (List list5) { ListNode* ptr = head;... Problem 1 (4 points, 10 minutes) 2

in an incorrect List member function in intlists.cc: ListNode* ptr; ptr->next = 0; Abbreviated intlists.h typedef int InfoType; struct ListNode; class List { public: List (); List (const List&); ~List (); // defined in implementation file // initializes an empty list // copy constructor // destructor // See if the list object is empty. bool IsEmpty (); // Return the list object's lenght. int Length (); // Note in the following that positions in the list // start with 1 (unlike in Scheme). // Insert a new item so that it's at a given position in the // list object (positions of subsequent items increase by 1). // success is set to false if position was out of range. void Delete (int position, bool& success); // Return the item at a given position in the list object. // success is set to false if position was out of range. void Retrieve (int position, InfoType& item, bool& success); // Add an item to the end of the list object. void AddToEnd (InfoType newlastitem); private: ListNode* PtrTo (int position); int size; ListNode* head; // pointer to first thing in the list ; First part of intlists.cc struct ListNode { InfoType info; ListNode* next; Problem 2 (4 points, 10 minutes) 3

; ListNode (InfoType item); // info item and next 0 ListNode (InfoType item, ListNode* ptr); Problem 3 (4 points, 10 minutes) Fill in the blanks in the List member function RemoveAlternateElements whose framework appears below. RemoveAlternateElements should remove and delete alternate nodes in the List object starting with the second node in the list. If the List object is empty or contains only one element, RemoveAlternateElements should leave it unchanged. Two examples of how RemoveAlternateElements should work with longer lists appear below. list before call to RemoveAlternateElements list after call to RemoveAlternateElements Don't change any of the framework code. Also, don't include any calls to other List member functions. void List::RemoveAlternateElements() { if(head!= 0 && head->next!= 0) { for (ListNode* ptr=head; ptr!=0 && ptr->next!=0; ptr=ptr->next) { Problem 4 (4 points, 10 minutes) Recode the RemoveAlternateElements so that it is not a List member function, but instead calls List member functions declared in the intlists.h file on page 5. Problem 3 (4 points, 10 minutes) 4

Problem 5 (3 points, 9 minutes) Consider the following make file. Part a vendmain: vending.o vendmain.o g++ -g vending.o -o vendmain.o vending.o: vending.cc vending.h g++ -g -Wall -fno-builtins vending.cc -c vendmain.o: vendmain.cc vending.h g++ -g -Wall -fno-builtins vendmain.cc -c suppose the command "make vendmain" is given in a working directory containing only the files vending.cc, vending.h, and vendmain.cc. What happens? (Hint: vendmain is not successfully created.) Part b Fix the make file so that the command "make vendmain" does successfully create the executable vendmain. Posted by HKN (Electrical Engineering and Computer Science Honor Society) University of California at Berkeley If you have any questions about these online exams please contact mailto:examfile@hkn.eecs.berkeley.edu Problem 5 (3 points, 9 minutes) 5