• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/58

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

58 Cards in this Set

  • Front
  • Back

Object-oriented analysis (OOA)

What to do and what not to do.

Object-oriented design (OOD)

models of how it could be done

Encapsulation

Objects combine data and operations

Inheritance

Classes inherit properties from other classes

Polymorphism

Objects determine appropriate operations at execution.

What is cohesive modules?

Cohesive modules perform single well-defined tasks. Good for:
1)Self-documenting


2)Easy to revise


3)Easy to reuse

What is coupling?

Coupling is a measure of depedence among modules. In other words:




1)Loosely coupled modules desired


2)Independence


3)If module fails, all dependent modules will fail


4)Objects should collaborate

Operational contract

1)Documentation


2)Specifies data flow


3)Does not need to specify the task


4)Remember pre and post conditions



Unusal Conditions

Failed?


Garbage in, garbage out logic!

Abstraction

1)Seperates purpose of a module from its implementation


2)Use without concern about the implementation


3)What not how


4)Sort

ADT - Bag (How to design?)

1)What does the problem require?


2)What operations are required to be executed on the data?

ADT- Bag (Behaviors, name 2!)

1)Get size of bag


2)Check if bag is empty


3)Add object to bag


4)Remove an object


etc...

ADT- Specify at least two functions associated with Data and operations

getCurrentSize()


isEmpty()


add(newEntry: ItemType): boolean


remove(anEntry: ItemType): boolean


clearn (): void


getFrequencyOf(anEntry: itemType): integer


contains(anEntry: ItemType): boolean


toVector(): vector

BREAK NEXT SLIDE

Enter Interlude 1 classes

UML

Uniform Modelling Language

Methods what is a get and set called?

Accessor is a get, mutator is a set.

Write the function prototype for a get and set

ItemType getItem() const;


void setItem(const ItemType& theItem);



What do you add to the top of your file to prevent compling errors in terms of includes?

#ifndef _CLASS


#define _CLASS


//code


#endif

Virtual Methods

a member function that you expect to be redefined in derived classes. In other words, polymorphism.

Abstract Classes always have what and cannot be what?

Always have one or more virtual methods and cannot be instantiated.

BREAK-- Not really that was lame af, but onward!

RECURSION: The Mirrors

What is the point of recursion?

Breaking larger problems into smaller ones, such is life.

Recursion will keep reducing in size until it encounters a _____ case;

Base

Memory Structure, when functions are invoked they are pushed onto the _________. Then they are _____ when execution finishes.




Note:


Global / static vars are stored in the static data section

Stack, popped

BREAK-- Onto the next nightmare

WallsMirros CHP 3 PPT

What is an ADT?

A collection of data and a set of operations on that data

Specifications of an ADT indictate...

What an ADT does, but not how its implemented

When using Fixed-Size Arrays you must...

Track array elements used, figure out how methods are to be incorporated.

Defining core methods from this point forward you will just write the functions out based off of the function prototype.

bool ArrayBag<ItemType>::add(const ItemType& newEntry){
//CODE
}

bool roomtoadd = (itemCount<maxItems);


if(roomtoadd){


items[itemCount]=newEntry;
itemCount++;
}
return roomtoadd;

vector<ItemType> ArrayBag<ItemType>::toVector(){
//code
}

vector<ItemType> bagContents;
for(int i=0;i<itemCount;i++)


bagContents.push_back(items[i]);
return bagContents;

int ArrayBag<ItemType>::getCurrentSize() const{


//code
}

bool ArrayBag<ItemType>::isEmpty() const{
//code
}

1)return itemCount;


2)return itemCount==-0;

int ArrayBag<ItemType>::getFrequencyOf(const ItemType& anEntry) const{
//code
}

int freq=0;


int curidx=0;
while(curidx<itemCount){


if(items[curidx]==anEntry){
freuq++;
}
curIndex++;


}
return freq;

bool ArrayBag<ItemType>::contains(const ItemType& anEntry) const{
//code
}

bool isFound=false;
int curIndex=0;
while(!isFound&&(curIndex<itemCount)){
isFound=(anEntry==items[curIndex]);
if(!isFound)
curIndex++;
}
return isFound;

int ArrayBag<ItemType>::getIndexOf(const ItemType& target) const{
//code
}

bool isFound=false;


int results=-1;
int searchIndex=0;
while(!isFound && (searchinedex<itemCount)){
isFound=(items[searchIndex]==target);
if(!isFound)


result=searchIndex;


else


searchIndex++;
}
return result;

bool ArrayBag<ItemTpye>::remove(const ItemType& anEntry){
//code
}

int locatedIndex=getindexOf(anEntry);
bool canRemoveItem= !isEmpty() && (locatedIndex>-1);
if(canRemoveItem)
{


itemCount--;


items[locatedIndex]=items[itemCount];
}
return canRemoveItem;

void ArrayBag<ItemType>::clear(){
//code
}

itemCount=0;

int ArrayBag<ItemType>::getIndexOf(const ItemType& taget, int searchIndex) const{
//code
}

USING RECURSION, kind of a B werd.

int result=-1;


if(searchIndex<itemCount)


{


if(items[searchIndex]==target)


result=searchIndex;


else
result=getindexOf(target, searchIndex+1);


}
return result;

int ArrayBag<ItemType>::countFrequency(const ItemType& target, int searchIndex) const{
//code
}

RECURSION

if(searchIndex<itemCount)
{
if(items[searchIndex]==target)
return 1+countFrequency(target,searchIndex+1);
else
return countFrequncy(target, searchIndex+1);
}
else
return 0;

int ArrayBag<ItemType>::countFrequency(const ItemType& target, int searchIndex) const
{


//code
}

int frequency=0;
if(searchIndex<itemCount)
{
if(items[searchIndex]==target)
frequency =1+countFrequency(target,searchIndex+1);
else
frequency =countFrequency(target,searchIndex+1);
} // end if
} // end if
return frequency

Break -- No serious take a ten minute break

MY MIND IS MELTING

How do you avoid causing dangling pointers?

Set a deleted pointer to null and making sure that declared pointers have a value

How do you declare a virtual method?

Declare methods in base class as virtual.

How do you dynamically declare an array?

int size=50;


doublt *anArray=new double[size];

How do you delete that dynmaicllay declared array?

delete [] anArray;

Write an old array to a new array, dynamically!
Start you out...

double *oldArray=anArray;


anArray= new double[2* arraySize];

for(int i=0;i<arraySize;i++)
anArray[i]=oldArray[i];




delete [] oldArray;

Creating a resizable array to implement ADT BAG

bool Arraybag<ItemType>::add(const ItemType& newEntry){


//code

}

bool hasRoomToAdd = (itemCount < maxItems);
if(!hasRoomToAdd)
{
ItemType* oldArray = items;


items= new ItemType[2*max];
for(int i=0;i<max;i++)


items[i]=oldArray[i];


delete [] oldArray;


max=2*max;


}
items[itemCount]=newEntry;


itemCount++;


return true;



BREAK -- Last leg of it!!

Nodes are usually placed into it...

objects

Class Node

void Noid<ItemType>::setItem(const ItemType& anItem)

item =anItem;

void Node<ItemType>::setNext(Node<ItemType>* nextNodePtr)

next=nextNodePtr;

ItemType Node<ItemType>::getItem() const

return item;

Node<ItemType>* Node<ItemType>::getNext() const

return next;

REFRESHER, give yourself a list of implementations of an ADT (Function list)

getCurrentSize()
isEmpty()
add(newEntry: ItemType): boolean
remove(anEntry: ItemType): boolean
clear(): void
getFrequencyOf(anEntry: ItemType): integer
contains(anEntry: ItemType): boolean
toVector(): vector

Define a basic constructor of a LinkedBag...

Starting you off...

LinkedBag<ItemType>::LinkedBag(): headPtr(nullptr),itemCount(0)

Nothing to see here...

bool LinkedBag<ItemType>::add(const ItemType& newEntry)
{
//code
}

INSERTION AT BEGINNING OF CHAIN

Node<ItemType>* newNodePtr= new Node<ItemType>();
newNodePtr->setItem(newEntry);
newNodePtr->setNext(headPtr);
headPtr=newNodePtr;
itemCount++;



return true;

What is a tranversion operation?

Visits each node in a linked chain

std::vector<ItemType> LinkedBag<ItemType>::toVector() const{
//code
}

std::vector<ItemType> bagContents;
Node<ItemType>* curPtr= headPtr;
int counter=0;
while((curPtr!=nullptr)&&(counter<itemCount))
{
bagContents.push_back(curPtr->getItem());
curPtr=curPtr->getNext();
counter++;
}
return bagContents;

a

a