User Tools

Site Tools


opus:fall2011:drobie2:part1

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.

opus/fall2011/drobie2/part1.txt · Last modified: 2011/10/01 03:26 by drobie2