Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Algorithm Workbook/hw0-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// hw0-test.cpp
// pic10b
//
// Created by Michael James Murray on 12/30/23.
//

#include <iostream>
#include <string>
#include <vector>
#include "hw0.hpp"

int main(){
{
// Question 1 test
std::vector<std::vector<int>> v = {{1,2,3}, {-1,2}, {7}, {}};
std::cout << max_element(v) << std::endl;
}

{
// Question 2 test
int x = 1;
int y = 2;
int*p1 = &x;
int*p2 = &y;
pointer_swap(p1,p2);
std::cout << (p1 == &y) << " " << (p2 == &x) << std::endl;
std::cout<< x << " " << y << std::endl;
}
{
// // Question 3 test for Caesar: this string is the opening paragraph of the Hitchhiker's guide to the galaxy, a wonderful book!
int offset = -12;
std::string s = "Far out in the uncharted backwaters of the unfashionable end of the Western Spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-eight million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.";

// First test the Caesar cipher 1
// Lets just print the first 40 characters
std::string encoded_s = caesar_cipher1(s,offset);
std::cout << encoded_s.substr(0, 30) << std::endl;

std::string decoded_s = caesar_cipher1(encoded_s,-offset);
std::cout << decoded_s.substr(0, 30) << std::endl;

std::cout << std::boolalpha << (decoded_s == s) << std::endl;

// Now test Caesar cipher 2

// caesar_cipher2(s,offset);
// std::cout << (encoded_s == s) << std::endl;
//
// caesar_cipher2(s,-offset);
// std::cout << (decoded_s == s) << std::endl;
return 0;
}

{
// Question 4 test
const Undergrad s1;
Undergrad s2("Tim", 12345, 91);
std::cout << s1.name << " " << s1.ID << " " << s1.get_grade() << std::endl;
std::cout << s2.name << " " << s2.ID << " " << s2.get_grade() << std::endl;
s2.update_grade(102);
s2.update_grade(95);
std::cout << s2.name << " " << s2.ID << " " << s2.get_grade() << std::endl;
}
}
206 changes: 206 additions & 0 deletions Algorithm Workbook/hw0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
//
// hw0.cpp
// pic10b
//
// Created by Michael James Murray on 1/4/24.
//
#include <iostream>
#include <string>
#include <vector>
#include "hw0.hpp"
using namespace std;

// Question 1: max element function
int max_element(vector<vector<int>> vmax){
////first it is the vector of vectors that gets counted to see if it is empty
/// then we check the elements of the said chosen vector to see if those are empty
///
if (vmax.size() == 0 || vmax[0].size() == 0){
return -1;
}


int maxes = vmax[0][0];


for (size_t i = 0; i != vmax.size(); ++i){

for (size_t j = 0; j != vmax[i].size(); ++j){

if (vmax[i][j] > maxes) {
maxes = vmax[i][j];
}
}
}
return maxes;
}

// Question 2: pointer swap function
void pointer_swap(int*& one, int*& two){
int* x = one;
int* y = two;
two = x;
one = y;

int temp = *one;
*one = *two;
*two = temp;

}

// Question 3a: caesar cipher function

string caesar_cipher1(const string& text, int offsetchar) {
// Initialize the output string with the input text
string output = text;

// Define the alphabet used for the cipher
const string alphabet = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

// Ensure the offsetchar is within the size of the alphabet
offsetchar %= alphabet.size();

// Adjust the offset for negative values
if (offsetchar < 0) {
offsetchar += alphabet.size();
}

// Iterate through each character in the input text
for (size_t i = 0; i < text.size(); ++i) {
char& currentChar = output[i]; // Get a reference to the current character

// Check if the character is printable or a space
if (isprint(currentChar) || currentChar == ' ') {
// Find the position of the current character in the alphabet
size_t pos = alphabet.find(currentChar);

// If the character is found in the alphabet
if (pos != string::npos) {
// Apply the offset to shift the character
pos = (pos + offsetchar) % alphabet.size();

// Update the character in the output string with the shifted character from the alphabet
currentChar = alphabet[pos];
}
}
}

// Return the encoded text
return output;
}



// string caesar_cipher1(const string& text, int offsetchar){
//
// string output = text;
// const string alphabet = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
//
//
// offsetchar %= alphabet.size();
//
// // Adjust the offset for negative values
// if (offsetchar < 0) {
// offsetchar += alphabet.size();
// }
// string printed;
//
// // Iterate through each character in the input text
// for (size_t i = 0; i < text.size(); ++i) {
// char& currentChar = output[i]; // Get a reference to the current character
//
// // Check if the character is printable or a space
// if (isprint(currentChar) || currentChar == ' ') {
// // Find the position of the current character in the alphabet
// size_t pos = alphabet.find(currentChar);
//
// // If the character is found in the alphabet
// if (pos != std::string::npos) {
// // Apply the offset to shift the character
// pos = (pos + offsetchar) % alphabet.size();
//
// // Update the character in the output string with the shifted character from the alphabet
// currentChar = alphabet[pos];
// }
// }
// printed.push_back(currentChar);
// // output.swap(&currentChar);
// }
//return printed;
//}
//
//string caesar_ciper1(const string& text, int offsetchar){
//
// string output = text;
// const string alphabet = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
//
//
// if (offsetchar > alphabet.size() || offsetchar < -alphabet.size()){
// offsetchar %= alphabet.size();
// }
//// if (offsetchar < 0){
//// offsetchar = abs(offsetchar);
//// }
//
// for (size_t i = 0; i < text.size(); ++i){
// size_t pos = alphabet.find(text[i]);
// pos += offsetchar;
// // output[i] += alphabet[pos];
// output.push_back(alphabet[pos]);
//// if (offsetchar < 0){
//// //do the minus down the alphabet
//// pos += offsetchar;
//// output[i] += alphabet[pos];
//// }
// //if (text[i] == alphabet[i]){
// // string found = &text[i];
// // output.push_back(found);
// // output[text[i]] += offsetchar;
// // }
// }
// return output;
//}

//if (message[". "])
// do capital


// Question 3b: in-place caesar cipher function
//string caesar_cipher2(const string& message2, int offset2){
//
//
//
//}




// Question 4: member functions of Undergrad class
//Undergrad(string name, size_t ID, int grade): name(name), ID(ID), grade(grade){}

Undergrad::Undergrad(){
string name = "Test";
size_t ID = 0;
int grade = 0;
}
Undergrad::Undergrad(string name, size_t ID, int grade){}

int Undergrad::get_grade() const{
if (grade < 0 || grade > 100){
cout << "Grade is not valid, must be between 0 and 100." << endl;
return 0;
}
return grade;
}


void Undergrad::update_grade(int newgrade){

if (newgrade < 0 || newgrade > 100){
cout << "Grade is not valid, must be between 0 and 100." << endl;
}
else{
grade = newgrade;
}
}

49 changes: 49 additions & 0 deletions Algorithm Workbook/hw0.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// hw0.hpp
// pic10b
//
// Created by Michael James Murray on 1/4/24.
//

#ifndef hw0_hpp
#define hw0_hpp

#include <iostream>
#include <string>
#include <vector>

using namespace std;
// Question 1: declaration max element function
// XXXX max_element(XXXX);
int max_element(vector<vector<int>> vect);

////Question 2: declaration pointer swap function
void pointer_swap(int*& one, int*& two);
//
// Question 3a: declaration caesar cipher function
string caesar_cipher1(const string& message, int offset);

// Question 3b: declaration in-place caesar cipher function

string caesar_cipher2(const string message2, int offset2);


// Question 4: declaration of Undergrad class
class Undergrad{
private:
int grade;

public:
string name;
size_t ID;
Undergrad();
Undergrad(string name, size_t ID, int grade);

void update_grade(int newgrade);
int get_grade() const;

// Undergrad(const string name, const size_t id, int grade) : name(name), ID(id), grade(grade){}

};

#endif /* hw0_hpp */
2 changes: 2 additions & 0 deletions Pointer Matching/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Again thiis is another method of showing static data manipulation.
Clearly looking for defined integers within an array by recursively calling their pointers to ommit copys.
Binary file removed Projects/Binary Search
Binary file not shown.
Binary file removed Projects/Linked List
Binary file not shown.
Binary file removed Projects/Magic Square
Binary file not shown.
1 change: 0 additions & 1 deletion Projects/Matching Pointer Search

This file was deleted.

Binary file removed Projects/Polymorphism
Binary file not shown.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# 1. Matching Pointer Search - Arrays
Provide an array with a specific value and length to try to find them using pointers to be more efficient in data manipulation

# 2. Magic Square
# 2. Rational # Operator Overloading
Overloads all basic arithemtic operators and istream ostream for custom dynamic data manipulation using static containers.

# 3. Magic Square Algorithm
This project makes sure to organize random arrangements of a non-conflicting matrix as many times as possible.

# 3. Linked List
# 4. Linked List
A linked list iterator that iterates forward and reverse.

# 4. Binary Search Tree
# 5. Binary Search Tree
Navigating through a search tree to find a particular number in the tree.

# 5. Polymorphism
# 6. Polymorphism
Using polygon as an analogy for being able to use objects in a polymorphic inheritance.

### Basic Fun Tasks
Simple tasks for algorithm reference
3 changes: 3 additions & 0 deletions Rational Number Arithmetic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New Activity Touching on Arithmetic Basics to show understang of object oriented data manipulation.
Mathematically this is a clear demonstration of how object oriented programming can use dynamic and static data manipulation.
Clearly using efficient systems like pointers to reduce time and storage capacity of machines.
35 changes: 35 additions & 0 deletions Rational Number Arithmetic/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include "rational.hpp"

int main() {
Rational& r();
Rational& r2();
Rational& r3();
Rational& r4();
Rational& r5();

std::cout << "Type a rational in the form num/den, and I'll say it back at you: ";
std::cin >> r;
std::cout << "This is your rational: " << &r << std::endl;
std::cout << "Type a rational in the form num/den, and I'll say it back at you: ";
std::cin >> r2;
std::cout << "This is your rational: " << &r2 << std::endl;
std::cout << "Type a rational in the form num/den, and I'll say it back at you: ";
std::cin >> r3;
std::cout << "This is your rational: " << &r3 << std::endl;
std::cout << "Type a rational in the form num/den, and I'll say it back at you: ";
std::cin >> r4;
std::cout << "This is your rational: " << &r4 << std::endl;
std::cout << "Type a rational in the form num/den, and I'll say it back at you: ";
std::cin >> r5;
std::cout << "This is your rational: " << &r5 << std::endl;

Rational& operator+= (Rational& aduh);
std::cout << operator+=(&aduh) << std::endl;

// Rational operator-=(r3);
// Rational& operator*=(multi);
// Rational& operator/=(const Rational& divi);
return 0;

}
Loading