User Tools

Site Tools


blog:fall2015:mmalik1:journal

This is an old revision of the document!


HPC Experience

September 1, 2015

On the first day of HPC, all we did was organize the tables we had in the room into a more “lair” like feel. We moved the tables into their own pods. That's basically all we did.

On the second day of HPC, we still didn't have the computers due to an error when ordering them. So, all we did was set up the monitors on all the pods.

On the third day of HPC, the computers finally came! We set everything up. The goal for that day was to have a fully functional lair. I believe we were able to successfully set every pod up except for one (which was set up the next day).

That's essentially all we have done so far.

September 7, 2015

We didn't really do much in HPC. I believe Dan and Brian set some stuff up (I can't remember what they did). Currently we are just looking for any possible bugs that is in the current pod system. For example, there was a problem with VIM where you could not backspace. Andrew Hoover found the solution to this problem, where setting backspace=2 solved it.

vim ~/.vimrc

Add in the line “set backspace=2”.

I believe for next class we will be working on cable management. We will try our best to organize the cables, as in their current state, it looks very messy and unorganized.

Data Structures

September 1, 2015

We talked about what data structures is all about. Essentially, it is about writing code which is efficient and doesn't eat up resources. In previous programming courses, we are taught how to program, but not how to program effectively and efficiently.

We learned about something called a LinkedList. It is basically an array except each element is in a random location in memory (instead of being lined up, like in an array). Matt showed us an example of this using a struct called node. Node contained two variables, a signed short int called value and a struct node pointer called next. Basically, each instance of struct node is an element in a LinkedList. Each element of this struct node will then point to the next instance in the LinkedList.

Our first project for this course is to create a program which will simulate a LinkedList except using an array (for now). The purpose of this project is so that we can get a refresher of C and so that we can start leading into data structures.

September 7, 2015

Today I finished the first project for dsi0. Here is the code:

#include <stdio.h>
 
int main() {
	// initialization of variables
	int loopMenu = 1;
	int numbers[21];
	numbers[0] = -1;
	// loop through all indexes in array and set it to zero
	int j;
	for(j = 1; j <= 20; j++) {
		numbers[j] = 0;
	}
	int currentIndex = 0;
	// will loop the main menu until the user requests to exit
	do {
		printf("\nMenu Options\n");
        	printf("1 = build list\n");
        	printf("2 = display list\n");
        	printf("3 = insert into list\n");
        	printf("4 = append into list\n");
        	printf("5 = obtain from list\n");
        	printf("6 = clear list\n");
        	printf("7 = quit\n");
        	int option = 0;
        	printf("\nEnter an option: ");
		// scans in option number
        	scanf("%d", &option);
		// checks which option it is
		if(option == 1) {
			printf("\n");
			// checks if the max amount of numbers has been built into array
			if(currentIndex == 20) { 
				printf("You have reached the limit of 20 numbers.\n");
			} else {
				int loopAppend = 1;
				// will loop until -1 is input or the limit is reached
                        	do {
                                	int input = 0;
                                	printf("Input a number to add to the list: ");
                                	scanf("%d", &input);
					// checks if they have reached the limit
                                	if(currentIndex == 20 && input != -1) {
						printf("You have reached the limit of 20 numbers.\n");
						loopAppend = 0;
						numbers[20] = -1;
                                	} else {
						numbers[currentIndex] = input;
						printf("numbers[%d] = %d\n", currentIndex, input);
						if(input == -1) {
							loopAppend = 0;
						} else {
							currentIndex++;
						}
					}
                        	} while(loopAppend == 1);
			}
		} else if(option == 2) {
			// checks if the list has any numbers
			if(numbers[0] == -1) {
				printf("Your list has no numbers.\n");
			} else {
				printf("List Contents:\n");
                        	int i;
				// loops through all indexes; prints them
                        	for(i = 0; i < 21; i++) {
                                	int number = numbers[i];
                                	if(number == -1) {
                                        	break;
                                	} else {
                                        	printf("numbers[%d] = %d\n", i, number);
                                	}
                        	}
			}
		} else if(option == 3) {
			int index = 0;
			printf("Enter index: ");
			scanf("%d", &index);
			if(index < 0 || index > currentIndex) {
				printf("The index must be between 0 and %d.\n", currentIndex);
			} else {
				int input = 0;
				printf("Enter the number you wish to insert: ");
				scanf("%d", &input);
				int i;
				// shifts the array
				for(i = currentIndex; i >= index; i--) {
					int numAt = numbers[i];
					int newIndex = i + 1;
					if(newIndex == 20) {
						numbers[20] = -1;
					} else {
						numbers[newIndex] = numAt;
					}
				}
				currentIndex++;
				if(currentIndex > 20) {
					currentIndex = 20;
				}
				// sets the input in for the destination index
				numbers[index] = input;
			}
                } else if(option == 4) {
			int index = 0;
			printf("Insert index: ");
			scanf("%d", &index);
			if(index < -1 || index > (currentIndex - 1)) {
				printf("The index must be between -1 and %d.", currentIndex - 1);
			} else {
				index++;
				int input = 0;
				printf("Enter the number you wish to append: ");
				scanf("%d", &input);
				int i;
				// shifts the array elements over
				for(i = currentIndex; i >= index; i--) {
					int numAt = numbers[i];
					int newIndex = i + 1;
					if(newIndex == 20) {
						numbers[20] = -1;
					} else {
						numbers[newIndex] = numAt;
					}
				}
				currentIndex++;
				if(currentIndex > 20) {
					currentIndex = 20;
				}
				// sets the input number in for the dest index
				numbers[index] = input;
			}
                } else if(option == 5) {
			int index = 0;
			printf("Insert index: ");
			scanf("%d", &index);
			// checks if the index is present in the list
			if(index < 0 || index >= currentIndex) {
				printf("The index must be between 0 and %d.", currentIndex - 1);
			} else {
				// prints what the number is in that index
				printf("numbers[%d] = %d\n", index, numbers[index]);
				int i;
				// removes the number at that index and shifts everything over
				for(i = index + 1; i <= currentIndex; i++) {
					int numAt = numbers[i];
					int newIndex = i - 1;
					numbers[newIndex] = numAt;
				}
				currentIndex--;
				if(currentIndex < 0) {
					currentIndex = 0;
					numbers[0] = -1;
				}
			}
                } else if(option == 6) {
			// sets the first (zero-th) index to -1
			numbers[0] = -1;
			currentIndex = 0;
			printf("The list has been cleared.\n");
                } else if(option == 7) {
			// exits...
			loopMenu = 0;
			printf("Exitting...\n");
                } else {
			printf("Incorrect menu option.\n");
		}
	} while(loopMenu == 1);
	return 0;
}

The project wasn't insanely difficult, but it did require some thinking, especially for the insert into and append features of the program. Everything else wasn't very hard but it did require some thinking to make it so that everything worked together.

blog/fall2015/mmalik1/journal.1441672281.txt.gz · Last modified: 2015/09/08 00:31 by mmalik1