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.