added old projects

This commit is contained in:
Austin Bennett
2026-02-03 08:18:39 -06:00
parent 43acf989bf
commit 2451448b8a
623 changed files with 28117 additions and 0 deletions
Binary file not shown.
@@ -0,0 +1 @@
1200.43 .08 60
@@ -0,0 +1,107 @@
//
// main.cpp
// CompoundingInterest
//
// Created by Austin Bennett on 6/19/22.
//
/*
Write a program that read the starting balance, interest rate and number of months from a file.
Example:
1200.43 .08 60
(Balance of $1200.43, 8 percent interest rate, 60 months)
your program will print out a table showing month number and current balance (assume it is compounded monthly) for the number of specified months. Your program should prompt the user for the name of the output file. Use the formatting function you created previously to format the amount. Please note that the output of the program must show balance each month - not just the total at the end.
Example:
0 1,200.43
1 1,208.44
2 1,216.54
etc.
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string Format(double input) {
char result[] {};
// resultIndex will handle what goes where in our output
int resultIndex = 0;
//Making the input nice to work with
std::string inputString = to_string(input);
char num[inputString.length() + 1];
strcpy(num, inputString.c_str());
// characteristic is all the numbers on the right of the decimal point
char* characteristic = strtok(num, ".");
int characteristicLen = strlen(characteristic);
int characteristicIndex {0};
// this adds the commas
for (int i = characteristicLen - 1 ; i >= 0; i--) {
bool isComma = ((i + 1) % 3 == 0);
if (isComma) {
result[resultIndex] = ',';
resultIndex++;
result[resultIndex] = characteristic[characteristicIndex];
characteristicIndex++;
resultIndex++;
} else {
result[resultIndex] = characteristic[characteristicIndex];
characteristicIndex++;
resultIndex++;
}
}
//adds the decimal
result[resultIndex] = '.';
resultIndex++;
// creates the mantissa
characteristic = strtok(NULL, ".");
//adds the decimals
for (int i = 0; i <= 1; i++) {
result[resultIndex] = characteristic[i]; // the mantissa's value at index i
resultIndex++;
characteristicIndex++;
}
//builds out the result
string s = "";
for (size_t i = 0; i < resultIndex; i++) {
s = s + result[i];
}
return s;
}
int main()
{
// Get intial values
float newBalance, interestRate, months, oldBalance;
fstream input("/Users/austin/Documents/School/Summer 2022/CSC 122/CompoundingInterest/CompoundingInterest/input.txt", ios_base::in);
input >> oldBalance >> interestRate >> months;
// Build the output file
string fileName;
cout << "Enter File Name (No extension): ";
cin >> fileName;
ofstream output;
output.open ("/Users/austin/Documents/School/Summer 2022/CSC 122/CompoundingInterest/CompoundingInterest/" + fileName + ".txt");
//Assuming the first month counts as one of the input months
output << "0 " << Format(oldBalance) << endl;
for (int i = 1; i < months; i++) {
newBalance = ( 1 + interestRate / 12 ) * oldBalance;
output << i << " " << Format(newBalance) << endl;
oldBalance = newBalance;
}
}
@@ -0,0 +1,60 @@
0 1,200.43
1 1,208.43
2 1,216.48
3 1,224.59
4 1,232.76
5 1,240.98
6 1,249.25
7 1,257.58
8 1,265.96
9 1,274.40
10 1,282.90
11 1,291.45
12 1,300.06
13 1,308.73
14 1,317.45
15 1,326.24
16 1,335.08
17 1,343.98
18 1,352.94
19 1,361.96
20 1,371.04
21 1,380.18
22 1,389.38
23 1,398.64
24 1,407.96
25 1,417.35
26 1,426.80
27 1,436.31
28 1,445.89
29 1,455.53
30 1,465.23
31 1,475.00
32 1,484.83
33 1,494.73
34 1,504.70
35 1,514.73
36 1,524.83
37 1,534.99
38 1,545.22
39 1,555.53
40 1,565.90
41 1,576.34
42 1,586.84
43 1,597.42
44 1,608.07
45 1,618.79
46 1,629.59
47 1,640.45
48 1,651.39
49 1,662.39
50 1,673.48
51 1,684.63
52 1,695.86
53 1,707.17
54 1,718.55
55 1,730.01
56 1,741.54
57 1,753.15
58 1,764.84
59 1,776.61