Skip to content

Commit

Permalink
partial p7, p1 complete p4
Browse files Browse the repository at this point in the history
  • Loading branch information
jasojone committed May 16, 2021
1 parent 12055a4 commit 1574b70
Show file tree
Hide file tree
Showing 71 changed files with 2,528 additions and 83 deletions.
13 changes: 0 additions & 13 deletions cis17cMidTermP4_1.0/nbproject/private/private.xml

This file was deleted.

13 changes: 0 additions & 13 deletions cis17cMidTermP4_1.1/nbproject/private/private.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
Binary file not shown.
89 changes: 89 additions & 0 deletions cis17cMtP1.1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//Libraries
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <chrono>
using namespace std;


//Function Prototypes
void fillAry(int [],int,int,int);
int binSrch(int [],int, int);


int main(int argc, char** argv)
{
//Set the random number seed
srand(static_cast<unsigned int>(time(0)));

//Declare all Variables Here
const int SIZE=80000000;
int *array = new int[SIZE];
int lowRng=0,highRng=SIZE;
int loopCnt = 100000;
int answer = 0;
//double beg = time(0);
//double endd = time(0);
clock_t t;

//Finish initializing the rest of the array
fillAry(array,SIZE,highRng,lowRng);

//Start time
t = clock();
//beg = time(0);
//auto start = high_resolution_clock::now();

//Test the binary search by looping randomly chosen values
for(int i = 0; i < loopCnt; ++i)
{
int value=rand()%(highRng-lowRng+1)+lowRng;
answer += binSrch(array,SIZE,value);
}

// End time
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC;
//endd = time(0);
//auto stop = high_resolution_clock::now();
//auto duration = duration_cast<microseconds>(stop - start);

//Output
cout<<"Array Size: "<<SIZE<<endl;
cout<<"Loop Count: "<<loopCnt<<endl;
cout<<"Operations: "<<answer / loopCnt<<endl;
cout<<"Average Time: "<<time_taken / loopCnt<<" Seconds"<<endl;
// cout<<"Average Time: "<<(endd-beg) / loopCnt<<" Seconds"<<endl;
// cout<<"Average Time: "<<duration.count() / loopCnt<<" Micro Seconds"<<endl;

//Exit
delete [] array;
return 0;
}
int binSrch(int a[],int n, int val)
{
//Initialize Vars
int lowEnd=0;
int highEnd=n-1;
int ops = 3;

//Loop until value found not indexes
do
{
int middle=(highEnd+lowEnd)/2;
ops += 12;
if(val==a[middle])return ops;
else if(val>a[middle])lowEnd=middle+1;
else highEnd=middle-1;
}while(lowEnd<=highEnd);

//Not found
return ops;
}

void fillAry(int a[],int n,int hr,int lr)
{
for(int indx=0;indx<n;indx++){
a[indx]=rand()%(hr-lr+1)+lr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ LDLIBSOPTIONS=

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0.exe
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1.exe

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0.exe: ${OBJECTFILES}
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1.exe: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0 ${OBJECTFILES} ${LDLIBSOPTIONS}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1 ${OBJECTFILES} ${LDLIBSOPTIONS}

${OBJECTDIR}/main.o: main.cpp
${MKDIR} -p ${OBJECTDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ LDLIBSOPTIONS=

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0.exe
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1.exe

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0.exe: ${OBJECTFILES}
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1.exe: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.0 ${OBJECTFILES} ${LDLIBSOPTIONS}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1 ${OBJECTFILES} ${LDLIBSOPTIONS}

${OBJECTDIR}/main.o: main.cpp
${MKDIR} -p ${OBJECTDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}


# Project Name
PROJECTNAME=cis17cMidTermP4_1.1
PROJECTNAME=cis17cMtP1.1

# Active Configuration
DEFAULTCONF=Debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ CND_DISTDIR=dist
# Debug configuration
CND_PLATFORM_Debug=Cygwin-Windows
CND_ARTIFACT_DIR_Debug=dist/Debug/Cygwin-Windows
CND_ARTIFACT_NAME_Debug=cis17cmidtermp4_1.1
CND_ARTIFACT_PATH_Debug=dist/Debug/Cygwin-Windows/cis17cmidtermp4_1.1
CND_ARTIFACT_NAME_Debug=cis17cmtp1.1
CND_ARTIFACT_PATH_Debug=dist/Debug/Cygwin-Windows/cis17cmtp1.1
CND_PACKAGE_DIR_Debug=dist/Debug/Cygwin-Windows/package
CND_PACKAGE_NAME_Debug=cis17cmidtermp41.1.tar
CND_PACKAGE_PATH_Debug=dist/Debug/Cygwin-Windows/package/cis17cmidtermp41.1.tar
CND_PACKAGE_NAME_Debug=cis17cmtp1.1.tar
CND_PACKAGE_PATH_Debug=dist/Debug/Cygwin-Windows/package/cis17cmtp1.1.tar
# Release configuration
CND_PLATFORM_Release=Cygwin-Windows
CND_ARTIFACT_DIR_Release=dist/Release/Cygwin-Windows
CND_ARTIFACT_NAME_Release=cis17cmidtermp4_1.1
CND_ARTIFACT_PATH_Release=dist/Release/Cygwin-Windows/cis17cmidtermp4_1.1
CND_ARTIFACT_NAME_Release=cis17cmtp1.1
CND_ARTIFACT_PATH_Release=dist/Release/Cygwin-Windows/cis17cmtp1.1
CND_PACKAGE_DIR_Release=dist/Release/Cygwin-Windows/package
CND_PACKAGE_NAME_Release=cis17cmidtermp41.1.tar
CND_PACKAGE_PATH_Release=dist/Release/Cygwin-Windows/package/cis17cmidtermp41.1.tar
CND_PACKAGE_NAME_Release=cis17cmtp1.1.tar
CND_PACKAGE_PATH_Release=dist/Release/Cygwin-Windows/package/cis17cmtp1.1.tar
#
# include compiler specific variables
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ CND_BUILDDIR=build
CND_DLIB_EXT=dll
NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1
OUTPUT_BASENAME=cis17cmidtermp4_1.1
PACKAGE_TOP_DIR=cis17cmidtermp41.1/
OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1
OUTPUT_BASENAME=cis17cmtp1.1
PACKAGE_TOP_DIR=cis17cmtp1.1/

# Functions
function checkReturnCode
Expand Down Expand Up @@ -60,15 +60,15 @@ mkdir -p ${NBTMPDIR}

# Copy files and create directories and links
cd "${TOP}"
makeDirectory "${NBTMPDIR}/cis17cmidtermp41.1/bin"
makeDirectory "${NBTMPDIR}/cis17cmtp1.1/bin"
copyFileToTmpDir "${OUTPUT_PATH}.exe" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}.exe" 0755


# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmidtermp41.1.tar
rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmtp1.1.tar
cd ${NBTMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmidtermp41.1.tar *
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmtp1.1.tar *
checkReturnCode

# Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ CND_BUILDDIR=build
CND_DLIB_EXT=dll
NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1
OUTPUT_BASENAME=cis17cmidtermp4_1.1
PACKAGE_TOP_DIR=cis17cmidtermp41.1/
OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.1
OUTPUT_BASENAME=cis17cmtp1.1
PACKAGE_TOP_DIR=cis17cmtp1.1/

# Functions
function checkReturnCode
Expand Down Expand Up @@ -60,15 +60,15 @@ mkdir -p ${NBTMPDIR}

# Copy files and create directories and links
cd "${TOP}"
makeDirectory "${NBTMPDIR}/cis17cmidtermp41.1/bin"
makeDirectory "${NBTMPDIR}/cis17cmtp1.1/bin"
copyFileToTmpDir "${OUTPUT_PATH}.exe" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}.exe" 0755


# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmidtermp41.1.tar
rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmtp1.1.tar
cd ${NBTMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmidtermp41.1.tar *
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17cmtp1.1.tar *
checkReturnCode

# Cleanup
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions cis17cMtP1.1/nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<data xmlns="http://www.netbeans.org/ns/make-project-private/1">
<activeConfTypeElem>1</activeConfTypeElem>
<activeConfIndexElem>0</activeConfIndexElem>
</data>
</project-private>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<type>org.netbeans.modules.cnd.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>cis17cMidTermP4_1.0</name>
<name>cis17cMtP1.1</name>
<c-extensions>cpp</c-extensions>
<cpp-extensions/>
<header-extensions/>
<sourceEncoding>UTF-8</sourceEncoding>
<make-dep-projects/>
<sourceRootList/>
<confList>
Expand All @@ -19,7 +20,6 @@
<type>1</type>
</confElem>
</confList>
<sourceEncoding>UTF-8</sourceEncoding>
<formatting>
<project-formatting-style>false</project-formatting-style>
</formatting>
Expand Down
5 changes: 5 additions & 0 deletions cis17cMtP1/.dep.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This code depends on make tool being used
DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES}))
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
File renamed without changes.
80 changes: 80 additions & 0 deletions cis17cMtP1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//Libraries
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <chrono>

using namespace std;
using namespace chrono;

//Function Prototypes
void fillAry(int [],int,int,int);
int linSrch(int [],int, int);


int main(int argc, char** argv)
{
//Set the random number seed
srand(static_cast<unsigned int>(time(0)));

//Declare all Variables Here
const int SIZE=1000000;
int *array = new int[SIZE];
int lowRng=0,highRng=SIZE;
int loopCnt = 10000;
int answer = 0;
double beg = time(0);
double endd = time(0);

//Finish initializing the rest of the array
fillAry(array,SIZE,highRng,lowRng);


// Start time
beg = time(0);
auto start = high_resolution_clock::now();

//Test the linear search by looping randomly chosen values
for(int i = 0; i < loopCnt; ++i)
{
int value=rand()%(highRng-lowRng+1)+lowRng;
answer += linSrch(array,SIZE,value);
}
// End time
endd = time(0);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);

//Output results
cout<<"Array Size: "<<SIZE<<endl;
cout<<"Loop Count: "<<loopCnt<<endl;
cout<<"Operations: "<<answer / loopCnt<<endl;
cout<<"Average Time: "<<(endd-beg) / loopCnt<<" Seconds"<<endl;
cout<<"Average Time: "<<duration.count() / loopCnt<<" Micro Seconds"<<endl;

//Exit
delete [] array;
return 0;
}
int linSrch(int a[],int n, int val)
{

int ops = 0;

//Loop until value found
for(int indx=0;indx<n;indx++)
{
if(val==a[indx])return ops;
ops += 5;
}
//Not found
return ops;
}

void fillAry(int a[],int n,int hr,int lr)
{
for(int indx=0;indx<n;indx++)
{
a[indx]=rand()%(hr-lr+1)+lr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ LDLIBSOPTIONS=

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1.exe
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.exe

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1.exe: ${OBJECTFILES}
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.exe: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1 ${OBJECTFILES} ${LDLIBSOPTIONS}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1 ${OBJECTFILES} ${LDLIBSOPTIONS}

${OBJECTDIR}/main.o: main.cpp
${MKDIR} -p ${OBJECTDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ LDLIBSOPTIONS=

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1.exe
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.exe

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1.exe: ${OBJECTFILES}
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1.exe: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmidtermp4_1.1 ${OBJECTFILES} ${LDLIBSOPTIONS}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cmtp1 ${OBJECTFILES} ${LDLIBSOPTIONS}

${OBJECTDIR}/main.o: main.cpp
${MKDIR} -p ${OBJECTDIR}
Expand Down
Loading

0 comments on commit 1574b70

Please sign in to comment.