Daniel Herman's Fall 2011 Opus
(It's been three months and I still haven't filled out this section, oops)
I am currently a Computer Science major going into my final semester at CCC this spring. I work at JCPenney's and enjoy both computer and math related subjects. In my free time, as little as that is, I watch television and browse the internet.
Up to today, I have read Chapters 1 & 2 and gone through most (if not all) of the exercises. This helped introduce me to many of the starting concepts of C/C++ programming that I have not known before. A few concepts did not make perfect sense to me. This includes what the Data Types really are and Type Conversions. There are a few challenges that I face related to the course. One of the challenges I face is that I have no experience whatsoever (besides Object-oriented and Structured Problem Solving) with any programming languages or programming itself. Another of the challenges I face is the limited time I have given myself to deal with both classes at CCC and my job.
I have begun reading Chapter 3 and worked some on the first project. Getting my first project completed is very important as it opens up possibilities to more projects. I have had some trouble remembering how the data types are calculated (long long int, unsigned int, etc.) and will have to refresh my memory with some studying.
Today, I ran a few experiments and recorded them into my Opus. I also read about unsigned/signed chars, long long ints, etc. The experiments can be used in many different ways, primarily to figure out different possibilities of the C language in different situations. The char and int data values are important parts of my project and knowing what they are and how to calculate them is very important. The base concepts for them does not seem very logical to me and is somewhat of a challenge.
Today, I read more in Chapter 3, about switches and loops. I have already encountered loops before in O.O.&S. Problem Solving, but have not seen switches before. The switch seems like the if statement, but with a lot more possibilities being able to set more conditions and therefore more possible results. Using the Switch can help to simplify a problem if the problem included a lot of conditions that needed to be tested. Using if statements in this type of problem would be much more unnecessary coding.
Standard I/O refers to the communication between the input of the keyboard into the command line, and the output in Unix. Standard I/O simplifies the communications into three categories:
STD IN - Standard Input is where the input is read.
STD OUT - Standard Output is where the output is sent to the command window of the user.
STD ERROR - Standard Error is similar to output, but is used as a way to differentiate normal output from errors.
Header Files are usually used in C/C++ programs for declarations and definitions.
Here's an example of this:
#include <stdio.h>
This calls stdio.h to be used in said program as a resource.
Arithmetic is the counting and calculating of numbers, quite simply. Some parts of Arithmetic include addition, subtraction, multiplication, and division. These are the basic functions of Arithmetic. Arithmetic is incorporated into programming languages to save much time for the user. Arithmetic is a core part of how programming works and why it exists.
Logic is an important part of problem solving in any program. Operators are incorporated into the C program in the form of:
These operators check for conditions to be true. The user can direct the results for different conditions with these operators.
Variables are used to store data which can be manipulated or retrieved in the program. Variables are essential to allow many calculations to take place. The programmer can choose to make variables be initialized at a certain value, or to have a user enter a value to be stored and possibly calculated.
A Formatted Text String can be used to limit a variable to only accept certain characters as valid.
The scope in a program dictates where a variable in the program can be accessed.
A pointer is a data type in a program used to improve performance by referring directly to another value.
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Selection Structures are a way to allow the program to select statements in a different order than sequential. This allows the program to decide what module to call upon based on the input received.
Repetition/Iteration structures allow the program to repeat parts of the program. Looping is one form of this.
Arrays are an arrangement of multiple values. They can be used to store multiple values in an arranged order. An array can be metaphorically thought of as a table of values.
The first objective is to demonstrate structured and object-oriented problem solving concepts. Structured and Object-oriented problem solving is a logical form of solving a program to produce a desired result.
The method I will be using to demonstrate my knowledge of this topic is to state multiple solutions to a problem. Using different solutions allows for more demonstration of the knowledge of the concept.
The problem I will be solving is to test for condition A and produce result B if it is true, and show the possible results while doing so.
One possible way of testing for condition A is to run an 'if' statement. For example: If A > 0, then B = 2. This is a basic condition check which will set B to 2 if the value of A is greater than 0. An if statement is usually used to set values in this manner.
Another possible way of testing for condition A is to run a 'for' statement. For example: For A = [1 to 10],
B[Index] = A + 2
endfor This condition check uses A as an array to set values in the array B to A + 2.
Another possible way of testing for condition A is to run a 'while' statement. For example: A = 0 While A < 10
B[A] = A/2 A = A + 1
endwhile This condition checks if A is less than 10, and if it is, assigns a value to the A value of the array B, and increases A by one.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
I was able to show some of my knowledge in Structured and Object-Oriented Problem Solving.
There is much more that I could do to show my knowledge of this type of problem solving, such as using modules and more complicated problems.
The measurement process I used was very long and could have been shorter.
Shortening the measurement process could be efficient if I was able to come up with shorter answers.
The course objective could not be altered as it is completely applicable to the course.
What happens when you remove the parenthesis in a printf statement?
The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie, 2nd Ed., Chapter 1
The program will not run correctly and the printf statement will not output correctly.
To test this hypothesis, I will run the “Hello World” program first with, then without parenthesis in the printf statement.
This is the original program:
#include <stdio.h> main() { printf("hello, world\n"); }
This is the output from this program:
lab46:~/test/experiments$ ./test0.out hello, world
This is the program after removing parethensis:
#include <stdio.h> main() { printf"hello, world\n"; }
This is the output from trying to compile the program:
lab46:~/test/experiments$ cc test0.c test0.c: In function 'main': test0.c:7: error: expected ';' before string constant
Based on the data collected:
My hypothesis was partially correct. The program was unable to compile, and therefore was unable to run.
The parenthesis are very important to the printf function's syntax. Without the parenthesis, the program will be unable to compile.
What happens when you use a declared variable in a statement without initializing it beforehand?
The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie, 2nd Ed., Chapter 1
The program will run but will produce different results.
I will be using the Fahrenheit experiment to test how the program runs with and without initializing the lower bound.
The program with the lower bound initialized:
#include <stdio.h> /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ main() { int fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperature table */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
This is the output of the compiled program:
lab46:~/test/experiments/exp2$ ./test0.out 0 -17 20 -6 40 4 60 15 80 26 100 37 120 48 140 60 160 71 180 82 200 93 220 104 240 115 260 126 280 137 300 148
This is the program after the removal of the initialization of the lower bound:
#include <stdio.h> /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ main() { int fahr, celsius; int lower, upper, step; upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
This is the output of the compiled program:
lab46:~/test/experiments/exp2$ ./test1.out lab46:~/test/experiments/exp2$
My hypothesis was partially correct. The program did run, but produced no results at all, instead of different results.
Removing the initialization of the lower bound in this case caused the program to output nothing.
What happens when you enter two statements on one line, instead of on separate lines?
The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie, 2nd Ed. Chapter 1.
The program will not compile correctly as it will not recognize the statement. Including 2 statements in one line will create an error.
I am going to compile and run a program with 2 statements in 2 lines and 2 statements in 1 line.
Program with two statements in two lines like usual:
#include <stdio.h> #define LOWER 0 /* lower limit of table */ #define UPPER 300 /* upper limit */ #define STEP 20 /* step size */ /*print Fahrenheit-Celsius table */ main() { int fahr; for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); }
Output for the program:
lab46:~/test/experiments/exp3$ ./test1.out 0 -17.8 20 -6.7 40 4.4 60 15.6 80 26.7 100 37.8 120 48.9 140 60.0 160 71.1 180 82.2 200 93.3 220 104.4 240 115.6 260 126.7 280 137.8 300 148.9
Program with two statements in one line:
#include <stdio.h> #define LOWER 0 /* lower limit of table */ #define UPPER 300 /* upper limit */ #define STEP 20 /* step size */ /*print Fahrenheit-Celsius table */ main() { int fahr; for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)printf("%3d %6.1f\$ }
Output for the program:
lab46:~/test/experiments/exp3$ ./test2.out 0 -17.8 20 -6.7 40 4.4 60 15.6 80 26.7 100 37.8 120 48.9 140 60.0 160 71.1 180 82.2 200 93.3 220 104.4 240 115.6 260 126.7 280 137.8 300 148.9
My hypothesis was incorrect. The output was the same for both programs.
Having more than one statement on the same line will not change the output. The amount of space between statements does not matter, as long as they are in the correct syntax.
Today, I worked on the first project and got a good amount done. I am still not sure how to calculate the data types' ranges or amount of unique values available. I know these values but I am not sure how the calculations are taking place based on the examples given.
Today, I finished my first project covering data types. I had to do a bit of researching to learn about data types and their specific values. I did learn a few things about the limits header, as covered in my project. I had trouble figuring out how to calculate the values needed in the way the examples did it, so I will need to look into that to make sure I can calculate correctly.
I have read through the rest of chapter 3 and some of chapter 4 up to this point. I have been dealing with time constraints between work and classes which has limited my progress slightly recently.
I have been viewing a few tutorials that Dalton recommended to me on Youtube for C++. They seem to be quite informative and helpful for some key concepts. The channel is “thenewboston” who releases a number of tutorials and lectures for numerous topics such as chemistry, math, and programming topics. On another note, I have been thinking about what type of concept to explore in my next project, which I will probably start very soon.
A Multi-dimensional array is “an array of arrays”. It can be described as a table of values, or multi-variable, as compared to a normal array which only has one independent variable. All values have to be the same data type.
File Access in C is managed through using a FILE pointer with the fopen function. The modes for reading, writing, and appending are 'r', 'w', and 'a', respectively.
Similar to an array, structures handle a collection of variables, and can hold different data types. Structures can be used in more ways than arrays.
typedef is a declaration that can be used to define different variable types.
enum is a declaration used for variables that are limited to certain values.
union is similar to structures except all the fields are in one location.
Arguments are user-entered information (in the command line) when prompted, which are usually used for calculation or storage.
namespaces can be used to define multiple things under one category as a “sub-scope”.
Type Casting is the method of converting a variable from one data type to a different data type.
Templates are functions that can be used to create functionality for multiple data types or classes without repeating code. Parameters are used to manage templates.
As the word suggests, an Abstract Base Class is a class that is abstract. It is used as a class and it can not be made as an object. It is used to define a class that “has one or more pure virtual member functions”.
Overloading a function is making multiple declarations of the same function name in the same scope. Doing this causes the program to select the best function when you call said overloaded function.
Operator overloading is the overloading of an operator (such as +, -, *, etc.), to manipulate a given operation to be closer to the desired solution of a problem.
Some programs are split into multiple files if the number of functions in the said program exceeds what the user desires. Having too many functions or coding in one file can put a strain on file size and/or make it difficult for the user to read. Creating multiple files for one program can help to maintain this if there is too much coding for one file. These multiple files can then be linked together to compile into a single program, rather than compiling a single file.
This objective is to understand the difference between procedural and object-oriented languages.
To understand the difference between these types of languages, it is necessary to express what defines each of these types of languages, and also to express the differences and similarities between them.
Procedural programming languages create a program that is run step by step, or in sequence. Object-Oriented programming languages create a program that holds objects which can be called based on how the coding allows it. Both of these types of programming languages can be used to accomplish very similar goals and problem solving. The nature of object-oriented programming allows it to often require less coding for a given problem than a procedural program would, usually due to repeated coding in procedural.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
I believe I understand the difference between the two types of languages well.
I could practice both types of languages in order to become more familiar with them.
Examples could have been used but I wasn't able to think of any.
Employing this enhancement would be efficient if a problem were given.
Object-oriented and procedural programs are more significant in considering problems and not languages, and the objective should reflect this more. They are more of a mindset or philosophy in approaching problems than anything else.
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.
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:
I have read Chapters 5 & 6 and managed to test a few of the examples in the book from most of the concepts. This is important in progressing in my abilities with this class. Right now I am having trouble juggling my studies and work especially with Black Friday coming up which I have to work on (oh yay). Keeping up with concepts in this class is very important especially at a late stage and I think I'll need to put even more effort into this direction when I can.
I've made it through Black Friday (thank god) and I'm able to focus more on classes. Right now I am in the middle of reading through Chapter 7 and will hopefully be able to practice some of it tonight. I think I will be able to finish the book before the end of semester, but I'm definitely doing so regardless if that time passes.
I am brainstorming for possible projects to do and these are the ones I have come up with:
This entry will also help me to start my project much faster than just thinking about it, although it's tough to come up with more for now.
I have read through Chapter 7 and some of Chapter 8. I have also done some example exercises based on examples from Chapter 7 to help my understanding. My progress toward the end of this semester is a little faster than it has been overall, and I hope I'll be able to find the time to complete the book before then. Most of my time (since Saturday) has had to be directed toward other classes due to tests. I have been going through the concepts well for the most part and thankfully time has been my only challenge for this course so far.
Parameters are used to pass arguments of a specified data type when called. One example:
int example (int x, int y)
The parameters given for 'int example' are 'int x' and 'int y'. The parameters are separated by commas.
Return types refers to the data type that is returned as the result of a function. The function can be defined to specify what data type to return, or to return no data by using “void”.
Recursion is when a function is declared to repeat itself, either infinitely or until the user specifies.
Code stages refers to what happens before, during and after compiling of a program. Source code is the code that is written before any compiling is done. Compiling the source code turns it into assembly code, which is then turned into object code by an Assembler. A “Linker” program is what turns the object code into binary code, and makes it executable.
These are what changes the source code into an executable program. The compiler changes source code into assembly code. The preprocessor looks at parts of the code such as “#include <stdio.h>”. Flags refers to the options that the user may have turned on or off for the program. The Assembler turns the assembly code into object code. The Linker turns that object code into an executable file.
The C Library, and other libraries, contain numerous functions and definitions that can be called and used in other programs. Makefiles are another way to organize code together, similar to libraries.
Const and volatile are both used to modify pointers. const protects a declaration from being changed after initialization. volatile allows the declaration to be modified by other ways than just the user application.
Members of a class are declarations of functions within a class. Constructors and destructors are similar to member functions of a class, but can have no return types. Constructors are member functions with the same name as the class. Destructors can be used to deallocate memory within a class.
The “this” pointer is used for a non-static member function toward an object.
Inheritance is exactly what is implies, which is the transfer (inheritance) of functions from one class to another.
Polymorphism enables the use of one function in different ways. This type of function allows for flexibility when using one function, rather than having to make new functions for different problems.
The Standard Template Library is library available to C++. It comes with a great number of built-in tools, such as algorithms, functors, containers, and iterators for use in programming.
This objective is to know the difference between structures and classes
The method I will use to show my knowledge of differences is analyzing and comparing structures and classes.
Both classes and structures are defined as groups of data elements which can be used in a number of ways. The only difference between the two is the default setting assigned to each. Classes are set to be private by default, where structures are set to be public by default.
The only difference between classes and structures is whether the default setting assigned to them is private or public, respectively. While both allow the use of member functions and objects, these default settings help to differentiate when it is more convenient to use one than the other.
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.
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: