Skip to content

Instantly share code, notes, and snippets.

View Amali24's full-sized avatar

Andy Thomas Amali24

  • Boston, MA
View GitHub Profile
@Amali24
Amali24 / Tax Bracket Algorithm
Last active February 17, 2017 22:08
Horrible Algorithm that I hate very much to calculate income tax on a progressive scale with marginal increases
public int calcTax(decimal agi)
{
// Create Arrays to hold Income Cutoffs and tax rates
// Storing these numbers like so allows for them to be changed without much issue
decimal[] incomeCutoffs = { 999.99m, 9999.99m, 19999.99m, 29999.99m };
decimal[] rates = { .1m, .15m, .20m, .25m, .28m };
decimal
max0 = incomeCutoffs[0] * rates [0],
max1 = (incomeCutoffs[1] - incomeCutoffs[0]) * rates [1],
max2 = (incomeCutoffs[2] - incomeCutoffs[1]) * rates [2],
@Amali24
Amali24 / Lab12.2.cpp
Last active January 22, 2022 16:08
Random Access File Usage
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
double getNum();
int getInt();
#include <iostream>
#include <ctype.h>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
@Amali24
Amali24 / TextFileStruct.cpp
Last active July 20, 2016 23:04
Simple utility to count, display and output to file number of lines in a text file, byte offsets, etc
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct FileText {
int lineNumber; // Line number from original file
long long fileOffset; // Number of bytes from start line starts
int length; // Length of line
@Amali24
Amali24 / MovieStruct.cpp
Created July 6, 2016 22:41
Demonstration of Structures in C++
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct MovieData {
string title;
string director;
int yearReleased;
double runningTime;
@Amali24
Amali24 / DynamicArrayWithPointers.cpp
Created June 29, 2016 15:34
Lab demonstrating dynamic memory allocation for arrays using pointers
#include <iostream>
#include <iomanip>
using namespace std;
int populateIntegerArray(int *arrayPtr, int arraySize);
void displayIntegerArray(int *arrayPtr, int arraySize);
int findMaximumInteger(int *arrayPtr, int arraySize);
double getNum();
int getInt();
@Amali24
Amali24 / PtrArithmetic.cpp
Created June 22, 2016 23:33
Playing with pointer arithmetic
#include <iostream>
using namespace std;
int main() {
const int SIZE = 5;
cout << "Demonstrating a potential pitfall of pointer arithmetic...\n\n";
@Amali24
Amali24 / textSorter.cpp
Created June 20, 2016 23:42
Simple selection sort demonstration. Intended to sort names (one per line in a txt file)
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void selectionSort(string[], int);
void showArray(string[], int);
int main() {
@Amali24
Amali24 / FilesIntoArrays.cpp
Created June 15, 2016 22:52
Reads ints from a text file into an array and displays various statistics about the numbers. Requires whitespace between integers.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int maxValue(int[], int);
int minValue(int[], int);
int sumValue(int[], int);
double avgValue(int[], int);
@Amali24
Amali24 / TextFileReadWrite.cpp
Last active June 16, 2023 17:09
Simple C++ File I/O Lab
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
// String variables for holding user inputted filenames
// And temp for temporarily holding a line of text from file
string fileNameIn, fileNameOut, temp;
// ifstream and ofstream for read/write