Dalton Robie's Fall 2011 Opus
Knowledge is Something Everyone Needs
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.
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.
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.
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.
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.
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."; }
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 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.
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 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 objects are a special type of container, specifically designed to operate with sequences of characters.
A text listing of commands to be compiled or assembled into an executable computer program.
Code produced by a compiler or assembler.
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.
A Complier is a program or interface which translates code into a machine language so that the written program may be actually executed.
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.
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.
Demonstrate Structured and Object-Oriented Problem Solving Concepts
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.
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.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
What will happen if quotations are not used in a printf statement?
“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie
When the quotations are removed from a printf statement, the program will not compile correctly and will not run.
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
The program brings up an error while it is trying to be compiled.
Based on the data collected:
Quotations are important in defining specific details in a program.
What will happen if the semicolon is forgotton before the start of a new line?
“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie
The program will not compile because it will not recognize that a new line has started without the semicolon.
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
When the semicolon is removed from the line, it fails to compile.
Based on the data collected:
A semicolon is essential to a program so that it can recognize when a new line is starting.
What happens when one of the equals signs is removed from a program line?
“The C Programming Language” By Brian W. Kernighan and Dennis M. Ritchie
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.
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
Program did not run.
Based on the data collected:
Using the equals signs are essential to setting a program line to a certain value so it may function properly.
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.
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.
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.
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.
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")
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); }
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 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 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
A pointer is a data type which directly relates one variables values to another variable either through storage or just replacement.
int *ptr;
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 perform tasks without breaking the flow of the program itself.
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 allow you to group different “entities” together under a specific name.
namespace ExampleName { int a, b; }
Allows you to convert a given expression into a different type of expression.
short a=2000; int b; b=a;
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.
Exposure to Open-Source concepts and ideals.
By using unbuntu more within different classes, I am gaining the basic concepts of open-source programs and logic.
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.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
What happens if you replace a “for” statement with a “while”?
The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
The program will not run because there will be no “do” statement for the while to depend on.
#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”
THe program does not run with “while” in place of the “for”
Based on the data collected:
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.
What is the question you'd like to pose for experimentation? State it here.
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.
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.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
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.
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:
Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.
Evaluate their resources and commentary. Answer the following questions:
State their experiment's hypothesis. Answer the following questions:
Follow the steps given to recreate the original experiment. Answer the following questions:
Publish the data you have gained from your performing of the experiment here.
Answer the following:
Answer the following:
Worked through some Array programs that we made in Structured Orientation and Problem Solving.
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;
// 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;
}
Worked on Opus, studied the point program a little bit (used example from a website that guided me through the process)
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"); }
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[] )
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 is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationships between them.
Polymorphism is the ability for objects of different classes related by inheritance to respond differently to the same member function call
Operator overloading is a special kind of Polymorphism which is defined by the programmer or the program itself.
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; }
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; 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
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); }
know the difference between structures and classes
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.
What will happen if you do not declare a variable in a pointer program?
Using google I collected a guide to making a pointer program with undefined variables.
The program will not run because the variables are undefined and the program will not know what to do.
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; }
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)
Based on the data collected:
Variables need to be defined in any program you write in order to operate properly