repo update

This commit is contained in:
2022-04-04 15:41:31 -05:00
parent 1156c003f9
commit 16003d1715
20 changed files with 13101 additions and 13046 deletions

74
.gitignore vendored
View File

@@ -1,38 +1,38 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Other
/.vscode
*.pdf
*.zip
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Other
/.vscode
*.pdf
*.zip
*.code-workspace

View File

@@ -1,188 +1,188 @@
/**
* @file ReadSTL.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief A C++ file containing the functionality need to read in a .stl file.
* The ReadSTL class allows the min/max coordinates and total count of the STL
* facets be stored. The appropriate getters are also included.
* @version 1.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
class ReadSTL {
private:
int numFacet;
double Xmin;
double Xmax;
double Ymin;
double Ymax;
double Zmin;
double Zmax;
public:
ReadSTL(string filename) {
// Instantiate variables
numFacet = 0;
// Input Stream setup
ifstream inputfile(filename, ifstream::in);
string line;
string token;
string solidName;
// Solid header line
getline(inputfile, line);
// Input string stream for each line
istringstream lineStream(line);
// Iterate stream past "solid"
lineStream >> token;
// Get solid name
lineStream >> solidName;
do {
// Process entire solid, looping through each facet
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
// Get first word in line
lineStream >> token;
if(!token.compare("facet")) {
// Facet header
// Iterate past "normal"
lineStream >> token;
// No additional functionality required for facet normal vectors
// Normal X
lineStream >> token;
// Normal Y
lineStream >> token;
// Z Normal
lineStream >> token;
// End facet header
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if (!token.compare("outer")) {
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if(!token.compare("vertex")) {
// Process vertex
// Coord double value
double coord;
// X Coord
lineStream >> token;
coord = stod(token);
if((coord < Xmin) || numFacet == 0) {
Xmin = coord;
}
if((coord > Xmax) || numFacet == 0) {
Xmax = coord;
}
// Y Coord
lineStream >> token;
coord = stod(token);
if((coord < Ymin) || numFacet == 0) {
Ymin = coord;
}
if((coord > Ymax) || numFacet == 0) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
if((coord < Zmin) || numFacet == 0) {
Zmin = coord;
}
if((coord > Zmax) || numFacet == 0) {
Zmax = coord;
}
} // End vertex line
} while(token.compare("endloop")); // Endloop
}
}while(token.compare("endfacet")); // Endfacet
// Iterate facet counter
numFacet++;
}
}while(token.compare("endsolid"));
// Close file
inputfile.close();
}
/**
* @brief Getter for the number of facets
*
* @return int
*/
int getNumFacets(){
return numFacet;
}
/**
* @brief Getter for Xmin
*
* @return double
*/
double getXmin() {
return Xmin;
}
/**
* @brief Getter for Xmax
*
* @return double
*/
double getXmax() {
return Xmax;
}
/**
* @brief Getter for Ymin
*
* @return double
*/
double getYmin() {
return Ymin;
}
/**
* @brief Getter for Ymax
*
* @return double
*/
double getYmax() {
return Ymax;
}
/**
* @brief Getter for Zmin
*
* @return double
*/
double getZmin() {
return Zmin;
}
/**
* @brief Getter for Zmax
*
* @return double
*/
double getZmax() {
return Zmax;
}
};
/**
* @file ReadSTL.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief A C++ file containing the functionality need to read in a .stl file.
* The ReadSTL class allows the min/max coordinates and total count of the STL
* facets be stored. The appropriate getters are also included.
* @version 1.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
class ReadSTL {
private:
int numFacet;
double Xmin;
double Xmax;
double Ymin;
double Ymax;
double Zmin;
double Zmax;
public:
ReadSTL(string filename) {
// Instantiate variables
numFacet = 0;
// Input Stream setup
ifstream inputfile(filename, ifstream::in);
string line;
string token;
string solidName;
// Solid header line
getline(inputfile, line);
// Input string stream for each line
istringstream lineStream(line);
// Iterate stream past "solid"
lineStream >> token;
// Get solid name
lineStream >> solidName;
do {
// Process entire solid, looping through each facet
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
// Get first word in line
lineStream >> token;
if(!token.compare("facet")) {
// Facet header
// Iterate past "normal"
lineStream >> token;
// No additional functionality required for facet normal vectors
// Normal X
lineStream >> token;
// Normal Y
lineStream >> token;
// Z Normal
lineStream >> token;
// End facet header
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if (!token.compare("outer")) {
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if(!token.compare("vertex")) {
// Process vertex
// Coord double value
double coord;
// X Coord
lineStream >> token;
coord = stod(token);
if((coord < Xmin) || numFacet == 0) {
Xmin = coord;
}
if((coord > Xmax) || numFacet == 0) {
Xmax = coord;
}
// Y Coord
lineStream >> token;
coord = stod(token);
if((coord < Ymin) || numFacet == 0) {
Ymin = coord;
}
if((coord > Ymax) || numFacet == 0) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
if((coord < Zmin) || numFacet == 0) {
Zmin = coord;
}
if((coord > Zmax) || numFacet == 0) {
Zmax = coord;
}
} // End vertex line
} while(token.compare("endloop")); // Endloop
}
}while(token.compare("endfacet")); // Endfacet
// Iterate facet counter
numFacet++;
}
}while(token.compare("endsolid"));
// Close file
inputfile.close();
}
/**
* @brief Getter for the number of facets
*
* @return int
*/
int getNumFacets(){
return numFacet;
}
/**
* @brief Getter for Xmin
*
* @return double
*/
double getXmin() {
return Xmin;
}
/**
* @brief Getter for Xmax
*
* @return double
*/
double getXmax() {
return Xmax;
}
/**
* @brief Getter for Ymin
*
* @return double
*/
double getYmin() {
return Ymin;
}
/**
* @brief Getter for Ymax
*
* @return double
*/
double getYmax() {
return Ymax;
}
/**
* @brief Getter for Zmin
*
* @return double
*/
double getZmin() {
return Zmin;
}
/**
* @brief Getter for Zmax
*
* @return double
*/
double getZmax() {
return Zmax;
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,26 @@
solid Shape
facet normal 0.00441668 -0.0110034 -0.99993
outer loop
vertex 3.44187 5.90737 22.4502
vertex 3.45978 5.88253 22.4505
vertex 3.20279 5.6495 22.4519
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
solid Shape
facet normal 0.00441668 -0.0110034 -0.99993
outer loop
vertex 3.44187 5.90737 22.4502
vertex 3.45978 5.88253 22.4505
vertex 3.20279 5.6495 22.4519
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
endsolid Shape

View File

@@ -1,36 +1,36 @@
/**
* @file main.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief The main driver file used to demonstrate the functionality of the
* ReadSTL class. The user enters the file location of the STL file as a
* command line arg and the console returns the min/max coords of the solid's
* facets as well as the total number of facets.
* @version 1.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <iostream>
#include "ReadSTL.cpp"
using namespace std;
int main(int argc, char** argv) {
ReadSTL stl1(argv[1]);
cout << endl << "File read successfully!" << endl;
// Formatted file info output
cout << "Facets in file: " << stl1.getNumFacets() << endl << endl;
cout << "X Min: " << stl1.getXmin() << endl;
cout << "X Max: " << stl1.getXmax() << endl << endl;
cout << "Y Min: " << stl1.getYmin() << endl;
cout << "Y Max: " << stl1.getYmax() << endl << endl;
cout << "Z Min: " << stl1.getZmin() << endl;
cout << "Z Max: " << stl1.getZmax() << endl << endl;
return 0;
}
/**
* @file main.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief The main driver file used to demonstrate the functionality of the
* ReadSTL class. The user enters the file location of the STL file as a
* command line arg and the console returns the min/max coords of the solid's
* facets as well as the total number of facets.
* @version 1.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <iostream>
#include "ReadSTL.cpp"
using namespace std;
int main(int argc, char** argv) {
ReadSTL stl1(argv[1]);
cout << endl << "File read successfully!" << endl;
// Formatted file info output
cout << "Facets in file: " << stl1.getNumFacets() << endl << endl;
cout << "X Min: " << stl1.getXmin() << endl;
cout << "X Max: " << stl1.getXmax() << endl << endl;
cout << "Y Min: " << stl1.getYmin() << endl;
cout << "Y Max: " << stl1.getYmax() << endl << endl;
cout << "Z Min: " << stl1.getZmin() << endl;
cout << "Z Max: " << stl1.getZmax() << endl << endl;
return 0;
}

View File

@@ -1,25 +1,25 @@
# lab1 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = ReadSTL.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab1
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
# lab1 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = ReadSTL.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab1
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f *.d

View File

@@ -1,94 +1,94 @@
/**
* @file main.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief A main driver that provides some rudimentary tests for row.cpp
* Tests involving memory leaks were tested using valgrind via the command:
* `valgrind ./lab2` Test output was left in submission to signify modules
* that have successfully passed and provide further clarity of testing
* methods.
* @version 1.0
* @date 2022-03-22
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <iostream>
#include "row.h"
using namespace std;
int main() {
// Test Setup
int length;
double testValue;
cout << "Enter the desired length for the row matrix:" << endl;
cin >> length;
cout << "Enter a double value to test as row data element:" << endl;
cin >> testValue;
cout << "Test - Constructor / Access Operator" << endl;
// Test: Constructor
Row row1(length);
// Test: Access Operator (non const)
try{
// All elements are accessed
for(int i = 0; i < length; i++){
cout << row1[i] << " ";
}
cout << endl;
// First element shown as 0
cout << row1[0] << endl;
// First element is assigned the test value
row1[0] = testValue;
// First element is now the test value
cout << row1[0] << endl;
// Throws OOB Exception
cout << row1[length+1] << endl;
}catch(const out_of_range e){
cout << "Out of Range Exception Successfully Caught" << endl;
}
cout << "Test - Constructor / Access Operator: PASS" << endl;
cout << "Test - Copy Constructor / Access Operator (const)" << endl;
// Test: Copy Constructor
const Row row1Copy(row1);
// Test: Access Operator (const)
try{
for(int i = 0; i < length; i++){
cout << row1Copy[i] << " ";
}
cout << endl;
// First element is the same as the original Row object's
cout << row1Copy[0] << endl;
// Throws OOB Exception
cout << row1Copy[length+1];
}catch(const out_of_range e){
cout << "Out of Range Exception Successfully Caught" << endl;
}
cout << "Test - Copy Constructor / Access Operator (const): PASS" << endl;
// Test: Assignment Operator
Row row2(length);
// Set new row object equal to another row object
row2 = row1;
// Show that the elements are identical to the original row object
for(int i = 0; i < length; i++){
cout << row2[i] << " ";
}
cout << endl;
// Test: Clear
cout << "Test - Clear" << endl;
row2.clear();
for(int i = 0; i < length; i++){
cout << row2[i] << " ";
}
cout << endl;
cout << "Test - Clear: PASS" << endl;
// Tested for memory leaks using valgrind:
// Result: "All heap blocks were freed -- no leaks are possible"
return 0;
}
/**
* @file main.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief A main driver that provides some rudimentary tests for row.cpp
* Tests involving memory leaks were tested using valgrind via the command:
* `valgrind ./lab2` Test output was left in submission to signify modules
* that have successfully passed and provide further clarity of testing
* methods.
* @version 1.0
* @date 2022-03-22
*
* @copyright Copyright (c) 2022
*
*/
#include <string>
#include <iostream>
#include "row.h"
using namespace std;
int main() {
// Test Setup
int length;
double testValue;
cout << "Enter the desired length for the row matrix:" << endl;
cin >> length;
cout << "Enter a double value to test as row data element:" << endl;
cin >> testValue;
cout << "Test - Constructor / Access Operator" << endl;
// Test: Constructor
Row row1(length);
// Test: Access Operator (non const)
try{
// All elements are accessed
for(int i = 0; i < length; i++){
cout << row1[i] << " ";
}
cout << endl;
// First element shown as 0
cout << row1[0] << endl;
// First element is assigned the test value
row1[0] = testValue;
// First element is now the test value
cout << row1[0] << endl;
// Throws OOB Exception
cout << row1[length+1] << endl;
}catch(const out_of_range e){
cout << "Out of Range Exception Successfully Caught" << endl;
}
cout << "Test - Constructor / Access Operator: PASS" << endl;
cout << "Test - Copy Constructor / Access Operator (const)" << endl;
// Test: Copy Constructor
const Row row1Copy(row1);
// Test: Access Operator (const)
try{
for(int i = 0; i < length; i++){
cout << row1Copy[i] << " ";
}
cout << endl;
// First element is the same as the original Row object's
cout << row1Copy[0] << endl;
// Throws OOB Exception
cout << row1Copy[length+1];
}catch(const out_of_range e){
cout << "Out of Range Exception Successfully Caught" << endl;
}
cout << "Test - Copy Constructor / Access Operator (const): PASS" << endl;
// Test: Assignment Operator
Row row2(length);
// Set new row object equal to another row object
row2 = row1;
// Show that the elements are identical to the original row object
for(int i = 0; i < length; i++){
cout << row2[i] << " ";
}
cout << endl;
// Test: Clear
cout << "Test - Clear" << endl;
row2.clear();
for(int i = 0; i < length; i++){
cout << row2[i] << " ";
}
cout << endl;
cout << "Test - Clear: PASS" << endl;
// Tested for memory leaks using valgrind:
// Result: "All heap blocks were freed -- no leaks are possible"
return 0;
}

View File

@@ -1,25 +1,25 @@
# lab2 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = main.cpp row.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab2
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
# lab2 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = main.cpp row.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab2
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f *.d

View File

@@ -1,51 +1,51 @@
#ifndef row_h
#define row_h
class Row{
public:
/* Parameterized constructor
* Takes in length and creates a row matrix with values cleared
* to zero
*/
Row(unsigned int length);
/* Copy constructor
* Create a new row matrix with the same size and values as the
* from matrix
*/
Row(const Row& from);
/* Destructor
* Correctly delete any heap memory
*/
~Row();
/* Access operator (const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double operator[](unsigned int column) const;
/* Access operator (non const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double& operator[] (unsigned int column);
/* Assignment operator
* 1. Check if two sides are the same object
* 2. Delete the current row matrix
* 3. Create a new row matrix with the same size and values as
* the rhs matrix
*/
Row& operator= (const Row& rhs);
/* Clear all data values to zero
*/
void clear();
private:
// Row matrix data
double * row_data;
// Size of row matrix
unsigned int length;
};
#endif
#ifndef row_h
#define row_h
class Row{
public:
/* Parameterized constructor
* Takes in length and creates a row matrix with values cleared
* to zero
*/
Row(unsigned int length);
/* Copy constructor
* Create a new row matrix with the same size and values as the
* from matrix
*/
Row(const Row& from);
/* Destructor
* Correctly delete any heap memory
*/
~Row();
/* Access operator (const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double operator[](unsigned int column) const;
/* Access operator (non const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double& operator[] (unsigned int column);
/* Assignment operator
* 1. Check if two sides are the same object
* 2. Delete the current row matrix
* 3. Create a new row matrix with the same size and values as
* the rhs matrix
*/
Row& operator= (const Row& rhs);
/* Clear all data values to zero
*/
void clear();
private:
// Row matrix data
double * row_data;
// Size of row matrix
unsigned int length;
};
#endif

View File

@@ -1,25 +1,25 @@
# lab3 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = main.cpp row.cpp matrix.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab3
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
# lab3 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS =
# Change w/ every new project
SOURCES = main.cpp row.cpp matrix.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab3
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f *.d

View File

@@ -1,51 +1,51 @@
#ifndef row_h
#define row_h
class Row{
public:
/* Parameterized constructor
* Takes in length and creates a row matrix with values cleared
* to zero
*/
Row(unsigned int length);
/* Copy constructor
* Create a new row matrix with the same size and values as the
* from matrix
*/
Row(const Row& from);
/* Destructor
* Correctly delete any heap memory
*/
~Row();
/* Access operator (const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double operator[](unsigned int column) const;
/* Access operator (non const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double& operator[] (unsigned int column);
/* Assignment operator
* 1. Check if two sides are the same object
* 2. Delete the current row matrix
* 3. Create a new row matrix with the same size and values as
* the rhs matrix
*/
Row& operator= (const Row& rhs);
/* Clear all data values to zero
*/
void clear();
private:
// Row matrix data
double * row_data;
// Size of row matrix
unsigned int length;
};
#endif
#ifndef row_h
#define row_h
class Row{
public:
/* Parameterized constructor
* Takes in length and creates a row matrix with values cleared
* to zero
*/
Row(unsigned int length);
/* Copy constructor
* Create a new row matrix with the same size and values as the
* from matrix
*/
Row(const Row& from);
/* Destructor
* Correctly delete any heap memory
*/
~Row();
/* Access operator (const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double operator[](unsigned int column) const;
/* Access operator (non const version)
* Allow access to row matrix data
* Should return an exception if column is too large
*/
double& operator[] (unsigned int column);
/* Assignment operator
* 1. Check if two sides are the same object
* 2. Delete the current row matrix
* 3. Create a new row matrix with the same size and values as
* the rhs matrix
*/
Row& operator= (const Row& rhs);
/* Clear all data values to zero
*/
void clear();
private:
// Row matrix data
double * row_data;
// Size of row matrix
unsigned int length;
};
#endif

View File

@@ -1,25 +1,25 @@
# lab4 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS = -lX11
# Change w/ every new project
SOURCES = main.cpp gcontext.cpp x11context.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab4
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) -o $@ $(OBJECTS) $(LFLAGS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
# lab4 Makefile
CC = g++
CFLAGS = -c -MMD -g
LFLAGS = -lX11
# Change w/ every new project
SOURCES = main.cpp gcontext.cpp x11context.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab4
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) -o $@ $(OBJECTS) $(LFLAGS)
-include *.d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f *.d

View File

@@ -1,25 +1,25 @@
#include <iostream>
using namespace std;
/*
void swap(int x, int y) {
int temp = x;
x = y;
y = temp;
}
*/
void swap(int* x, int* y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int A = 2;
int B = 8;
// Pass in addresses to be
swap(&A,&B);
cout << "A: " << A << " B: " << B << endl;
return 0;
#include <iostream>
using namespace std;
/*
void swap(int x, int y) {
int temp = x;
x = y;
y = temp;
}
*/
void swap(int* x, int* y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int A = 2;
int B = 8;
// Pass in addresses to be
swap(&A,&B);
cout << "A: " << A << " B: " << B << endl;
return 0;
}

View File

@@ -1,23 +1,23 @@
#makefile comment
CC = g++
CFLAGS = -C
LFLAGS =
SOURCES = math.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = making_ex1
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $(EXECUTABLE) $(OBJECTS)
%.o:%.cpp
$(CC) $(CFLAGS) $<
-include
clean:
rm -f *.o
rm -f $(EXECUTABLE)
#makefile comment
CC = g++
CFLAGS = -C
LFLAGS =
SOURCES = math.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = making_ex1
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $(EXECUTABLE) $(OBJECTS)
%.o:%.cpp
$(CC) $(CFLAGS) $<
-include
clean:
rm -f *.o
rm -f $(EXECUTABLE)
rm -f *.d

View File

@@ -1,71 +1,71 @@
#include <iostream>
#include "dog.h"
using namespace std;
Dog::Dog(int age, int namelength, char * name) {
this->age = age;
this->namelength = namelength;
this->name = new char[namelength];
for(int i = 0; i < namelength; i++){
this->name[i] = name[i];
}
}
Dog::~Dog(){
if(this->namelength > 0){
delete[] this->name;
}
}
Dog::Dog(const Dog& from){
this->age = from.age;
this->namelength = from.namelength;
this->name = new char[this->namelength];
for(int i = 0; i< this->namelength; i++){
this->name[i] = from.name[i];
}
}
Dog& Dog::operator=(const Dog& rhs){
if(&rhs != this){
// delete existing memory
if(namelength > 0){
delete[] this->name;
}
this->age = rhs.age;
this->namelength = rhs.namelength;
this->name = new char[namelength];
for(int i = 0; i < namelength; i++){
this->name[i] = rhs.name[i];
}
}
return *this;
}
char Dog::operator[](int index) const{
if(index >= namelength){
// Use with try/catch when called in main do exception e.what()
throw(out_of_range("index is larger than name length"));
}
return name[index];
}
char& Dog::operator[](int index){
if(index >= namelength){
// Use with try/catch when called in main do exception e.what()
throw(out_of_range("index is larger than name length"));
}
return name[index];
}
Dog Dog::puppy(int namelength, char * name){
Dog p(0, namelength, name);
return p;
}
ostream& operator<<(ostream& os, const Dog& d){
for(int i = 0; i< d.namelength; i++) {
os << d[i];
}
return os;
#include <iostream>
#include "dog.h"
using namespace std;
Dog::Dog(int age, int namelength, char * name) {
this->age = age;
this->namelength = namelength;
this->name = new char[namelength];
for(int i = 0; i < namelength; i++){
this->name[i] = name[i];
}
}
Dog::~Dog(){
if(this->namelength > 0){
delete[] this->name;
}
}
Dog::Dog(const Dog& from){
this->age = from.age;
this->namelength = from.namelength;
this->name = new char[this->namelength];
for(int i = 0; i< this->namelength; i++){
this->name[i] = from.name[i];
}
}
Dog& Dog::operator=(const Dog& rhs){
if(&rhs != this){
// delete existing memory
if(namelength > 0){
delete[] this->name;
}
this->age = rhs.age;
this->namelength = rhs.namelength;
this->name = new char[namelength];
for(int i = 0; i < namelength; i++){
this->name[i] = rhs.name[i];
}
}
return *this;
}
char Dog::operator[](int index) const{
if(index >= namelength){
// Use with try/catch when called in main do exception e.what()
throw(out_of_range("index is larger than name length"));
}
return name[index];
}
char& Dog::operator[](int index){
if(index >= namelength){
// Use with try/catch when called in main do exception e.what()
throw(out_of_range("index is larger than name length"));
}
return name[index];
}
Dog Dog::puppy(int namelength, char * name){
Dog p(0, namelength, name);
return p;
}
ostream& operator<<(ostream& os, const Dog& d){
for(int i = 0; i< d.namelength; i++) {
os << d[i];
}
return os;
}

View File

@@ -1,18 +1,18 @@
using namespace std;
class Dog {
public:
Dog(int age, int namelength, char * name);
// has to be dog object, not reference
static Dog Dog::puppy(int namelength, char *name);
Dog(const Dog& from);
~Dog();
Dog& operator=(const Dog& rhs);
char operator[](int index) const;
char& operator[](int index);
friend ostream& operator<<(ostream& os, const Dog& d);
private:
int age;
int namelength;
char * name;
using namespace std;
class Dog {
public:
Dog(int age, int namelength, char * name);
// has to be dog object, not reference
static Dog Dog::puppy(int namelength, char *name);
Dog(const Dog& from);
~Dog();
Dog& operator=(const Dog& rhs);
char operator[](int index) const;
char& operator[](int index);
friend ostream& operator<<(ostream& os, const Dog& d);
private:
int age;
int namelength;
char * name;
};

View File

@@ -1,16 +1,16 @@
#include <iostream>
using namespace std;
int & multiply(int A, int B) {
int i = A*B;
return i;
}
int main() {
int A = 5;
int B = 3;
int C = multiply(A,B);
cout << "A: " << A << " B: " << B << " C: " << C << endl;
return 0;
#include <iostream>
using namespace std;
int & multiply(int A, int B) {
int i = A*B;
return i;
}
int main() {
int A = 5;
int B = 3;
int C = multiply(A,B);
cout << "A: " << A << " B: " << B << " C: " << C << endl;
return 0;
}

View File

@@ -1,15 +1,15 @@
#include <iostream>
using namespace std;
int main() {
// int length;
// cin >> length;
int array1[3] = {3, 10, 40};
cout << array1 << endl;
cout << *array1 << endl;
cout << array1 << endl;
return 0;
#include <iostream>
using namespace std;
int main() {
// int length;
// cin >> length;
int array1[3] = {3, 10, 40};
cout << array1 << endl;
cout << *array1 << endl;
cout << array1 << endl;
return 0;
}

27
Lecture/Week5/Lab5.txt Normal file
View File

@@ -0,0 +1,27 @@
Shape class
data:
color (required)
1st point
# points
functions:
constructor(color)? <- optional
shape::shape(...) <- do this in child?
copy constructor
assignment operator
destructor (virtual)
draw <- pure virtual
Shape::draw(Graphics context gc)
gc->setColor(color)
Shape * S1 = new Line(...)
Shape * S2 = new Triangle(...)
S1->draw(...) draw Line
S2->draw(...) draw Triangle
Image class

28
Lecture/Week5/main.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include <iostream>
using namespace std;
class Pet{
public:
string name;
void set_data(int data){}
};
class Cat: public Pet{
public:
int fish;
void set_data(int data){fish = data;}
};
class Bird: public Pet{
public:
int seed;
void set_data(int data){seed = data;}
};
int main(){
Pet* C1 = new Cat;
Pet* C2 = new Cat;
C1->name = "Cat1";
C1->set_data(1);
}