User Tools

Site Tools


opus:fall2011:dgirard3:part3

Part 3

Entries

November 3, 2011

This week for class we did a mix bewteen working on stuff and learning stuff. Tuesday we just worked on projects and opus, and we got to mess with the video wall. We learned to display images on others computers user their server region (where they happen to be sitting) and we were able to display logos, eyes and anything else we could find. WE played with that and also worked on things. I worked on my optical archiving, its done it just needs to be documented and once that is complete, the project is complete. Thursday we took a spring 2012 catalog course list and cut it down with regular expressions and grep and sed and other commands. We took an almost un readable html code and made it so anyone can read it easily. For C i have read some of the book and started 2 projects, multiplication table and fun with colors. I also finished the datatypes and soon these programs will be finished and executed well.

November 10, 2011

This week we worked with regular expressions and taking apart an html text. We took apart a course catalog from an unreadable version to a version that any person can read. It took a long expression because of how much was needed to be removed but in the end it was not that hard. We used sed and cut and the list of regular expressions you have learned. And on the side of this, we have taken some time to just work on projects and and opus. I have been working on the encoding and its so close to being finished, its just has some minor malfunctions that needs to be fixed. And in C, i have been working on roshambo and multiplication table. I got the table finished and documented and just starting on roshambo. Its not going to be too hard, its the logic that might be a little confusing. But other than that, that is what i have worked on this week and what has been learned.

November 17, 2011

This week we did the same thing just took the text apart a little bit differently. We used sed and regular expressions as usual but this time we used a new command called tr. tr translates or deletes characters, so you are basically you are just replacing characters with another character so like you want the letter “a” to be deleted. replace it with “\n” and it will cut out that word and just have an endline in the place. Regardless of that, all we did was play time and i worked on my optar project and i got it finished and i have made my own optar project for everyone to use. In c i have been just working on projects and trying to get as many as i can done. I have finished one project and one is close to done, just need to add a few loops and variables and everything should fall into place.

November 24, 2011

This week was break week so not much was done, I still had class on tuesday and we took that day as a play day and just worked on whatever was needed to be done, I worked a little bit on some projects but not all of them. I have 7 projects but 2 have yet to be finished and i probably will have to create a few more to reach all my attributes. Until then i only have a few projects to go in this class and the EOC experience. In C i have been doing the same thing and just doing projects. I am in a rut on my roshambo so i have moved on and will come back to it whenever i finish a few other projects. I also have a EOC experience for this class as well so i need to do around 4 projects in this class plus that. So all tpgether i have 2 EOCE and 6+ projects to complete.

cprog Topics

Recursion

Recursion is technically another way of looping but its not looping. Its where a function will call itself and essentially loops itself.

This is a simple example of recursion

void recurse()
{
  recurse(); //Function calls itself
}

int main()
{
  recurse(); //Sets off the recursion
}

this is more of a detailed sample of recursion.

#include <iostream>

using namespace std;

void recurse ( int count ) // Each call gets its own count
{
  cout<< count <<"\n";
  // It is not necessary to increment count since each function's
  //  variables are separate (so each count will be initialized one greater)
  recurse ( count + 1 );
}

int main()
{
  recurse ( 1 ); //First function call, so it starts at one        
}

Command-line arguments

It is possible to use commands from the command line in linux to your program in c/c++. The main can actually accept two arguments: one argument is number of command line arguments, and the other argument is a full list of all of the command line arguments. an example of this is in the code block below.

#include <stdio.h>

int main ( int argc, char *argv[] )
{
    if ( argc != 2 ) 
    {
        
        printf( "usage: %s filename", argv[0] );
    }
    else 
    {
        
        FILE *file = fopen( argv[1], "r" );

        
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
            int x;
            
            while  ( ( x = fgetc( file ) ) != EOF )
            {
                printf( "%c", x );
            }
            fclose( file );
        }
    }
}

Code stages (Source, Object, Binary)

When you write programs, that code you have written goes through a few stages. It turns into a different format of code, but it is still the same. Source code is what you type out on your text editor or wherever you type it. Then when you go to compile, your code becomes object code after the steps where its does a syntax check and token check, it goes into a the assembler and it turns into object code. Then after it checks the libraries and code, it becomes executable which is binary.

C Library, Libraries, and Makefiles

The C library is essentially your main library for programming. It contains your main ISO functions that you need such as printf and scanf. You use these on a daily basis so you can just put these libraries up and full access to these function. There are of course other libraries such as math.h, for your mathematical uses and such. Libraries allow you to pull out functions that are very common, so you dont have to write code for it every time. Then you have makefiles, this is where you can take a huge program, take the different parts inside it (such as main, functions and headers) and you can compile them separately. But after its compiled it goes into one file for execution. This is the better way to go because if there is an error, it is very easy to spot and fix instead of going through a huge code.

Multi-file programs (how to structure, how to compile)

A multi-file program works similar to makefiles. If you have a big file, with a big main function and a big side function, you dont want to compile it, find something wrong and search through all that code. So with a multi-file, it will take each part of the program (the main function, other functions, and even header files) and it will put them in their own separate files, compile them and put it all into one working file for you to use.

Version Control (checkout, commit, update, add, log)

Version control is the same as revision control, this is the ability to track and control the changes in projects, programs or file changes. When you change a project in some way, it saves the older version. So you are able, if a mistake is made, you can go back a bring back an older copy and start from where you were before. When you checkout you are going back into the repository for a working copy, so go back a grab a copy. When you commit, yoou make a change on the project or store a change in the version control database. Updating is where you make sure that commits are on your copy or that your copy is “up to date” with everyone elses. Adding is where you can add changes into a copy, as long as that they do not overlap each other, if it does, that is an issue with the head person of the project. log is where you leave a message with your commit to let a person know what has been done and why.

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

I/O streams are there for you to streams classes that can read from a file, write to a file or do both from/to a file. cin is for writing to a file, it accepts user input and goes to a file for use later on. cout reads from a file and prints out the data from a place you pull from. cerr is there incase you run into an error and this will check for those and let you know. These are many stream opators that you will use in c++ you could have int, char and float from the ostream. You can pull out a lot of operators for you to use in your program.

Exception Handling (throw, try, catch) [C++]

Exceptions handling is a way to help us react to common circumstances like a run time error, and we do this by using special functions called handlers. So you will make a separate function with a try block. This try block will execute the throw and catch. The throw excepts one parameter and acts as an argument. The type of parameter here is important because whatever it is here has to be the same for the catch argument, so it can be “caught”. catch is also has a single parameter and acts as an argument as well. However you dont have to have a specific data type so you can chain catch expressions. The thing that would happen is if it does not have a corresponding datatype with a throw, it just wont execute.

// exceptions
#include <iostream>
using namespace std;

int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << endl;
  }
  return 0;
}

Namespaces [C++]

Namespaces allows a person to take entities like classes, objects and functions, and put it under a name. This is so instead of have multiple entities in one big global scope, you can smaller sub-scopes with their own name. You also have a tool called using, which allows you to make a directive of which names you want to use.

// using
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
  int y = 10;
}

namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}

int main () {
  using first::x;
  using second::y;
  cout << x << endl;
  cout << y << endl;
  cout << first::y << endl;
  cout << second::x << endl;
  return 0;
}

Polymorphism/Virtual Functions [C++]

Polymorphism is where you can implement ways of a function to work different ways. So say you wrote a program for a bird flying, it could flap its wings like crazy or it could glide amazingly. The function does not care how it flies, just that it does fly. So you could create a function that could work for any function from any class you make.

class bird
{
public:
  virtual void fly() = 0;
}

Migrate function that can accept any bird.

void migrate(bird* tweetiepie)
{
  // ...
  tweetiepie->fly();
  // ...
}

Main program

class swallow : public bird
{
public:
  virtual void fly()
  {
    flap_wings_like_crazy();
  }
};

class albatross : public bird
{
public:
  virtual void fly()
  {
    glide_majestically_over_the_waves();
  }
};

then with this you could choose any bird and throw it into the migrate function

swallow s;
albatross a;

migrate(&s);
migrate(&a);

Function Overloading [C++]

This is where you declare more than one function in the same scope. So say you have a print function that displays an int. Well in the same scope, you also have print functions that displays a double and a char. When you overload a function you must have different datatype or different arguments in order for it to be properly overloaded. In easier terms, you can kind of mix functions together to all run in one big function, this is a similar form of polymorphism.

#include <iostream>
using namespace std;

void print(int i) {
  cout << " Here is int " << i << endl;
}
void print(double  f) {
  cout << " Here is float " << f << endl;
}

void print(char* c) {
  cout << " Here is char* " << c << endl;
}

int main() {
  print(10);
  print(10.10);
  print("ten");
}

Abstract Base class[C++]

An ABC is classes that deal with a abstract concept. Like the concept of vehicles, when you say vehicles one thinks of a car. Well in reality a car is not the only vehicle, which makes it abstract. In vehicle you have space shuttle, ocean liner, bicycle, car, van and etc. So in an implementation view say you have a class of vehicle (class vehicle) and you have derived classes of cars. bicycles and etc. An ABC is a class that has one or more pure virtual member functions. You cannot make an object (instance) of an ABC

unix Topics

X Window System

This is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X. One implementation with this is a simple and fun one called xeyes, it brings up a pair of eyes that will follow your mouse. This can only be done on computers with x system hardware remember. But that is something basic, it brings up fun graphical objects you can use.

High-Performance computing

HPC develops supercomputers and software to run on supercomputers. A main area of this discipline is developing parallel processing algorithms and software: programs that can be divided into little pieces so that each piece can be executed simultaneously by separate processors. In easier terms, you can run one screen across 12 computers or more. So it can be a wall of 12 computer screens and combined into one big one.

The VI text editor

The VI text editor is a very powerful text editor on the linux system. It is not like any other ordinary editor, most have commands and line editing in one, this one has separate modes. You have a command mode and a insert mode. Command mode lets you do commands like save, delete, cut, copy and many more you could normally do on other text editors. In insert mode is where you will be doing most work. You type whatever you want here and such. Generally you switch between the 2 modes with esc or I, but there are other advanced ways, like A will take you into insert mode at the place after your cursor, to be much more precise and faster when editing your text. Also a separate file called vimrc.info allows you to customize it to the way you want.

  1 This is an example of vi. You can type files that are text or make executabl
    e. The number you see to the left are preset and when programming, i have
    them preset to highlight. This is a very good editor and can be amazing once 
    you get the hang of it.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT --                                                  1,178         All

Enviroment Variable

Within the shell, a variable that is stored in the environment. The environment is inherited by all the child processes,so the environment variables can be thought as global variables. They are not strictly global however because changes by the child are not propagated by the parent. So some things like $PATH, that is a environment variable. This searches through a list of files and directories for the command you may have typed in. You can add your own paths in if you want to run any commands of your own from your home directory or where ever.

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

This is where i can run commands and programs from.

Text Processing

This is where you manipulate text in anyway that you want. You can make it to be in any format or you can replace things with other things! or just make it so its easier to read. text manipulation uses regular expressions and commands like cut, grep and sed.

lab46:~$ cat Schedulecut
cat spring2012-20111103.html | grep 'ddtitle' | sed 's/^<TH CLASS="ddtitle".*crn_in=.....">//g' | sed 's/<\/A.*$//g' | sed 's/^\(.*\) - \([0-9][0-9][0-9][0-9][0-9]\) - \(.*\) - \([0-9][0-9][0-9]\)$/\2:\3-\4:\1/g' | sort | less
lab46:~$

this example above was to cut down a html formatted course list into a easily readable format that anyone could read. If you are able to master this, you will be greatly respected.

Copying

Copying in linux is very simple. If you want to copy a directory or a file just use the cp command along with the file you want to copy and the name of the file you want the copy to be called.

lab46:~$ vi copyme
lab46:~$ ls
Cexetension.tgz   a.out              irc           puzzlepaper
Desktop           badname            lab1a.text    regularexpressions
Documents         badname.tgz        motd          scripts
Downloads         bin                networkcmds   spring2012-20111103.html
FilelistforOPTAR  candy              newdirectory  src
Maildir           classlog12         out           test
Music             contact.info.save  outfile       test2
Nyan Cat.wav      copyme             output        tmp
Public            courses            pgm2ps        unixprog
Schedulecut       data               pss           wildcards
Templates         dl                 public_html
Videos            in                 puzzlebox
lab46:~$ cp copyme hiopus
lab46:~$ ls
Cexetension.tgz   a.out              in            puzzlebox
Desktop           badname            irc           puzzlepaper
Documents         badname.tgz        lab1a.text    regularexpressions
Downloads         bin                motd          scripts
FilelistforOPTAR  candy              networkcmds   spring2012-20111103.html
Maildir           classlog12         newdirectory  src
Music             contact.info.save  out           test
Nyan Cat.wav      copyme             outfile       test2
Public            courses            output        tmp
Schedulecut       data               pgm2ps        unixprog
Templates         dl                 pss           wildcards
Videos            hiopus             public_html
lab46:~$

Moving/Renaming

Another simple process in linux. This is where you can move a file into a new directory or move a directory into a directory. All you need is the command mv, the file/directory you want to move and where you want to move it.

lab46:~$ vi moveme
lab46:~$ mkdir gohere
lab46:~$ mv moveme gohere
lab46:~$ ls
Cexetension.tgz   Maildir       Templates    bin                courses  in           newdirectory  pss                 scripts                   tmp
Desktop           Music         Videos       candy              data     irc          out           public_html         spring2012-20111103.html  unixprog
Documents         Nyan Cat.wav  a.out        classlog12         dl       lab1a.text   outfile       puzzlebox           src                       wildcards
Downloads         Public        badname      contact.info.save  gohere   motd         output        puzzlepaper         test
FilelistforOPTAR  Schedulecut   badname.tgz  copyme             hiopus   networkcmds  pgm2ps        regularexpressions  test2
lab46:~$ cd gohere
lab46:~/gohere$ ls
moveme
lab46:~/gohere$

Removing

Removing files and directories is easy as well. Choose whatever file or directory you want and use the rm command to remove it.

lab46:~/gohere$ cd
lab46:~$ rmdir gohere
rmdir: failed to remove `gohere': Directory not empty
lab46:~$ cd gohere
lab46:~/gohere$ rm moveme
rm: remove regular file `moveme'? y
lab46:~/gohere$ cd
lab46:~$ rmdir gohere
lab46:~$

As you see here, in order to remove a directory it must be empty and you have to add a “dir” to the rm command to specify its a directory and not just a file.

Creating

This is also very simple. To create a file without any data in it, just use “the touch of god” or the touch command. It should create a file with 0 bytes, completely empty. But if you want a file with data in it all you need to do is type out what you want to put in the file and use the “>” to direct it to a existing file or one you create right on the spot. And in order to make a directory all you need is to use mkdir. It should give you a empty directory to store your files.

lab46:~$ touch touchme
lab46:~$ echo touchme
touchme
lab46:~$ file touchme
touchme: empty
lab46:~$ echo "yep... DIARRHEA" > invaderzim
lab46:~$ file invaderzim
invaderzim: ASCII text
lab46:~$ cat invaderzim
yep... DIARRHEA
lab46:~$ mkdir directoryofdoom
lab46:~$ ls
Cexetension.tgz   Maildir       Templates    bin                courses          in          networkcmds   pgm2ps       regularexpressions        test2
Desktop           Music         Videos       candy              data             invaderzim  newdirectory  pss          scripts                   tmp
Documents         Nyan Cat.wav  a.out        classlog12         directoryofdoom  irc         out           public_html  spring2012-20111103.html  touchme
Downloads         Public        badname      contact.info.save  dl               lab1a.text  outfile       puzzlebox    src                       unixprog
FilelistforOPTAR  Schedulecut   badname.tgz  copyme             hiopus           motd        output        puzzlepaper  test                      wildcards
lab46:~$

Current working directory

Your current working directory is where you are at that moment. It is where you run your processes and execute commands. You can figure out where exactly you are with the command pwd.

lab46:~$ pwd
/home/dgirard3
lab46:~$

Types of Files

There are many types of files in the linux system, actually everything is a file on this. There a few different types of files however. You have directories which hold these files. You have regular files such as text files, you have special files which holds programs and special data, you have executable which can execute programs and then you have data files which holds some sort of data link.

Files

Everything is a file in linux. Everything that you do has some sort of file to hold that data. Files are, in way, similar to text documents that you would keep and store away. And when you wanted that information, you go to where you put the paper and read the information. Thta is what a file is, just in the computer world its a resource for storing information. So say you use a command on the command line, it is actually using a path to go read directories and finding the file program that can enable you to use that command. Everything has a place in a file somewhere.

cprog Objective

Objective

know how to use arrays and pointers. This objective is basically saying if you understand the concept of arrays and pointers and an example will be shown here.

Method

I will explain how an array and a pointer will work through explanation and small examples.

Measurement

Arrays are essentially groups of data stored sequentially. Arrays can be a hard concept to understand but it is actually very simple. For a basic array all you really need is how to create and address them and how to manipulate the array. Well creating an array is simple this is all you need to do:

int array[20]; //This is an array that will hold int values
char array2[20] //This array will hold char values;

The Arrays above are similar in nature, they just hold different data types. The name of the array comes before the brackets so the top one is called array and the bottom one is array2. Then what is inside the brackets is the size of that array, how many variables are going into it. So this is a size of 20, going from 0-19. You can easily print out you elements you have inside your arrays as well.

int myArray [5] = {1,2,3,4,5};
/* To print all the elements of the array
for (int i=0;i<5;i++){
   printf("%d", myArray[i]);
}

Here is an easy way to print out the elements you have stored into your array. Now you can also perform operations inside an array, here is a sample program that shows how it all works.

#include <stdio.h>
void oneWay(void);
void anotherWay(void);
int main(void) {
   printf("\noneWay:\n");
   oneWay();
   printf("\nantherWay:\n");
   anotherWay();
}

/*Array initialized with aggregate */
void oneWay(void) {
   int vect[10] = {1,2,3,4,5,6,7,8,9,0};
   int i;
   for (i=0; i<10; i++){
       printf("i = %2d vect[i] = %2d\n", i, vect[i]);
   }
}

/*Array initialized with loop */
void anotherWay(void) {
   int vect[10];
   int i;
   for (i=0; i<10; i++)
        vect[i] = i+1;
   for (i=0; i<10; i++)
        printf("i = %2d vect[i] = %2d\n", i, vect[i]);
}

/* The output of this program is
   oneWay:
   i = 0 vect[i] = 1
   i = 1 vect[i] = 2
   i = 2 vect[i] = 3
   i = 3 vect[i] = 4
   i = 4 vect[i] = 5
   i = 5 vect[i] = 6
   i = 6 vect[i] = 7
   i = 7 vect[i] = 8
   i = 8 vect[i] = 9
   i = 9 vect[i] = 0

   antherWay:
   i = 0 vect[i] = 1
   i = 1 vect[i] = 2
   i = 2 vect[i] = 3
   i = 3 vect[i] = 4
   i = 4 vect[i] = 5
   i = 5 vect[i] = 6
   i = 6 vect[i] = 7
   i = 7 vect[i] = 8
   i = 8 vect[i] = 9
   i = 9 vect[i] = 10
   */

This is the operations with an array. Your array can also be multi dimensional, like an array inside an array. When you have an array you have rows and columns, The first [] will hold your number of rows and your second [] will hold your columns. Now to initialize this is a little bit different. It works like this:

int values [3] [4] = {
	{
		1, 2, 3, 4
	}
	{
		5, 6, 7, 8
	}
	{
		9, 10, 11, 12
	}
};

here is an example of a multi dimensional array storing and printing its values:

main ( )
{
	int stud [4] [2];
	int i, j;
	for (i =0; i < =3; i ++)
	{
		printf ("\n Enter roll no. and marks");
		scanf ("%d%d", &stud [i] [0], &stud [i] [1] );
	}
	for (i = 0; i < = 3; i ++)
	printf ("\n %d %d", stud [i] [0], stud [i] [1]);
}

Now with arrays comes the magical use of pointers. A pointer, in general, is a number representing a memory address. We call it a pointer because it is pointing to a place in memory we want to work with. You can establish what kind of pointer you want to work with like an int or char or even void. In order to point to something you use the asterisk (*) in front of the variable name. So here is a small of example of it. Now in the for loop, both lines will do the same thing, just in a different way:

#include <stdio.h>

int my_array[] = {1,23,17,4,-5,100};
int *ptr;

int main(void)
{
    int i;
    ptr = &my_array[0];     /* point our pointer to the first
                                      element of the array */
    printf("\n\n");
    for (i = 0; i < 6; i++)
    {
      printf("my_array[%d] = %d   ",i,my_array[i]);   /*<-- A */
      printf("ptr + %d = %d\n",i, *(ptr + i));        /*<-- B */
    }
    return 0;
}

Line A Just accesses the array like it normally would but line B points to the spot where you would like to begin and move on. This is a very simple concept of using a pointer but it gets the point across. You just pick a spot in memory and “point” to it, its that easy :D. Now it does get more complicated when you start pointing to strings or functions even.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do? I think i did pretty good
  • Room for improvement? Yes, there is so much more i can learn
  • Could the measurement process be enhanced to be more effective? Yes, possibly more information on certain parts
  • Do you think this enhancement would be efficient to employ? yes
  • Could the course objective be altered to be more applicable? How would you alter it? No i like how it is now

unix Objective

Objective

experience the connection between UNIX and C

Method

I will show how linux comes with a compiler built in “gcc”.

Measurement

Linux has its own compiler for The C source code. Its called gcc, and you use it to compile c programs written in vi text editor or nano. here is an example program that was written using C in VI:

  1 /*--- range.c begin ---
  2  * Compile with: gcc -o range range.c -lm
  3  * Execute with: ./range
  4  */
  5 #include <stdio.h>
  6 #include <math.h>
  7 
  8 int main()
  9 {
 10     // Variables
 11     unsigned long long int quantity = 0;
 12     unsigned long long int uc = 0;
 13     signed long long int sc = 0;
 14 
 15 // Display information for unsigned long int data type
 16     printf("An unsigned long int is %d bytes\n", sizeof(uc));
 17     printf("The range of an unsigned long int is %llu to %llu\n", uc, (uc-1));
 18     quantity = (unsigned long long int)(uc-1);    // What does this line do?
 19     printf("An unsigned long int can store %llu unique values\n\n", quantity);
 20 
 21 // Display information for signed long int data type
 22     printf("A signed long int is %d bytes\n", sizeof(sc));
 23     quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); // What is happening?
 24     printf("The range of a signed long int is %lld to %lld\n", (sc-(quantity/2)), (sc+(quantity/2)-1));
 25     printf("A signed long int can store %llu unique values\n\n", quantity);
 26 
 27     return(0);
 28 }
 29 //--- range.c end ---
 

Here is how you compile this program into an executable file:

gcc -o example datatypes.c

Linux works really well with the C language and i would so since it is written in C. Everything that this system does is run by a C program or a shell script. C is found everywhere on the linux system and these are like a perfect match for each other.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do? Not so good, i could do better but this part would delete on me every time i typed it
  • Room for improvement? Oh definitely
  • Could the measurement process be enhanced to be more effective? yes, there could be more
  • Do you think this enhancement would be efficient to employ? Yes, it gets the point across
  • Could the course objective be altered to be more applicable? How would you alter it? No it is fine, just technical error was making this difficult.

Experiments

Experiment 1

Question

Can i sudo onto linux?

Resources

My information comes from class :) so Matt Haas

Hypothesis

Umm well what sudo does is allow me to become root of the system. I am not root but its like an access window to be allowed to move around like a root user. With sudo, if i am allowed i should be able to do like anything i want cause im seen as a root user.

Experiment

I am just going to show the experiment right in the linux terminal screen.

Data

lab46:~$ man sudo
lab46:~$ sudo su -

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for dgirard3:
dgirard3 is not in the sudoers file.  This incident will be reported.
lab46:~$

Well there ya go xD

Analysis

Based on the data collected:

  • was your hypothesis correct? No it was not
  • was your hypothesis not applicable? Yes it was
  • is there more going on than you originally thought? (shortcomings in hypothesis) yes, i thought i could just use my name and password but i guess i must be listed as a superuser.
  • what shortcomings might there be in your experiment? Umm there is none, i just have no permission to do this so there is no more to do
  • what shortcomings might there be in your data? I believe i did everything right so noting :D

Conclusions

well a simple user of linux can not become a superuser. It kind of sucks cause i would like to have that power, but i cant. So if you try then you can not do it. Maybe one day me or someone else can be listed as the super user of a linux system.

Experiment 2

Question

Can you put a char in a int?

Resources

Class and matt haas :)

Hypothesis

I believe it can be done. I know a char holds a value in the ASCII code so i believe doing this will just pull out the value that char c holds.

Experiment

I will write a small program and execute it.

Data

  1 #include <stdio.h>
  2 
  3 int main()
  4 {
  5 int c='c';
  6 
  7 printf("Can you print a char as an int?\n");
  8 sleep(10);
  9 printf("Let's find out :D\n");
 10 
 11 printf("%d\n" ,c);
 12 return(0);
 13 }
 14 

Execution:

lab46:~/src/cprog$ ./yesno
Can you print a char as an int?
Let's find out :D
99

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes it was
  • was your hypothesis not applicable? No it was :D
  • is there more going on than you originally thought? (shortcomings in hypothesis) Nope i knew what was going on
  • what shortcomings might there be in your experiment? I could have done the code wrong or something i dont know whats going on
  • what shortcomings might there be in your data? IOf it went wrong in the experiment then yes, but if not then no.

Conclusions

I knew there was a value in a char value i just was not sure if you were able to print it out and guess what :D you can. So this was pretty simple and it is very possible to do this.

Experiment 3

Question

Can a pointer be a void pointer?

Resources

My information comes from class :) so Matt Haas

Hypothesis

I think it can be because i have heard and read that it is possible, i just have not seen it, so i am curious to whether or not it is possible.

Experiment

Now i know i can do a pointer program like so:

1 #include <iostream>
2 using namespace std;
3 int main ()
4 {
5  int firstvalue, secondvalue;
6  int * woo;
7
8  woo= &firstvalue;
9  *woo = 10;
10  woo = &secondvalue;
11  *woo = 20;
12  cout << "firstvalue is " << firstvalue << endl;
13  cout << "secondvalue is " << secondvalue << endl;
14  return 0;
15  }

now it should just give me the values of 10 and 20, because it is pointing to them.

1 #include <iostream>
2 using namespace std;
3
4 void increase (void* data, int candy)
5 {
6  if ( candy== sizeof(char) )
7  { char* mountain; mountain=(char*)data; ++(*mountain); }
8  else if (party == sizeof(int) )
9  { int* no; no=(int*)data; ++(*no); }
10 }
11
12 int main ()
13 {
14  char a = 'x';
15  int b = 1602;
16  increase (&a,sizeof(a));
17  increase (&b,sizeof(b));
18  cout << a << ", " << b << endl;
19  return 0;
20 }

This is a void pointer at work. Just run this code and a value of y and 1603 should appear.

Analysis

yes my hypothesis was right, you can have a void pointer. You just need to have another pointer so it has a concrete data point to deference too. Voids can go from int to float easily but if you want to dereference it, you cant cause it doesnt have that concrete data type that is needed. However i feel as though i much rather see this kind of thing in a real program, like a program related to something. I just dont know what i would make it do or what for so for now i will leave it at that. I feel as though as this was a good hypothesis and no shortcomings were found except when i was looking at this code. It is just weird how it works at times, i just cant fully grasp it. I know what is happening, its all just an odd feeling i guess.

Data

This was done in the experiment.

Conclusions

In the end i basically knew that this could be done because i looked it up on google after i asked this but seeing work on linux and working out showed me that this stuff is possible to do at home and anyone can do it. Look up sample and work with those, manipulate them and just lay. When you play, you learn. I feel this isomething that is important to learn for the C language.

opus/fall2011/dgirard3/part3.txt · Last modified: 2011/12/13 01:20 by dgirard3