Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnwani committed Feb 3, 2014
0 parents commit 0fa69d8
Show file tree
Hide file tree
Showing 29 changed files with 994 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The program reads an n x n grid of letters from a file and prints out all the words that can be found in the grid. Words can be found in the array by starting from any letter and reading left, right, up, down, or along any of the four diagonals. Words must be at least 5 characters long. The list of possible words is included in a file called 'dictionary'. Optimization Methods Class Fall 2012
Binary file added ipch/nwa_3b-98ca56da/nwa_3b-3a62eb06.ipch
Binary file not shown.
Binary file added nwa_3b.sdf
Binary file not shown.
20 changes: 20 additions & 0 deletions nwa_3b.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nwa_3b", "nwa_3b\nwa_3b.vcxproj", "{E1E38B2B-901B-4E07-8151-744253158EFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1E38B2B-901B-4E07-8151-744253158EFE}.Debug|Win32.ActiveCfg = Debug|Win32
{E1E38B2B-901B-4E07-8151-744253158EFE}.Debug|Win32.Build.0 = Debug|Win32
{E1E38B2B-901B-4E07-8151-744253158EFE}.Release|Win32.ActiveCfg = Release|Win32
{E1E38B2B-901B-4E07-8151-744253158EFE}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added nwa_3b.suo
Binary file not shown.
Binary file added nwa_3b/Debug/CL.read.1.tlog
Binary file not shown.
Binary file added nwa_3b/Debug/CL.write.1.tlog
Binary file not shown.
Binary file added nwa_3b/Debug/cl.command.1.tlog
Binary file not shown.
5 changes: 5 additions & 0 deletions nwa_3b/Debug/nwa_3b.Build.CppClean.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
C:\Users\nwani.m\Documents\Visual Studio 2010\Projects\nwa_3b\nwa_3b\Debug\cl.command.1.tlog
C:\Users\nwani.m\Documents\Visual Studio 2010\Projects\nwa_3b\nwa_3b\Debug\CL.read.1.tlog
C:\Users\nwani.m\Documents\Visual Studio 2010\Projects\nwa_3b\nwa_3b\Debug\CL.write.1.tlog
C:\Users\nwani.m\Documents\Visual Studio 2010\Projects\nwa_3b\nwa_3b\Debug\vc100.idb
C:\USERS\NWANI.M\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\NWA_3B\NWA_3B\DEBUG\VC100.PDB
186 changes: 186 additions & 0 deletions nwa_3b/Debug/nwa_3b.log

Large diffs are not rendered by default.

Binary file added nwa_3b/Debug/vc100.idb
Binary file not shown.
Binary file added nwa_3b/Debug/vc100.pdb
Binary file not shown.
40 changes: 40 additions & 0 deletions nwa_3b/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
========================================================================
CONSOLE APPLICATION : nwa_3b Project Overview
========================================================================

AppWizard has created this nwa_3b application for you.

This file contains a summary of what you will find in each of the files that
make up your nwa_3b application.


nwa_3b.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.

nwa_3b.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).

nwa_3b.cpp
This is the main application source file.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named nwa_3b.pch and a precompiled types file named StdAfx.obj.

/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.

/////////////////////////////////////////////////////////////////////////////
27 changes: 27 additions & 0 deletions nwa_3b/binarySearch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <vector>
#include <iostream>



void binarySearch(const vector<string> wordstring, string key) {

int iteration = 0, left = 0, right = wordstring.size()-1, mid;

while (left <= right) {
iteration++;
mid = (int) ((left + right) / 2);
if (key == wordstring[mid]) {
cout << "Match found: " << wordstring[mid] << endl;
iteration++;
return;
}
else if (key > wordstring[mid])
left = mid + 1;
else
right = mid - 1;
}


return;

}
20 changes: 20 additions & 0 deletions nwa_3b/bubbleSort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "dictionary.h"
#include "grid.h"

void bubbleSort(vector<string> &arr, int n) {
bool swapped = true;
int j = 0;
string tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++) {
if (arr[i] > arr[i + 1]) {
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
swapped = true;
}
}
}
}
157 changes: 157 additions & 0 deletions nwa_3b/d_except.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include <strstream>
#include <string>

using namespace std;

class baseException
{
public:
baseException(const string& str = ""):
msgString(str)
{
if (msgString == "")
msgString = "Unspecified exception";
}

string what() const
{
return msgString;
}

// protected allows a derived class to access msgString.
// chapter 13 discusses protected in detail
protected:
string msgString;
};

// failure to allocate memory (new() returns NULL)
class memoryAllocationError: public baseException
{
public:
memoryAllocationError(const string& msg = ""):
baseException(msg)
{}
};

// function argument out of proper range
class rangeError: public baseException
{
public:
rangeError(const string& msg = ""):
baseException(msg)
{}
};

// index out of range
class indexRangeError: public baseException
{
public:
indexRangeError(const string& msg, int i, int size):
baseException()
{
char indexString[80];
ostrstream indexErr(indexString, 80);

indexErr << msg << " index " << i << " size = " << size << ends;
// indexRangeError can modify msgString, since it is in
// the protected section of baseException
msgString = indexString;
}
};

// attempt to erase from an empty container
class underflowError: public baseException
{
public:
underflowError(const string& msg = ""):
baseException(msg)
{}
};

// attempt to insert into a full container
class overflowError: public baseException
{
public:
overflowError(const string& msg = ""):
baseException(msg)
{}
};

// error in expression evaluation
class expressionError: public baseException
{
public:
expressionError(const string& msg = ""):
baseException(msg)
{}
};

// bad object reference
class referenceError: public baseException
{
public:
referenceError(const string& msg = ""):
baseException(msg)
{}
};

// feature not implemented
class notImplementedError: public baseException
{
public:
notImplementedError(const string& msg = ""):
baseException(msg)
{}
};

// date errors
class dateError: public baseException
{
public:
dateError(const string& first, int v, const string& last):
baseException()
{
char dateStr[80];
ostrstream dateErr(dateStr, 80);

dateErr << first << ' ' << v << ' ' << last << ends;
// dateError can modify msgString, since it is in
// the protected section of baseException
msgString = dateStr;
}
};

// error in graph class
class graphError: public baseException
{
public:
graphError(const string& msg = ""):
baseException(msg)
{}
};

// file open error
class fileOpenError: public baseException
{
public:
fileOpenError(const string& fname):
baseException()
{
char errorStr[80];
ostrstream fileErr(errorStr, 80);

fileErr << "Cannot open \"" << fname << "\"" << ends;
// fileOpenError can modify msgString, since it is in
// the protected section of baseException
msgString = errorStr;
}
};

// error in graph class
class fileError: public baseException
{
public:
fileError(const string& msg = ""):
baseException(msg)
{}
};
108 changes: 108 additions & 0 deletions nwa_3b/d_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <iostream>
#include <vector>

#include "d_except.h"

using namespace std;

template <typename T>
class matrix
{
public:
matrix(int numRows = 1, int numCols = 1, const T& initVal = T());
// constructor.
// Postcondition: create array having numRows x numCols elements
// all of whose elements have value initVal

vector<T>& operator[] (int i);
// index operator.
// Precondition: 0 <= i < nRows. a violation of this
// precondition throws the indexRangeError exception.
// Postcondition: if the operator is used on the left-hand
// side of an assignment statement, an element of row i
// is changed

const vector<T>& operator[](int i) const;
// version for constant objects

int rows() const;
// return number of rows
int cols() const;
// return number of columns

void resize(int numRows, int numCols);
// modify the matrix size.
// Postcondition: the matrix has size numRows x numCols.
// any new elements are filled with the default value of type T

private:
int nRows, nCols;
// number of rows and columns

vector<vector<T> > mat;
// matrix is implemented as nRows vectors (rows),
// each having nCols elements (columns)
};

template <typename T>
matrix<T>::matrix(int numRows, int numCols, const T& initVal):
nRows(numRows), nCols(numCols),
mat(numRows, vector<T>(numCols,initVal))
{}

// non-constant version. provides general access to matrix
// elements
template <typename T>
vector<T>& matrix<T>::operator[] (int i)
{
if (i < 0 || i >= nRows)
throw indexRangeError(
"matrix: invalid row index", i, nRows);

return mat[i];
}

// constant version. can be used with a constant object.
// does not allow modification of a matrix element
template <typename T>
const vector<T>& matrix<T>::operator[] (int i) const
{
if (i < 0 || i >= nRows)
throw indexRangeError(
"matrix: invalid row index", i, nRows);

return mat[i];
}

template <typename T>
int matrix<T>::rows() const
{
return nRows;
}

template <typename T>
int matrix<T>::cols() const
{
return nCols;
}

template <typename T>
void matrix<T>::resize(int numRows, int numCols)
{
int i;

// handle case of no size change with a return
if (numRows == nRows && numCols == nCols)
return;

// assign the new matrix size
nRows = numRows;
nCols = numCols;

// resize to nRows rows
mat.resize(nRows);

// resize each row to have nCols columns
for (i=0; i < nRows; i++)
mat[i].resize(nCols);
}
Loading

0 comments on commit 0fa69d8

Please sign in to comment.