User Tools

Site Tools


opus:spring2012:smalik2:part2

Part 2

Entries

Entry 5: March 11, 2012

For the UNIX course I am playing around with the IRC bot phenny.

It's pretty cool, but since I had a ton of trouble with scripting, the scripting for this case study is taking me awhile to take care of.

The idea behind bots is really cool though, just whenever you need something done based on some condition, you can get a bot to do it for you. Quite neat.

Entry 6: March 18, 2012

In C++ this past week we worked on Project 2 and more stuff on classes and whatnot in C++. This C++ material is something I've never been exposed to before, but it makes sense if you have a very very large program and want it to be even more organized. We also dealt with header files, which are useful as they make the code less cluttered.

Regarding Project 2, it's the first thing that I had to resort to using pencil and paper to get it all organized before coding it, which I know is a good habit. Hopefully I will stay on that same track.

Entry 7: March 30, 2012

This past week in C++ we did a lot of playing around with inheritance and all that good stuff.

We basically build classes and functions within the classes that would run logical operations and returning the boolean values.

At first it was like hitting a brick wall, I would bet because the syntax was unlike anything I have ever seen before. It does make sense why one would want to do this however… for a large scale team effort on something, it would provide a good means for organization. But when it comes to my own programming, I can't really see myself using it unless I was working on something very big and very segmented where it would be a good advantage.

It took awhile to understand it, but once I did the actual coding was fairly smooth sailing, I've managed to create classes and functions to perform and, or, not, nor, and nand operations.

Entry 8: April 17, 2012

In unix I did a bunch of pattern matching and regexp stuff.

At first it was kind of hard, but once I got the syntax down it was fairly easy.

I can see how it's useful, especially in word processing and stuff. It helps you manipulate information much more quickly. Which is never a bad thing.

Keywords

cprog Keywords

9. Type Casting

Definition

Type casting is basically telling the program to treat a certain entity (an int, char, whatever) using the rules of a different one.

Demonstration

So if we use…

int a = 3; int b = 5;

int c = a/b;

c is actually zero, because of integer division. But if we use this line instead….

int c; (float)c = a/b;

The (float) is a type cast to c, telling the program to treat c as a float, which would ensure that it stores a 0.6 instead of a 0.

10. I/O Streams (cin, cout, cerr, stream operators) [C++]

Definition

Needs #include <iostream>

cout produces output ~ printf cin provides input ~ scanf cerr is just the error output stream operators are things such as setf() and setw() which held you do different things with the stream.

Demonstration

int a=1 int b=2

printf(“a is %d, b is %d\n”, a, b); cout « “a is ” « a « “,b is ” « b « endl;

scanf(“%d”, %a); cin » a;

cerr « “Error, yo” « endl;

Stream operator in use: cout « setw(5) « a « “ sheep are sleeping.” « endl;

11. Header Files (Local and System), C Standard Library (Libc), Libraries

Definition

Header files are basically files that contain class and function 'prototypes'. It basically will let the program know that there is a class or function which is named something, and the types of parameters and return type it has. Local Header files are the ones that tend to be user made, or could get pulled in from another source I suppose. System header files are the ones that are in the system.

The C Standard Library has a bunch of the most common and useful C header files I would guess, such as stdio for input and output capabilities.

Libraries in C contain all of these functions and whatnot in them.

Demonstration

To call a system header

#include <stdio>

To call a local header

#include “nor.h”

12. Arithmetic (equations, operators)

Definition

Arithmetic is the way that we can manipulate data. Equations would set some value equal to something else, while operators can compare values.

Demonstration

To assign a value to a variable using an equation:

Density = 50*8/13;

To compare using an operator:

if (Density < 100)
{
    printf("Wow")
}

13. Scope (Block, Local, Global, File)

Definition

Scope is basically the region of the program in which a declared variable will exist. Block would mean the scope is in regards to the set of brackets you're in. Local would mean within a function. Global would mean within an entire file of code. File would (I assume) mean between files. Although how to do this I do not know.

Demonstration
if( x>3)
{
    int Q = 5;   // Q only exists within this if statement
}
 
int Sum1(int num1, int num2)   //these two integers are only defined within this function!
{
    return (num1 + num2)
}
 
int x;     //this variable will be defined throughout the entire file, regardless of functions and whatnot.
int main()
{
    x = 4
}

14. Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments

Definition

Functions are basically isolate segments of code that can do certain things based on Parameters that you pass them. It saves a lot of coding, for example, to have a function that you just send different values of length and width to calculate the area of 50 squares is much easier than actually writing the code to do 50 different areas.
Return Types are the variable type that the function will be returning- in the case of the area function, we would probably want to return a float value.
Recursion is basically when a function calls itself within itself, with some end terminating condition. We haven't covered it in class yet though.
Command-line arguments are when you pass parameters to the main function of the program.

Demonstration

There are some great examples of functions in Project 1 and Project 2. Everything is used except Recursion.

15. Overloading (Functions, Operators) [C++]

Definition

Overloading a function is to use the same function name for multiple functions, with the difference being the parameters passed to the function.

Demonstration

Let's say we want to write a program that will calculate areas. Rectangles, Squares, and Circles. We'll overload a function to do this.

int Area(int);    //for the square
float Area(float, float);   //for the rectangle
float Area(float);    //for the circle

These functions will actually work, and depending on the parameters that we send, it will either call the one meant for squares, rectangles, or circles!

16. Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

Definition

Inheritance is how classes can inherit the stuff from the public and protected part of their 'parent' class. Multiple Inheritance is when there are multiple layers going on.

Demonstration

To see an excellent example of inheritance, over multiple files, in my directory… /home/smalik2/src/cprog/c++

There is a multifile program using classes and inheritance and multiple inheritance.

cprog Objective

cprog Objective

break down and separate code into functions and illustrate the use of parameter passing

Definition

If you need to write a huge long program that does multiple things, that are similar to one another, this will be the capability to recognize the need for and be able to split the program apart into functions, so that code repetition is minimized and the code is more efficient.

Method

If I start doing what I said in the definition. Which I believe I already do fairly solidly. In Project2 we continuously printed arrays, so I actually just made a function that would print an array given the array name and the length of the array.

Measurement

I did a lot of this in Project 2.

Analysis

I just did it. There's always room for improvement, but it is not desperately needed. There's not really a way to enhance checking to see if you can do it. I think the objective is stated nicely.

unix Keywords

9. Tab Completion

Definition

Tab completion is being able to auto-complete typing a command by hitting tab.

Demonstration

If you have a program called thebiggestnumberis, and you want to execute it, you would type ./thebiggestnumberis

But using tabcompletion you can just type ./thebi [hit tab] and it will automatically fill it.

If there is another program in the directory that is called thebiggestloseris, then this won't work because there are possible combinations. you will have to type out even more of the program name before the tab completion will work.

10. Wildcards

Definition

The wildcard is the * in unix, and basically means (anything or whatever can do here).

Demonstration

lab46:~/src/unix/Labs$ ls la ls: cannot access la: No such file or directory lab46:~/src/unix/Labs$ ls la* lab0.txt lab1.txt lab2.txt lab3.txt lab4.txt lab5.txt lab6.txt lab46:~/src/unix/Labs$

See how the wildcard enabled the ls command to actually work.. and it gave all names that began with the la[insert anything here]. Cool.

11. Job Control

Definition

Job control is basically multitasking. It gives you the power to perform actions and run them in the background, leaving you free to do whatever else you want. It also allows you to kill these other processes.

Demonstration

We can display current running processes with ps

We can tell a command to run in the background by adding a & to the end of the command. Running fg #(process number) will bring that thing back to the foreground.

You can also use kill commands to kill the process, or using ctrl + C

12. The UNIX Shell

Definition

The UNIX shell is the way that the user uses the OS, called a Command Line Interpreter (CLI).

Demonstration

The shell is the command prompt. Whoa!

13. Environment variable

Definition

An Environment variable is basically a thing that stores some useful piece of information. An example would be how $HOME holds the users home directory.

Demonstration
lab46:~$ echo $PATH
/home/smalik2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
lab46:~$

14. $PATH

Definition

The $PATH variable holds the locations of executable programs.

Demonstration
smalik2@lab46:~$ echo $PATH
/home/smalik2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
smalik2@lab46:~$ ls /usr/games
adventure   caesar     gomoku   nethack          primes  snake        worms
arithmetic  canfield   hack     nethack-console  quiz    snscore      wtf
atc         cfscores   hangman  number           rain    teachgammon  wump
backgammon  countmail  hunt     phantasia        random  tetris-bsd
battlestar  cribbage   mille    pig              robots  trek
bcd         dab        monop    pom              rot13   wargames
boggle      go-fish    morse    ppt              sail    worm
smalik2@lab46:~$

Based off this, we can see that /usr/games is in $PATH. I ran ls on that directory, and sure enough, the games listed there can be run as commands from my home directory.

15. The UNIX Programming Environment

Definition

The UNIX programming environment is basically just the ability to create programs using a UNIX operation system.. doesn't seem like there's much else to it.

Demonstration

16. Shell Scripting

Definition

I see shell scripting as 'programming' commands. You make a file and basically use bash to 'code' a series of commands and whatnot that the shell will run if you run the file.

Demonstration
echo enter your birth year
read birthyear
currentyear=$(date +%Y)
let birthyear=$currentyear-$birthyear
echo $birthyear
smalik2@lab46:~/src/unix/scripts$ ./age.sh
enter your birth year
1993
19
smalik2@lab46:~/src/unix/scripts$

unix Objective

unix Objective

The ability to accomplish/automate tasks.

Definition

Given a problem, one would be able to carry out the solution. Or be able to write a script to automate tasks to accomplish the goal - solving the problem.

Method

How easily I can do the labs.

Measurement

Normal stuff I can take care of reasonably easily. When it comes to scripting however, I have difficulty. It isn't impossible for me though.

Analysis

I can solve problems pretty effectively, especially with the help of google. Scripting was very difficult for me to get a grasp on, but now I am moderately comfortable with it. Overall I think I am pretty good at accomplishing/automating tasks - I would give myself a B in my capability.

Experiments

Experiment 4

Question

I'm not trying to answer a specific question, but the goal of this whole thing is to figure out all that inheritance stuff in C++ using the 'project' that Haas proposed to us in class. Of making a program that will perform and, or, not, nand, nor, etc.

Resources

All the stuff that we've done in class.

Hypothesis

The result will be a working program that will perform various logic functions using boolean values, and

Experiment

Working on coding the program.

Data

So far I have classes and inheritance working for and, or, and not. I have multiple inheritance applying to nor and nand working right now. I believe the only thing left is XOR.

All the files are in /home/smalik2/src/cprog/c++

Analysis

It's working well, the main obstacle was the syntax behind it all, as it is unlike anything I have ever seen.

Conclusions

When the material was originally taught, I understand the concept behind it but not how to do it. Now I have a very in depth understanding of it and how to utilize it.

Experiment 5

Question

In Case Study B for Unix/Linux, we were having fun with the dd command. At one point in the lab, Mason and I were combining our problem solving ability to tackle some of the more difficult questions, one of them being to add 17 bytes of information to the end of an 8kB file. We are supposed to pull JUST THOSE 17 BYTES from the file, using dd.

Eventually, Mason came up with the proposed spell: dd if=test.file ibs=c count=8017 skip=8kB of=testA.file Which worked beautifully.

It occurred to me that the count=8017 might be redundant, because the full file size is 8017 anyway - why would dd default to anything else?

So, my question is: would that command still work if we didn't specify count? I'm betting yes.

Resources

None really, except maybe:

man dd

Hypothesis

Oh I kind of already did this in the question section. I'm betting that the command will still work if we don't specify count, because count in that case was the full file size anyway.

Experiment

Do it with count, check result. Reset. Do it without count being specified, check result.

Data

lab46:~$ dd if=test.file ibs=c count=8017 skip=8000 of=testA.file
17+0 records in
0+1 records out
17 bytes (17 B) copied, 0.0441264 s, 0.4 kB/s
lab46:~$ cat testA.file 
more information
lab46:~$ dd if=test.file ibs=c skip=8000 of=testB.file
17+0 records in
0+1 records out
17 bytes (17 B) copied, 0.0454818 s, 0.4 kB/s
lab46:~$ cat testB.file 
more information
lab46:~$ 

Analysis

Yes, I was right. It still worked. Same result. Ohhhh I love being right. There were no shortcomings in any way, and my hypothesis was nicely applicable. Very smooth experiment.

Conclusions

When using dd, the count argument need only be used if you need to stop copying before you reach the end of the file. For example, in a 50 byte file, let's say you need bytes 3-18.

dd if=input.file ibs=c skip=3 count=15 of=output.file

Retest 2

Perform the following steps:

State Experiment

http://lab46.corning-cc.edu/opus/spring2012/jcavalu3/start#experiment_1 Josh Cavaluzzi

What would be printed if I replace the %u with the $d for an unsigned integer?

Resources

* Do you feel the given resources are adequate in providing sufficient background information? Yes * Are there additional resources you've found that you can add to the resources list? Not particularly, it's a pretty simple concept that can be easily surmised. * Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment? Yes. * If you find a deviation in opinion, state why you think this might exist. I agree with everything stated.

Hypothesis

Hypothesis: I believe that the printed value will be the same ONLY if it is within the range of the signed integer data type. Ex. If the user inputs a value between 0 and 2,147,483,647, then it should print out fine, but if the value is greater than that range, then the value will “roll over” to the next integer in the signed integer data type, which would make the value a negative number. Due to the data type only covering positive numbers (unsigned integer), it can go to larger numbers in the 4 bytes it is given for memory, but if it is printed as a signed integer, then it will only be able to print out half of the positive integers that it could as an unsigned integer, so it will go back over into the negative numbers until it satisfies the amount of digits it has.

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?

Yes

  • What improvements could you make to their hypothesis, if any?

None.

Experiment

  • Are the instructions correct in successfully achieving the results?

Yes

  • Is there room for improvement in the experiment instructions/description? What suggestions would you make?

Not realy. * Would you make any alterations to the structure of the experiment to yield better results? What, and why? Nope.

Data

Publish the data you have gained from your performing of the experiment here.

I used his code and got the exact same results.

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author? Yes
  • Can you explain any deviations? There weren't any.
  • How about any sources of error? Not really. Unless a computer has a different definition for an integer.. but we were using the same system.
  • Is the stated hypothesis adequate? Yes.

Conclusions

Answer the following:

  • What conclusions can you make based on performing the experiment? He's right.
  • Do you feel the experiment was adequate in obtaining a further understanding of a concept? Yes
  • Does the original author appear to have gotten some value out of performing the experiment? Yes
  • Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).

Nope

opus/spring2012/smalik2/part2.txt · Last modified: 2012/04/22 22:26 by smalik2