User Tools

Site Tools


opus:fall2011:drobie2:start

Dalton Robie's Fall 2011 Opus

Knowledge is Something Everyone Needs

Introduction

My name is Dalton Robie, I'm a server performance analyst at Corning Inc. working on a computer science degree so I can become a better programmer. I'm a Call of Duty addict too.

Part 1

Entries

September 9th, 2011

I learned the basics of how a program works, and how the #include <stdio.h> is used to determine the library for the program. I also learned how to compile a newly wrote program in Lab46 using the cc <filename>. It's a difficult concept to grasp for me because I have not really wrote any programs before, therefore all the terminology is new to me. My main challenge for this course is going to be the fact that I'm taking Structered Orientation and Problem solving the same time as I'm taking this class, therefore learning both along the way, and not really applying what I may have already learned in the other class to this class.

September 15th, 2011

Today, I worked on some further programs in chapter 1/2 including the Temperature programs. The main concept I learned here is the different between “int” and “float” and that float allows a programmer to use decimals as opposed to int which only allows for the use of whole numbers.

September 20th, 2011

Today, I didn't really learn anything completely related to the class, however while in Structed Orientation and Problem Solving class, while discussing ArgoUML diagrams, I tried to tie in this class with what I was learning there, and how something as simple as a diagram can really impact how you write a program. I went into this further by creating a few diagrams trying to explain or plan some of the programs from the first few chapters, and if they made sense to not only me but a few friends. This concept is significant because I believe this step is essential in the role of both learning how a program works and how to write/script that program. Everything must be in logical order so that the computer can understand it and execute those commands. I feel like I don't think abstractly enough, or “out-of-the-box” enough for this course, therefore I struggle when it comes to actually trying to think about my own program and what it should do.

September 27th, 2011

Today, while working on the project, I spent time studying the actual variables and how unsgined and signed character(s)/integer(s) affect a program. It is a bit confusing and I do not understand this concept 100%. Probably going to be finishing the project within the next few days and keep studying how each character and integer works.

Topics

Standard I/O

stdio (or Standard I/O)=Standard Input/output header, this is the basic, standard stream of data in which a C program recognizes. This is a beautiful little command because as stated before, it is standard is C and C++ programming and almost 100% guarenteed to work on all operating systems. If this header was not defined in the start of the program, then the program would not recognize the commands it is being given.

/*
 * Defining stdio.h
 */
#include <stdio.h>
 
int main()
{
    printf="studio.h is the standard header for input and output in a C program.";
}

Header Files

A header file is a file which contains definitions and declarations that are used and shared in C and C++ programs. It's included into a program using the #include <“name”.h> format.

Arithmetic

Arithmetic operators allow for the inclusion of a mathmatic formula into a program. For example, it allows for the addition of variables when included in a program. These are essential in C programming because it allows for the program language to act as a “calculator”, saving a lot of work for the programmer.

Logic and Operators (and, or, not, xor)

And, or, not, xor, allow the program to flow and make decisions based upon pre-determined definitions and outcomes. For example, if an AND operator is entered into a programming step, then the program must check and see if both relativities are true to the “Truth” statement, and if they are not, then the operation would be false and the program would continue.

Variables

Variables are allocated bytes of storage which can be used in allignment with a name, such as “age,” “time,” etc. which can aid in the solving of equations and problems.

“String”, Format/Formatted Text String

String objects are a special type of container, specifically designed to operate with sequences of characters.

Source Code

A text listing of commands to be compiled or assembled into an executable computer program.

Object Code

Code produced by a compiler or assembler.

Binary Code

A coding system using the binary digits 0 and 1 to represent a letter, digit, or other character in a computer or other electronic device.

Compiler

A Complier is a program or interface which translates code into a machine language so that the written program may be actually executed.

Preprocessor

In many cases, the Preprocessor is the first stage of translation that is initiated by the complier program. The Preprocessor is usually a seperate program which handles macro and source file declarations.

Flags

A flag's purpose in a program in to indicate when a key point in the program has been reached, this can include things such as breaking a loop, or to repeat the loop again, being able to access different threads, etc.

Objectives

Objective 1

Demonstrate Structured and Object-Oriented Problem Solving Concepts

Method

In order to test somebody on knowledge of this topic, one might ask the following

How would you place a loop into a program? A) If B) While C) For

The correct answer would be B, a while statement. If someone can answer this basic question then they have a small concept of the Object-Oriented problem solving concepts.

Then, one might ask for a demonstration on making an activity diagram. If the person uses the correct shapes and flow of the program, this would be an excellent test of someone's knowledge of the object-oriented concepts.

Measurement

I would answer the question with the answer B, and would demonstrate a diagram using a start, followed by a get input option(input times 2), next a decision if the input ='s 0, if so, then the program will stop, if not then the program will continue and multiply the input number by 2 and display it.

Analysis

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

  • How did you do? Successful
  • Room for improvement? Learning the actual code to go along with this diagram.
  • Could the measurement process be enhanced to be more effective? Obviously more questions would need to be asked, and at a higher level to be more effective.
  • Do you think this enhancement would be efficient to employ? Yes, only if it was truly needed to know if someone has in depth knowledge of the object oriented concepts.
  • Could the course objective be altered to be more applicable? How would you alter it? This objective covers a broad range of concepts that were/are covered in the Objected Oriented class and really there isn't much time to cover it during this class.

Experiments

Experiment 1

Question

What will happen if quotations are not used in a printf statement?

Resources

“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie

Hypothesis

When the quotations are removed from a printf statement, the program will not compile correctly and will not run.

Experiment

Step 1) Test using this simple code: #include <stdio.h>

main()

{

      printf("hello, world!"\n);

}

Step 2) Remove the quotations around “hello, world!” Step 3) Compile the program and run it

Data

The program brings up an error while it is trying to be compiled.

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes
  • is there more going on than you originally thought? No, this was only a simple experiment to show the importance of quotations.
  • what shortcomings might there be in your experiment? There may have been some other information that could of been enterned incorrectly which may have caused an error.

Conclusions

Quotations are important in defining specific details in a program.

Experiment 2

Question

What will happen if the semicolon is forgotton before the start of a new line?

Resources

“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie

Hypothesis

The program will not compile because it will not recognize that a new line has started without the semicolon.

Experiment

1) Test using the code:

#include <stdio.h>

/* print Fahrenheit to Cesius Table

  For fahr = 0, 20, ..., 300*/

main()

{

      float fahr, celsius;
      int lower, upper, step;
      lower=0;        /*Lower limit of temp table */
      upper=300;      /*upper limit */
      step=20;        /*step size of table*/
      fahr=lower;
      while (fahr <= upper) {
              celsius = (5.0/9.0) * (fahr-32.0) / 9
      int lower, upper, step;
      lower=0;        /*Lower limit of temp table */
      upper=300;      /*upper limit */
      step=20;        /*step size of table*/
      fahr=lower;
      while (fahr <= upper) {
              celsius = (5.0/9.0) * (fahr-32.0) / 9;
              printf("%3.0f %6.5f\n", fahr, celsius);
              fahr = fahr + step;
      }

}

2) Remove the semicolon from the line “celsius = (5.0/9.0) * (fahr-32.0) / 9;” 3) Compile the program and run it

Data

When the semicolon is removed from the line, it fails to compile.

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes
  • is there more going on than you originally thought? No, the program just does not recognize that there is a new line starting.
  • what shortcomings might there be in your experiment? Human code error

Conclusions

A semicolon is essential to a program so that it can recognize when a new line is starting.

Experiment 3

Question

What happens when one of the equals signs is removed from a program line?

Resources

“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie

Hypothesis

When one of the equals signs is removed from the program, the program will no longer know what the if statement is being set to, creating a syntax error.

Experiment

1) test using the program: #include <stdio.h>

/* count lines in input */ main() {

      int c, nl;
      nl = 0;
      while ((c = getchar()) != EOF)
              if (c == '\n')
                      ++nl;
      printf("%d\n", nl);

}

2) remove one of the equals signs in the line “if (c == '\n')” 3) Try to compile the program and run it

Data

Program did not run.

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes
  • is there more going on than you originally thought? (shortcomings in hypothesis)No
  • what shortcomings might there be in your experiment? Human error

Conclusions

Using the equals signs are essential to setting a program line to a certain value so it may function properly.

Part 2

Entries

October 6th, 2011

Began to finish up the project (from about 2 weeks ago) and learned what the actual output commands are for displaying the size of the datatypes, still am trying to figure out how to display how many values they can hold. This is significant because being able to display information is an essential part of any program.

October 20th, 2011

Began studying arrays, I really do not understand and still slightly struggling with this class in general. Going to attempt to a make an array example program called Billy.

October 29th, 2011

Code for the array program is as follows

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

int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;

int main ()
{
  for ( n=0 ; n<5 ; n++ )
  {
    result += billy[n];
  }
  cout << result;
  return 0;
}

I cannot get this to work, will continue working on it further.

October 30th, 2011

I have slane Gywn, Lord of Cinder, and purged the land of all darkness earning the title Lord of Cinder for my own in Dark Souls.

cprog Topics

Assembler

Inline assembly is important because of its ability to operate and make its output visible on C/C++ variables. It is mainly used to instruct a complier to insert the code of a function so that it may be interperated.

asm("assembly code")

Linker

A linker is used to defideclare an object in a program from an outside program/source.

$ linker example.c
#include "use_me.h"

void bar()
{
        use_me(23);
}

C Library

Allows C and C++ programs to work by including header and essential program data without having to code every piece of that information in.

/*
 * Sample of Library
 */
#include <stdio.h>

Makefiles

Makefiles are special format files that together with the make utility will help you to automagically build and manage your projects.

lab46:make -f MyMakefile

Scope

Scope refers to the functions, class, types and variables and is that part of the source code where the particular identifier is visible.

#ifndef Variable
 #define Variable
 

Pointers

A pointer is a data type which directly relates one variables values to another variable either through storage or just replacement.

int *ptr;

Type Cast

A type cast provides a method for explicit conversion of the type of an object in a specific situation.

int main() {
double x = 3.1;
int i;
cout << "x = " << x << endl;
i = ( int )x;                     // assign i the integer part of x
cout << "i = " << i << endl;
}

Sequence Structures

Sequence structures perform tasks without breaking the flow of the program itself.

Version Control

Version Control allows you to keep track of changes to coding throughout many different languages, helping to prevent a massive change that would destroy the program/application.

Namespaces

Namespaces allow you to group different “entities” together under a specific name.

 namespace ExampleName
{
  int a, b;
}
 

Type Casting Operators

Allows you to convert a given expression into a different type of expression.

short a=2000;
int b;
b=a;

Arrays

An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.

cprog Objective

Objective

Exposure to Open-Source concepts and ideals.

Method

By using unbuntu more within different classes, I am gaining the basic concepts of open-source programs and logic.

Measurement

By using ubuntu/linux as an operating system has made me notice how it's great to have a system in which the user can actually modify it and make it their own, without needing to create their whole operating system.

Analysis

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

  • How did you do?
  • I still do not completely grasp why people allow this and put out these types/pieces of software, however it is amazing and I have to thank them dearly!
  • Room for improvement?
  • I need to use linux more in order to understand it.
  • Could the measurement process be enhanced to be more effective?
  • There could always be a test of knowledge about what the top Open Source programs are out there.
  • Do you think this enhancement would be efficient to employ?
  • Eventually yes if I ever needed to do some real hardcore troublshooting.
  • Could the course objective be altered to be more applicable? How would you alter it?
  • No, we're using this type of software, allowing us to play as we please.

Experiments

Experiment 1

Question

What happens if you replace a “for” statement with a “while”?

Resources

The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

Hypothesis

The program will not run because there will be no “do” statement for the while to depend on.

Experiment

#include <string.h>

/* reverse: reverse string s in place */ void reverse(char s[]) {

      int c, i, j;
      for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
              c = s[i];
              s[i] = s[j];
              s[j] = c;
              }

} replace “for” with “while”

Data

THe program does not run with “while” in place of the “for”

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes
  • is there more going on than you originally thought? (shortcomings in hypothesis) No, a while loop depends on the DO statement

Conclusions

For loops and While loops can be used interchangably, however you just need to make sure you use them correctly and do not mismatch the coding.

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Retest

If you're doing an experiment instead of a retest, delete this section.

If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Are there additional resources you've found that you can add to the resources list?
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • If you find a deviation in opinion, state why you think this might exist.

Hypothesis

State their experiment's hypothesis. Answer the following questions:

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
  • What improvements could you make to their hypothesis, if any?

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

  • Are the instructions correct in successfully achieving the results?
  • Is there room for improvement in the experiment instructions/description? What suggestions would you make?
  • Would you make any alterations to the structure of the experiment to yield better results? What, and why?

Data

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

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author?
  • Can you explain any deviations?
  • How about any sources of error?
  • Is the stated hypothesis adequate?

Conclusions

Answer the following:

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

Part 3

Entries

November 7th, 2011

Worked through some Array programs that we made in Structured Orientation and Problem Solving.

November 15th, 2011

started Purpose: A simple program demonstrating the use of pointers. #include <iostream> using namespace std; int main() { declare an integer and a float variable

int IntNum; 
float FloatNum;

// declare integer and float pointers
int *pIntNum;
float *pFloatNum;

// initialize the integer and float variables
IntNum = 10;
FloatNum = 12.34;

// store addresses in pointers
pIntNum = &IntNum;
pFloatNum = &FloatNum;

November 16th, 2011

// print out the original values
      cout << "Before increment: " << endl;
cout << "\t IntNum is: " << IntNum << endl;
cout << "\t FloatNum is: " << FloatNum << endl;

// note that we need to dereference a pointer in order
// to extract the value it contains.
cout << "\t pIntNum contains: " << *pIntNum << endl;
cout << "\t pFloatNum contains: " << *pFloatNum << endl;
// increment values of the integer and float variables 
(*pIntNum)++;  // dereference and then increment
(*pFloatNum)++;
// print out the values after increment
      cout << "After increment: " << endl;
cout << "\t IntNum is: " << IntNum << endl;
cout << "\t FloatNum is: " << FloatNum << endl;
cout << "\t pIntNum contains: " << *pIntNum << endl;
cout << "\t pFloatNum contains: " << *pFloatNum << endl;
return 0;

}

November 29, 2011

Worked on Opus, studied the point program a little bit (used example from a website that guided me through the process)

cprog Topics

Function Overloading

You overload a function name f by declaring more than one function with the name f in the same scope.

#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");
}

Command-line arguments

In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux, and are passed in to the program from the operating system.

int main ( int argc, char *argv[] )

“this” pointer

The type of the this pointer for a member function of a class type X, is X* const. If the member function is declared with the const qualifier, the type of the this pointer for that member function for class X, is const X* const

struct A {
  int a;
  int f() const { return a++; }
};

Inheritance

Inheritance is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationships between them.

Polymorphism

Polymorphism is the ability for objects of different classes related by inheritance to respond differently to the same member function call

Operator overloading

Operator overloading is a special kind of Polymorphism which is defined by the programmer or the program itself.

Exception Handing

Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.

// exceptions
#include <iostream>
using namespace std;
 
int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << endl;
  }
  return 0;
}

Abstract Base Class

An abstract class is a class that is designed to be specifically used as a base class

class AB {
public:
  virtual void f() = 0;
};

Standard Template Library

Standard Template Library; it provides many of the basic algorithms and data structures of computer science

vector<int> v(3);            // Declare a vector of 3 elements.
      v[0] = 7;
      v[1] = v[0] + 3;
      v[2] = v[0] + v[1];          // v[0] == 7, v[1] == 10, v[2] == 17 

Templates

Function templates are special functions that can operate with generic types

template <class myType>
myType GetMax (myType a, myType b) {
 return (a>b?a:b);
}

cprog Objective

Objective

know the difference between structures and classes

Analysis

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

The class is the template or plate of a program or code, while the structure is sort of like the meat and potatoes of a programs, they're both important to a program, but both very unique to one another.

Experiments

Experiment 1

Question

What will happen if you do not declare a variable in a pointer program?

Resources

Using google I collected a guide to making a pointer program with undefined variables.

Hypothesis

The program will not run because the variables are undefined and the program will not know what to do.

Experiment

Using the program,

#include <iostream>
using namespace std;

int main()
{
	// declare an integer and a float variable
	int IntNum; 
	float FloatNum;
	
	// declare integer and float pointers
	int *pIntNum;
	float *pFloatNum;
	
	// initialize the integer and float variables
	IntNum = 10;
	FloatNum = 12.34;
	
	// store addresses in pointers
	pIntNum = &IntNum;
	pFloatNum = &FloatNum;

	// print out the original values
        cout << "Before increment: " << endl;
	cout << "\t IntNum is: " << IntNum << endl;
	cout << "\t FloatNum is: " << FloatNum << endl;
	
	// note that we need to dereference a pointer in order
	// to extract the value it contains.
	cout << "\t pIntNum contains: " << *pIntNum << endl;
	cout << "\t pFloatNum contains: " << *pFloatNum << endl;

	// increment values of the integer and float variables 
	(*pIntNum)++;  // dereference and then increment
	(*pFloatNum)++;

	// print out the values after increment
        cout << "After increment: " << endl;
	cout << "\t IntNum is: " << IntNum << endl;
	cout << "\t FloatNum is: " << FloatNum << endl;

	cout << "\t pIntNum contains: " << *pIntNum << endl;
	cout << "\t pFloatNum contains: " << *pFloatNum << endl;

	return 0;
}

Data

The program was put into Putty and compiled. The program did not run, it gave the following results, ./pointer.c: In function 'main': ./pointer.c:26: error: 'cout' undeclared (first use in this function) ./pointer.c:26: error: (Each undeclared identifier is reported only once ./pointer.c:26: error: for each function it appears in.) ./pointer.c:26: error: 'endl' undeclared (first use in this function)

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes
  • is there more going on than you originally thought? (shortcomings in hypothesis)There are multiple variables in this program which need to be defined for the program to run, however I do believe that even if one or two variable were defined, it would still not run because there's over 8 variables alone.
  • what shortcomings might there be in your experiment? Coding may be incorrect
  • what shortcomings might there be in your data? Unsure.

Conclusions

Variables need to be defined in any program you write in order to operate properly

opus/fall2011/drobie2/start.txt · Last modified: 2014/01/19 09:20 by 127.0.0.1