forgot to commit this
This commit is contained in:
14 files changed
+353
-20
No files matched your search
+20
-1
@@ -1,8 +1,27 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Course: COMP 2510
|
||||||
|
* Assignment: Assignment 1
|
||||||
|
* Name: Braeden Sowinski
|
||||||
|
* Student ID: A01385066
|
||||||
|
* Date: 2025-09-20
|
||||||
|
* Description: Calculate download speeds from
|
||||||
|
* given file size and download speed
|
||||||
|
*/
|
||||||
|
|
||||||
#define MEGABYTES_TO_MEGABITS 8
|
#define MEGABYTES_TO_MEGABITS 8
|
||||||
|
|
||||||
int main(void) {
|
/**
|
||||||
|
* main program entry
|
||||||
|
*
|
||||||
|
* takes in user input for download speed
|
||||||
|
* int Mbs and file size in MBs
|
||||||
|
* and calculates the download speed
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
float downloadSpeedMbs;
|
float downloadSpeedMbs;
|
||||||
float fileSizeMB;
|
float fileSizeMB;
|
||||||
float downloadTimeSeconds;
|
float downloadTimeSeconds;
|
||||||
|
|||||||
+31
-6
@@ -1,26 +1,51 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Course: COMP 2510
|
||||||
|
* Assignment: Assignment 1
|
||||||
|
* Name: Braeden Sowinski
|
||||||
|
* Student ID: A01385066
|
||||||
|
* Date: 2025-09-20
|
||||||
|
* Description: Convert centimeters to feet and inches
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define CENTIMETERS_PER_FOOT 30.48
|
#define CENTIMETERS_PER_FOOT 30.48
|
||||||
#define CENTIMETERS_PER_INCH 2.54
|
#define CENTIMETERS_PER_INCH 2.54
|
||||||
#define INCHES_PER_FOOT 12
|
#define INCHES_PER_FOOT 12
|
||||||
|
|
||||||
int main(void) {
|
/**
|
||||||
|
* main program entry
|
||||||
|
*
|
||||||
|
* continuously takes user input for a height
|
||||||
|
* in centimeters and then converts that to
|
||||||
|
* feet and inches with proper amount of decimal
|
||||||
|
* points.
|
||||||
|
*
|
||||||
|
* Quits when a number less than or equal to 0
|
||||||
|
* is inputed.
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
float heightCm;
|
float heightCm;
|
||||||
int heightFeet;
|
int heightFeet;
|
||||||
float heightInches;
|
float heightInches;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
|
|
||||||
printf("Enter a height in centimeters (<=0 to quit): ");
|
printf("Enter a height in centimeters (<=0 to quit): ");
|
||||||
scanf("%f", &heightCm);
|
scanf("%f", &heightCm);
|
||||||
|
|
||||||
if (heightCm <= 0) {
|
if (heightCm <= 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
heightFeet = (heightCm / CENTIMETERS_PER_FOOT);
|
heightFeet = (heightCm / CENTIMETERS_PER_FOOT);
|
||||||
heightInches = (heightCm / CENTIMETERS_PER_INCH) -
|
heightInches = (heightCm / CENTIMETERS_PER_INCH) -
|
||||||
(INCHES_PER_FOOT * heightFeet);
|
(INCHES_PER_FOOT * heightFeet);
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
@@ -35,4 +60,4 @@ int main(void) {
|
|||||||
printf("Bye\n");
|
printf("Bye\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+28
-5
@@ -1,23 +1,46 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(void) {
|
/*
|
||||||
|
* Course: COMP 2510
|
||||||
|
* Assignment: Assignment 1
|
||||||
|
* Name: Braeden Sowinski
|
||||||
|
* Student ID: A01385066
|
||||||
|
* Date: 2025-09-20
|
||||||
|
* Description: Calculate sum of squares from X to Y
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program entry
|
||||||
|
*
|
||||||
|
* takes in user input for an upper and lower
|
||||||
|
* limit, then calculates the sum of squares
|
||||||
|
* from the lower to the upper limit.
|
||||||
|
*
|
||||||
|
* continuously takes input until upper limit
|
||||||
|
* is less than or equal to lower limit
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
int max;
|
int max;
|
||||||
int min;
|
int min;
|
||||||
int sumOfSquares;
|
int sumOfSquares;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
|
|
||||||
sumOfSquares = 0;
|
sumOfSquares = 0;
|
||||||
|
|
||||||
printf("Enter a lower and upper limit: ");
|
printf("Enter a lower and upper limit: ");
|
||||||
scanf("%d %d", &min, &max);
|
scanf("%d %d", &min, &max);
|
||||||
|
|
||||||
if (max <= min) {
|
if (max <= min)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = min; i <= max; i++) {
|
for (int i = min; i <= max; i++)
|
||||||
|
{
|
||||||
sumOfSquares += i * i;
|
sumOfSquares += i * i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,4 +56,4 @@ int main(void) {
|
|||||||
printf("Done\n");
|
printf("Done\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+35
-7
@@ -1,40 +1,66 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Course: COMP 2510
|
||||||
|
* Assignment: Assignment 1
|
||||||
|
* Name: Braeden Sowinski
|
||||||
|
* Student ID: A01385066
|
||||||
|
* Date: 2025-09-20
|
||||||
|
* Description: Demonstrate how to copy arrays using different methods
|
||||||
|
*/
|
||||||
|
|
||||||
#define ARRAY_SIZE 5
|
#define ARRAY_SIZE 5
|
||||||
|
|
||||||
void printArray(double arr[]) {
|
/**
|
||||||
for (int i = 0; i < 5; i++) {
|
* printArray to validate copy
|
||||||
|
*/
|
||||||
|
void printArray(char arrName[], double arr[]) {
|
||||||
|
printf("\n%s\n", arrName);
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
printf("%.1f, ", arr[i]);
|
printf("%.1f, ", arr[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy_arr using array notatoin
|
||||||
|
*/
|
||||||
void copy_arr(double target[], double source[], int size) {
|
void copy_arr(double target[], double source[], int size) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
target[i] = source[i];
|
target[i] = source[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
printArray(target);
|
printArray("target 1:", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy_ptr copies an array using pointer arithmatic
|
||||||
|
*/
|
||||||
void copy_ptr(double *target, double *source, int size) {
|
void copy_ptr(double *target, double *source, int size) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
*(target + i) = *(source + i);
|
*(target + i) = *(source + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
printArray(target);
|
printArray("target 2:", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy_ptrs copies an array using pointers
|
||||||
|
*/
|
||||||
void copy_ptrs(double *target, double *source, double *lastElement) {
|
void copy_ptrs(double *target, double *source, double *lastElement) {
|
||||||
while (source <= lastElement) {
|
while (source <= lastElement) {
|
||||||
target = source;
|
target = source;
|
||||||
source++;
|
source++;
|
||||||
target++;
|
target++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printArray(target);
|
printArray("target 3:", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program entry to test different ways
|
||||||
|
* of copying arrays
|
||||||
|
*/
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
double source[ARRAY_SIZE] = {1.1, 2.2, 3.3, 4.4, 5.5};
|
double source[ARRAY_SIZE] = {1.1, 2.2, 3.3, 4.4, 5.5};
|
||||||
@@ -42,9 +68,11 @@ int main(void) {
|
|||||||
double target2[ARRAY_SIZE];
|
double target2[ARRAY_SIZE];
|
||||||
double target3[ARRAY_SIZE];
|
double target3[ARRAY_SIZE];
|
||||||
|
|
||||||
|
printArray("source:", source);
|
||||||
|
|
||||||
copy_arr(target1, source, ARRAY_SIZE);
|
copy_arr(target1, source, ARRAY_SIZE);
|
||||||
copy_ptr(target2, source, ARRAY_SIZE);
|
copy_ptr(target2, source, ARRAY_SIZE);
|
||||||
copy_ptrs(target3, source, source + ARRAY_SIZE);
|
copy_ptrs(target3, source, source + ARRAY_SIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -5,7 +5,7 @@ CFLAGS = -Wall -std=c11
|
|||||||
#Input file
|
#Input file
|
||||||
INPUT = input2.txt
|
INPUT = input2.txt
|
||||||
OUTPUT = output.txt
|
OUTPUT = output.txt
|
||||||
REF = ref2.txt
|
REF = ref.txt
|
||||||
# Source file
|
# Source file
|
||||||
SRCS = lab5.c
|
SRCS = lab5.c
|
||||||
# Output
|
# Output
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Compiler and flags
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall -std=c11
|
||||||
|
|
||||||
|
#Input file
|
||||||
|
INPUT = input3.txt
|
||||||
|
OUTPUT = output.txt
|
||||||
|
REF = ref3.txt
|
||||||
|
# Source file
|
||||||
|
SRCS = lab6.c
|
||||||
|
# Output
|
||||||
|
TARGET = lab6.out
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
# Rule to build the executable
|
||||||
|
$(TARGET): $(SRCS)
|
||||||
|
$(CC) $(CFLAGS) $(SRCS) -o $(TARGET)
|
||||||
|
|
||||||
|
|
||||||
|
convert_input: $(INPUT)
|
||||||
|
dos2unix $(REF)
|
||||||
|
dos2unix $(INPUT)
|
||||||
|
|
||||||
|
convert_output: $(OUTPUT)
|
||||||
|
dos2unix $(OUTPUT)
|
||||||
|
|
||||||
|
check: $(OUTPUT) $(REF)
|
||||||
|
@diff -q $(OUTPUT) $(REF) > /dev/null; \
|
||||||
|
if [ $$? -eq 0 ]; then \
|
||||||
|
echo "Pass"; \
|
||||||
|
else \
|
||||||
|
echo "Fail"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rule to run the program
|
||||||
|
run: $(TARGET)
|
||||||
|
./$(TARGET) $(INPUT) $(OUTPUT)
|
||||||
|
|
||||||
|
# Rule to clean generated files
|
||||||
|
clean:
|
||||||
|
rm -f $(TARGET)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
2
|
||||||
|
2
|
||||||
|
2
|
||||||
|
22
|
||||||
|
11
|
||||||
|
E
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
4
|
||||||
|
4
|
||||||
|
0.5
|
||||||
|
3333
|
||||||
|
3333
|
||||||
|
2222
|
||||||
|
2222
|
||||||
|
E
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
2
|
||||||
|
2
|
||||||
|
1
|
||||||
|
11
|
||||||
|
22
|
||||||
|
E
|
||||||
+165
@@ -0,0 +1,165 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// Update this with your A number
|
||||||
|
char a_num[] = "01385066";
|
||||||
|
|
||||||
|
void writeOutput(char outputPath[], char **arr, int *rows, int *cols)
|
||||||
|
{
|
||||||
|
FILE *writeFile;
|
||||||
|
|
||||||
|
writeFile = fopen(outputPath, "w");
|
||||||
|
|
||||||
|
if (writeFile == NULL)
|
||||||
|
{
|
||||||
|
perror("Failed to open output file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// matrix to output file
|
||||||
|
for (int x = 0; x < *rows; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < *cols; y++)
|
||||||
|
{
|
||||||
|
fputc(arr[x][y], writeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x < *rows - 1) fputc('\n', writeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(writeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zoomArray(char **arr, float n, int *rows, int *cols, char outputFileName[])
|
||||||
|
{
|
||||||
|
|
||||||
|
int newRows = (int)(*rows * n);
|
||||||
|
int newCols = (int)(*cols * n);
|
||||||
|
|
||||||
|
char **scaled = malloc(sizeof(char*) * newRows);
|
||||||
|
|
||||||
|
if (scaled == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to malloc scaled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newRows; i++)
|
||||||
|
{
|
||||||
|
scaled[i] = malloc(sizeof(char) * newCols);
|
||||||
|
if (scaled[i] == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to malloc scaled[i]");
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
free(scaled[i]);
|
||||||
|
|
||||||
|
free(scaled);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newRows; i++) {
|
||||||
|
for (int j = 0; j < newCols; j++) {
|
||||||
|
int srcRow = (int)(i / n);
|
||||||
|
int srcCol = (int)(j / n);
|
||||||
|
|
||||||
|
if (srcRow >= *rows) srcRow = *rows - 1;
|
||||||
|
if (srcCol >= *cols) srcCol = *cols - 1;
|
||||||
|
|
||||||
|
scaled[i][j] = arr[srcRow][srcCol];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeOutput(outputFileName, scaled, &newRows, &newCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 3)
|
||||||
|
{
|
||||||
|
printf("Usage: %s <input_file> <output_file>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *inputFileName = argv[1];
|
||||||
|
char *outputFileName = argv[2];
|
||||||
|
char **arr = NULL;
|
||||||
|
int rows = 0, cols = 0;
|
||||||
|
float zoomFactor = 0;
|
||||||
|
|
||||||
|
// Read the input array from the specified file
|
||||||
|
FILE *file = fopen(inputFileName, "r");
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
perror("Error opening input file");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the row value
|
||||||
|
fscanf(file, "%d", &rows);
|
||||||
|
// Read the column value
|
||||||
|
fscanf(file, "%d", &cols);
|
||||||
|
// Read the zoom factor
|
||||||
|
fscanf(file, "%f", &zoomFactor);
|
||||||
|
|
||||||
|
// Allocate memory for the 2D array
|
||||||
|
arr = (char **)malloc(rows * sizeof(char *));
|
||||||
|
if (arr == NULL)
|
||||||
|
{
|
||||||
|
printf("Memory allocation failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
arr[i] = (char *)malloc(cols * sizeof(char));
|
||||||
|
if (arr[i] == NULL)
|
||||||
|
{
|
||||||
|
printf("Memory allocation failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the elements of the array until 'E' is encountered
|
||||||
|
char inputChar;
|
||||||
|
int i = 0, j = 0;
|
||||||
|
while ((inputChar = fgetc(file)) != 'E')
|
||||||
|
{
|
||||||
|
if (inputChar >= '0' && inputChar <= '9' && i < rows && j < cols)
|
||||||
|
{
|
||||||
|
arr[i][j++] = inputChar;
|
||||||
|
if (j == cols)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
printf("A%s\n", a_num);
|
||||||
|
|
||||||
|
// Output the input array
|
||||||
|
printf("Input Array:\n");
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < cols; j++)
|
||||||
|
{
|
||||||
|
printf("%c", arr[i][j]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
// Call the zoomArray function
|
||||||
|
zoomArray(arr, zoomFactor, &rows, &cols, outputFileName);
|
||||||
|
|
||||||
|
// Free the memory allocated for the 2D array
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
free(arr[i]);
|
||||||
|
}
|
||||||
|
free(arr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
11
|
||||||
|
22
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
2222
|
||||||
|
2222
|
||||||
|
1111
|
||||||
|
1111
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
33
|
||||||
|
22
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
11
|
||||||
|
22
|
||||||
Reference in new issue
Block a user