Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Objective:

• Usage of constructor/destructor.
• Targets the object transition by reference.
• Character array manipulation.

Task. 14 Array ADT


The Array ADT that we discussed today,
Private Members: int *data ; pointer
to an array of integers
• int capcity; capacity of array pointed by data
• boot isValidIndex ( int index ) return true i f index is within bounds otherwise fa lse.
Public Members:
The class 'Array' should support the following operations
Array( int cap
Department of Software Englneerlng (DSE), PIJ, La ore, Pa Istan. @
Fareed UI Hassan Balg
Page 1 of
Sets 'cap ' to 'capacity' and initializes rest of the data members accordingly.

If user sends any invalid value ( —ve valUe) then sets the cap to zero.
'VA r ray ( )
Free the dynamically al located memory.
int & get Set (int index) ; insert value at
given index of array.

int getCapacity() returns the size of array.


void reSize ( int newCapacity ) resize the array to new capacity. Make sure that
elements in oZd array should be preserved in the new array if possible. If
newCapacity < Ø then make the

capacity equal to ø and deal with data pointer accordingly.


2 String ADT
A class which will provide basic functionalities related to strings.
Note: You are not allowed to use any C/C++ library functions related to strings.

class String
char * data; //points to char array int size; // represents the size of
array pointed by data. public:
String ( ) ; Initializes data to nullptr and size
to 0.
Strin (char c); Initializes data with char c
String(const char Initializes the data with received strin b
allocatin memor on hea
A- You know what to do.
Strin
void input(); Takes Input from console in calling
0b ect.
Index: Receives the Index for
string.
char & at(int index) ; Return Value: reference of array
location re resented b index
Tells whether string is empty or
not? An empty string is one which
boot isEmpty( has data==nullptr or

You might also like