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.
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.
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.
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.
Type casting is basically telling the program to treat a certain entity (an int, char, whatever) using the rules of a different one.
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.
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.
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;
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.
To call a system header
#include <stdio>
To call a local header
#include “nor.h”
Arithmetic is the way that we can manipulate data. Equations would set some value equal to something else, while operators can compare values.
To assign a value to a variable using an equation:
Density = 50*8/13;
To compare using an operator:
if (Density < 100) { printf("Wow") }
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.
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 }
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.
There are some great examples of functions in Project 1 and Project 2. Everything is used except Recursion.
Overloading a function is to use the same function name for multiple functions, with the difference being the parameters passed to the function.
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!
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.
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.
break down and separate code into functions and illustrate the use of parameter passing
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.
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.
I did a lot of this in Project 2.
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.
Tab completion is being able to auto-complete typing a command by hitting tab.
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.
The wildcard is the * in unix, and basically means (anything or whatever can do here).
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.
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.
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
The UNIX shell is the way that the user uses the OS, called a Command Line Interpreter (CLI).
The shell is the command prompt. Whoa!
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.
lab46:~$ echo $PATH /home/smalik2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games lab46:~$
The $PATH variable holds the locations of executable programs.
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.
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.
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.
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$
The ability to accomplish/automate tasks.
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.
How easily I can do the labs.
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.
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.
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.
All the stuff that we've done in class.
The result will be a working program that will perform various logic functions using boolean values, and
Working on coding the program.
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++
It's working well, the main obstacle was the syntax behind it all, as it is unlike anything I have ever seen.
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.
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.
None really, except maybe:
man dd
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.
Do it with count, check result. Reset. Do it without count being specified, check result.
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:~$
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.
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
Perform the following steps:
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?
* 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: 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.
Yes
None.
Yes
Not realy. * Would you make any alterations to the structure of the experiment to yield better results? What, and why? Nope.
Publish the data you have gained from your performing of the experiment here.
I used his code and got the exact same results.
Answer the following:
Answer the following:
Nope