1
0

added more code

This commit is contained in:
Andrew W
2022-08-28 16:12:16 -05:00
parent 5a2894ed1b
commit 7dabaef6f6
2345 changed files with 1343530 additions and 0 deletions

173
CPE212/Project_01/main.cpp Normal file
View File

@ -0,0 +1,173 @@
//
// main.cpp -- Project01, CPE212 Fall 2010 -- C++ Review Project
//
// Driver program for Image Processing Program which is used to test each
// image processing operation.
//
// DO NOT SUBMIT OR SUBMIT THIS FILE
//
// List of allowed include files appear below
#include <iostream>
#include <fstream>
#include <string>
using namespace std; // Global using declaration
// Global Constants -- you may use these global constants in your code
const int MAXROWS = 10; // Maximum number of rows in image
const int MAXCOLS = 10; // Maximum number of columns in image
// Function Prototypes for functions included at the end of main.cpp
void Print(const int image[MAXROWS][MAXCOLS]);
void Bars();
// Function Prototypes for the functions you must implement in project01.cpp
void LoadImage(const string imagefile, int image[MAXROWS][MAXCOLS]);
void FlipHorizontal(int image[MAXROWS][MAXCOLS]);
void FlipVertical(int image[MAXROWS][MAXCOLS]);
void RotateCW(int image[MAXROWS][MAXCOLS]);
void RotateCCW(int image[MAXROWS][MAXCOLS]);
void Transpose(int image[MAXROWS][MAXCOLS]);
// Start of main() function
int main (int argc, char * const argv[]) // Command-line arguments (more on this later)
{
ifstream inputs; // Input file stream variable for test file
char op, ch; // Hold operation and optional char input from test file
string comment; // Holds comment string input from test file
int image[MAXROWS][MAXCOLS]; // Array of integers representing image
string imagefile; // Name of image file
// Output usage message if test input file name is not provided
if (argc != 2)
{
cout << "Usage:\n project01 <inputfile>\n";
return 1;
}
// Attempt to open test input file -- terminate if file does not open
inputs.open(argv[1]);
if (!inputs)
{
cout << "Error - unable to open input file" << endl;
return 1;
}
// Process comment line from input file
getline(inputs, comment); // Input file header comment
cout << endl << comment << endl << endl; // Output file header comment
// Below is primary loop that processes each operation appearing within the test file.
// Starts with an initial priming read of first operation
inputs >> op; // Attempt to input first test operation from file
while (inputs) // While Not-EOF
{
switch (op) // Process operation input from test file
{
case '#': // Test file comment
getline(inputs, comment); // Input and echo the comment appearing in the test file
cout << '#' << comment << endl;
break;
case 'p': // Print Grid
Print(image); // Function definition appears at the end of this file
break;
case 'b': // Print Bars
Bars(); // Function definition appears at the end of this file
break;
case 'i': // Load Image
inputs >> imagefile; // Input name of imagefile from test file
LoadImage(imagefile, image); // Implement this function in project01.cpp
break;
case '+': // Rotate Image Clockwise 90 Degrees
RotateCW(image); // Implement this function in project01.cpp
break;
case '-': // Rotate Image Counterclockwise 90 Degrees
RotateCCW(image); // Implement this function in project01.cpp
break;
case 'v': // Flip Image Vertical
FlipVertical(image); // Implement this function in project01.cpp
break;
case 'h': // Flip Image Horizontal
FlipHorizontal(image); // Implement this function in project01.cpp
break;
case 't': // Transpose Image Across Major Diagonal
Transpose(image); // Implement this function in project01.cpp
break;
default: // Error
cout << "Error - unrecognized operation '" << op << "'" << endl;
cout << "Terminating now..." << endl;
return 1;
break;
}
cout << endl;
inputs >> op; // Attempt to input next command
}
return 0;
}
/************** Implementation of Print() and Bars() functions ********************/
// DO NOT MODIFY THIS CODE
void Print(const int image[MAXROWS][MAXCOLS])
// Print() -- outputs image row-by-row in desired format substituting
// * for 1 and - for 0.
{
for(int r=0; r < MAXROWS; r++) // Loop to visit each row in image
{
for(int c=0; c < MAXCOLS; c++) // Loop to output every element on crrent row
{
if (image[r][c] == 1) // Output appropriate symbol
{
cout << '*';
}
else if (image[r][c] == 0)
{
cout << '-';
}
else
{
cout << 'X';
}
}
cout << endl;
}
} // End Print()
void Bars()
// Bars() -- prints two horizontal rows of bars
{
cout << "#################################################################" << endl;
cout << "#################################################################" << endl;
} // End Bars()
/************** DO NOT DELETE *************/
// The preprocessor directive below will import the function definitions
// from the file project01.cpp and place them at the end of this file creating an
// Expanded Source File which is forwarded to the compiler for compilation.
#include "project01.cpp"
/************** End of main.cpp ***************/

View File

@ -0,0 +1,9 @@
# Project01 -- Fall 2010 CPE212-01
project01: project01.cpp main.cpp
g++ main.cpp -o project01
clean:
rm project01

View File

@ -0,0 +1,13 @@
# p01image1.txt -- Sample Image #1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

View File

@ -0,0 +1,13 @@
# p01image2.txt -- Sample Image #2
0 1 1 1 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 1
0 0 0 1 1 0 0 0 0 0
0 0 0 1 1 1 1 0 0 1
1 0 0 1 1 1 1 0 0 0
1 0 0 1 1 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 1 1 0

View File

@ -0,0 +1,13 @@
# p01image3.txt -- Sample Image #3
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0

View File

@ -0,0 +1,77 @@
# p01input1.txt -- Test of Transpose Image
# Draw Bars
b
# Load Image1
i p01image1.txt
# Print Image1
p
# Transpose Image1
t
# Print Image1
p
# Transpose Image1
t
# Print Image1
p
# Draw Bars
b
# Load Image2
i p01image2.txt
# Print Image2
p
# Transpose Image2
t
# Print Image2
p
# Transpose Image2
t
# Print Image2
p
# Draw Bars
b
# Load Image3
i p01image3.txt
# Print Image3
p
# Transpose Image3
t
# Print Image3
p
# Transpose Image3
t
# Print Image3
p
# Draw Bars
b

View File

@ -0,0 +1,74 @@
# p01input2.txt -- Test of Horizontal Flip
# Draw Bars
b
# Load Image1
i p01image1.txt
# Print Image1
p
# Horizontal Flip Image1
h
# Print Flipped Image1
p
# Horizontal Flip Image1
h
# Print Flipped Image1
p
# Draw Bars
b
# Load Image2
i p01image2.txt
# Print Image2
p
# Horizontal Flip Image2
h
# Print Flipped Image2
p
# Horizontal Flip Image2
h
# Print Flipped Image2
p
# Draw Bars
b
# Load Image3
i p01image3.txt
# Print Image3
p
# Horizontal Flip Image3
h
# Print Flipped Image3
p
# Horizontal Flip Image3
h
# Print Flipped Image3
p
# Draw Bars
b

View File

@ -0,0 +1,74 @@
# p01input3.txt -- Test of Vertical Flip
# Draw Bars
b
# Load Image1
i p01image1.txt
# Print Image1
p
# Vertical Flip Image1
v
# Print Flipped Image1
p
# Vertical Flip Image1
v
# Print Flipped Image1
p
# Draw Bars
b
# Load Image2
i p01image2.txt
# Print Image2
p
# Vertical Flip Image2
v
# Print Flipped Image2
p
# Vertical Flip Image2
v
# Print Flipped Image2
p
# Draw Bars
b
# Load Image3
i p01image3.txt
# Print Image3
p
# Vertical Flip Image3
v
# Print Flipped Image3
p
# Vertical Flip Image3
v
# Print Flipped Image3
p
# Draw Bars
b

View File

@ -0,0 +1,117 @@
# p01input4.txt -- Test of Rotate Clockwise
# Draw Bars
b
# Load Image1
i p01image1.txt
# Print Image1
p
# Rotate Clockwise 90 Degrees Image1
+
# Print Rotated Image1
p
# Rotate Clockwise 90 Degrees Image1
+
# Print Rotated Image1
p
# Rotate Clockwise 90 Degrees Image1
+
# Print Rotated Image1
p
# Rotate Clockwise 90 Degrees Image1
+
# Print Rotated Image1
p
# Draw Bars
b
# Load Image2
i p01image2.txt
# Print Image2
p
# Rotate Clockwise 90 Degrees Image2
+
# Print Rotated Image2
p
# Rotate Clockwise 90 Degrees Image2
+
# Print Rotated Image2
p
# Rotate Clockwise 90 Degrees Image2
+
# Print Rotated Image2
p
# Rotate Clockwise 90 Degrees Image2
+
# Print Rotated Image2
p
# Draw Bars
b
# Load Image3
i p01image3.txt
# Print Image3
p
# Rotate Clockwise 90 Degrees Image3
+
# Print Rotated Image3
p
# Rotate Clockwise 90 Degrees Image3
+
# Print Rotated Image3
p
# Rotate Clockwise 90 Degrees Image3
+
# Print Rotated Image3
p
# Rotate Clockwise 90 Degrees Image3
+
# Print Rotated Image3
p
# Draw Bars
b

View File

@ -0,0 +1,117 @@
# p01input5.txt -- Test of Rotate Counter Clockwise
# Draw Bars
b
# Load Image1
i p01image1.txt
# Print Image1
p
# Rotate Counter Clockwise 90 Degrees Image1
-
# Print Rotated Image1
p
# Rotate Counter Clockwise 90 Degrees Image1
-
# Print Rotated Image1
p
# Rotate Counter Clockwise 90 Degrees Image1
-
# Print Rotated Image1
p
# Rotate Counter Clockwise 90 Degrees Image1
-
# Print Rotated Image1
p
# Draw Bars
b
# Load Image2
i p01image2.txt
# Print Image2
p
# Rotate Counter Clockwise 90 Degrees Image2
-
# Print Rotated Image2
p
# Rotate Counter Clockwise 90 Degrees Image2
-
# Print Rotated Image2
p
# Rotate Counter Clockwise 90 Degrees Image2
-
# Print Rotated Image2
p
# Rotate Counter Clockwise 90 Degrees Image2
-
# Print Rotated Image2
p
# Draw Bars
b
# Load Image3
i p01image3.txt
# Print Image3
p
# Rotate Counter Clockwise 90 Degrees Image3
-
# Print Rotated Image3
p
# Rotate Counter Clockwise 90 Degrees Image3
-
# Print Rotated Image3
p
# Rotate Counter Clockwise 90 Degrees Image3
-
# Print Rotated Image3
p
# Rotate Counter Clockwise 90 Degrees Image3
-
# Print Rotated Image3
p
# Draw Bars
b

BIN
CPE212/Project_01/project01 Normal file

Binary file not shown.

View File

@ -0,0 +1,155 @@
/*
Noah Woodlee
CPE212-01
Project 1, due Sunday, Febuary 21, 2020
*/
#include <iostream>
#include <fstream>
#include <string>
// LoadImage defintion
void LoadImage(const string imagefile, int image[MAXROWS][MAXCOLS])
{
ifstream input;
input.open(imagefile.c_str());
if (!input)
{
cout << "Error - File unable to be opened." << endl;
return;
}
int rows, cols, nums;
string str;
getline(input, str);
//cout << str;
for (int r = 0; r < MAXROWS ; r++) // iterate number of rows
{
for (int c = 0; c < MAXCOLS; c++) // iterate number of columns
{
input >> nums;
image[r][c]=nums;
}
}
} // End of LoadImage
// Flip Horozontal defintion
void FlipHorizontal(int image[MAXROWS][MAXCOLS])
{
int temp;
for (int r = 0; r < MAXROWS; r++) // loop for columns 1 & 10
{
temp=image[r][0];
image[r][0]=image[r][MAXCOLS-1];
image[r][MAXCOLS-1]=temp;
}
for (int r = 0; r < MAXROWS; r++) // loop for columns 2 & 9
{
temp=image[r][1];
image[r][1]=image[r][MAXCOLS-2];
image[r][MAXCOLS-2]=temp;
}
for (int r = 0; r < MAXROWS; r++) // loop for columns 3 & 8
{
temp=image[r][2];
image[r][2]=image[r][MAXCOLS-3];
image[r][MAXCOLS-3]=temp;
}
for (int r = 0; r < MAXROWS; r++) // loop for column 4 & 7
{
temp=image[r][3];
image[r][3]=image[r][MAXCOLS-4];
image[r][MAXCOLS-4]=temp;
}
for (int r = 0; r < MAXROWS; r++) // loop for column 5 & 6
{
temp=image[r][4];
image[r][4]=image[r][MAXCOLS-5];
image[r][MAXCOLS-5]=temp;
}
} // End of FlipHorizontal function
// FlipVertical defintion
void FlipVertical(int image[MAXROWS][MAXCOLS])
{
int temp;
for (int c = 0; c < MAXCOLS; c++) // loop for rows 1 & 10
{
temp = image[0][c];
image[0][c] = image[MAXROWS-1][c];
image[MAXROWS-1][c] = temp;
}
for (int c = 0; c < MAXCOLS; c++) // loop for rows 2 & 9
{
temp = image[1][c];
image[1][c] = image[MAXROWS-2][c];
image[MAXCOLS-2][c] = temp;
}
for (int c = 0; c < MAXCOLS; c++) // loop for rows 3 & 8
{
temp = image[2][c];
image[2][c] = image[MAXROWS-3][c];
image[MAXCOLS-3][c]=temp;
}
for (int c = 0; c < MAXCOLS; c++) // loop for rows 4 & 7
{
temp = image[3][c];
image[3][c] = image[MAXROWS-4][c];
image[MAXCOLS-4][c] = temp;
}
for (int c = 0; c < MAXCOLS; c++) // loop for rows 5 & 6
{
temp = image[4][c];
image[4][c] = image[MAXROWS-5][c];
image[MAXCOLS-5][c] = temp;
}
}
// RotateCW defintion
void RotateCW(int image[MAXROWS][MAXCOLS])
{
int n = MAXCOLS;
for (int i = 0; i < n/2; i++)
{
for (int j = i; j < n-i-1; j++)
{
int temp = image[i][j];
image[i][j]=image[n-1-j][i];
image[n - 1 - j][i] = image[n - 1 - i][n - 1 - j];
image[n - 1 - i][n - 1 - j] = image[j][n - 1 - i];
image[j][n - 1 - i] = temp;
}
}
}
// RotateCCW defintion
void RotateCCW(int image[MAXROWS][MAXCOLS])
{
int n=MAXROWS;
for(int i=0;i<n/2;i++)
{
for(int j=i;j<n-i-1;j++)
{
int temp=image[i][j];
image[i][j]=image[j][n-i-1];
image[j][n-i-1]=image[n-i-1][n-j-1];
image[n-i-1][n-j-1]=image[n-j-1][i];
image[n-j-1][i]=temp;
}
}
}
// Transpose defintion
void Transpose(int image[MAXROWS][MAXCOLS])
{
int temp;
for (int r = 0; r < MAXROWS; r++){ // loop to increment rows
for (int c = 0; c < r; c++) // loop to increment columns
{
temp = image[r][c];
image[r][c] = image[c][r];
image[c][r] = temp;
}
}
}