CPSC 260 - Midterm 1 - 2006 T2 - Questio...
CPSC_260_-_Midterm_1_-_2006_T2_-_Questions.pdf-MARKING KEY The University of British
Showing 7-9 out of 12
CPSC 260 - Midterm 1 - 2006 T2 - Questions.pdf-MAR...
CPSC_260_-_Midterm_1_-_2006_T2_-_Questions.pdf-MARKING KEY The University of British
CPSC 260 - Midterm 1 - 2006 T2 - Qu...
CPSC_260_-_Midterm_1_-_2006_T2_-_Questions.pdf-MARKING KEY The University of British
Page 7
Name:
MARKING KEY
Student No:
MARKING KEY
CPSC 260 Midterm Exam #1
Thursday, February 15, 2007
Page 7 of
12
2. The software life cycle { 7 marks }
Below is the Software Life Cycle
diagram that was discussed in lecture and which appears in the course
notes. For each empty
box in the diagram, choose the best
answer from among the terms on page 2 of
this exam and write its number
inside the box. Do not
write the names of the phases; write the numbers
that correspond to the missing labels for the boxes.
There are seven (7) boxes to fill. Make sure that you fill all of them. Don’t forget the one in the middle!
situation of concern
52
specification
58
11
verification
26
maintenance
testing
51
47
42
maintenance
verification
documentation
refinement
testing
implementation
design
requirements
specification
validation
situation of concern
production


Page 8
Name:
MARKING KEY
Student No:
MARKING KEY
CPSC 260 Midterm Exam #1
Thursday, February 15, 2007
Page 8 of
12
Below is the header file
IntSet.h
for the
IntSet
class that is essentially the same as what was used
in Lab 2 except for the addition of an overloaded “minus” operator. You may assume that the class
declaration is correct and that it is functionally the same as what was used in Lab 2. The class
declaration will be useful when you answer the next three
questions on this exam.
class IntSet
{
public:
IntSet();
IntSet( const IntSet& other );
~IntSet();
void insert( int entry );
void erase( int target );
int size() const;
int get( int index ) const;
bool find( int target ) const;
void print() const;
IntSet& operator=( const IntSet& other );
IntSet operator+( const IntSet& other ) const;
IntSet operator*( const IntSet& other ) const;
IntSet operator-( const IntSet& other ) const;
private:
int* data;
// pointer to array
int
max;
// maximum possible number of integers in array
int
count;
// actual number of integers in the array
const static int INITSIZE
= 10;
// initial size of array
const static int INCREMENT = 5
// amount to enlarge full array
void copy( const IntSet& other );
void clear( void );
void grow( int amount );
};
Continue on to the next page…
You may remove this page from the exam booklet.


Page 9
Name:
MARKING KEY
Student No:
MARKING KEY
CPSC 260 Midterm Exam #1
Thursday, February 15, 2007
Page 9 of
12
3. Dealing with dynamic storage { 10 marks }
Using the declaration on page 8 of this exam, and assuming the implementation that was provided to you
in Lab 2 for
IntSet
, write the definition for the
grow()
method as it should appear in the source file
IntSet.cpp
. Be careful to use the parameter
amount
correctly, as it was in the implementation for
the lab.
Do not
use any of the other methods in the class for your implementation. Write all of the code using
basic operations on the member variables of the
IntSet
object.
Be sure to always
include an appropriate precondition
and postcondition
, and to follow all of the
recommended programming guidelines for this course. You do not
have to include the class invariant.
ANSWER:
void IntSet::grow( int amount )
// Private member helper function
// PRE:
amount > 0
AND
//
there is enough memory to allocate a larger array
// POST: 'max' is increased by 'amount' and the contents of
//
the array ‘data’ are copied into a new array that
//
can hold 'amount' more elements
{
int* temp;
max = max + amount;
temp = new int[ max ];
for ( int i = 0; i < count; i++ )
{
temp[ i ] = data[ i ];
}
delete [] data;
data = temp;
}


Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
UBC Vancouver
UBC_Vancouver
School:
Object-Oriented_Programming
Course:
Great resource for chem class. Had all the past labs and assignments
Leland P.
Santa Clara University
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades

Students also viewed documents