Table of Contents

cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)

Definition

FILE *stdin

stdin is associated with a user's standard input stream. usually a keyboard.

FILE *stdout

stdin is associated with an output stream used for normal program output. usually a display terminal.

FILE *stderr

stdin is associated with an output stream used for error messages. often a display terminal.

Demonstration

Demonstration of the chosen 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()
{
  int x;
    printf( "please type your age: \n");
    scanf( "%d", &x ); 
    printf( "Is your age, %d \n");
    return(0);
}

Header Files

Definition

A header file is a file containing C declarations, You request the use of a header file in your program by including it, with the C preprocessing directive `#include'.

Demonstration

There are a large number of headers listed bellow is a few

/*
 * Sample code block
 */
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include <stddef.h>
#include <complex.h>
int main()
{
    return(0);
}

arithmetic (equations, operators)

Definition

Operator Description

+ Adds two operands

- Subtracts second operand from the first

* Multiply both operands

/ Divide numerator by denumerator

% Modulus Operator and remainder of after an integer division

++ Increment operator, increases integer value by one

– Decrement operator, decreases integer value by one

Demonstration

Binary arithmetic operators are +, -, *, /, and %.

         int a = 25;
         int b = 5;
         int c;
 
         c = a + b;
         printf( "a + b = %dn", c );
 
         c = a - b;
         printf( "a - b = %dn", c );
 
 
         printf( "a * b = %dn", a * b );
 
         c = a / b;
         printf( "a / b = %dn", c );
 
         c = 100 % 3;
         printf( "a % b = %dn", c );

logic and operators (and, or, not, xor)

Definition

“==” Checks if the value of two operands is equal or not, if yes then condition becomes true.

“!=” Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.

“>” Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.

“<” Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.

“>=” Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.

“⇐” Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

“&&” Logical AND operator. If both the operands are non zero then then condition becomes true.

“||” Logical OR Operator. If any of the two operands is non zero then then condition becomes true.

“!” Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

Demonstration

Demonstration of the chosen 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);
}

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Variables

man3 printf Are allocated blocks of storage in memory that we can associate with a name, such as “pirce”, “age”, “year”, etc.

Name Type Range

int Numeric - Integer -32 768 to 32 767

short Numeric - Integer -32 768 to 32 767

long Numeric - Integer -2 147 483 648 to 2 147 483 647

float Numeric - Real 1.2 X 10-38 to 3.4 X 1038

double Numeric - Real 2.2 X 10-308 to 1.8 X 10308

char Character All ASCII characters

Examples of variables can be but not limited to:

int x %d
short x %d
long x %d
char x %c
float x %f
double x %lf

Sizeof

The sizeof operator gets the size of its operand.

This initializes X to the size of c, resulting in a integer of the type size_t:

size_t X = sizeof(c);

String

In computing, a C string is a character sequence terminated with a null character

In the following, the string literal “hello world” is printed.

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
 
printf("hello world");
}

Repetition/Iteration Structures For

The variable initialization allows you to either declare a variable and give it a value or give a value to an already existing variable. Second, the condition tells the program that while the conditional expression is true the loop should continue to repeat itself.

FOR - for loops are the most useful type. The syntax for a for loop is

for ( variable initialization; condition; variable update ) {
  Code to execute while the condition is true
}

cprog Objective (added)

demonstrate structured and object-oriented problem solving concepts

By the end of this semester show the ability to demonstrate the use of logic and structure in program writing.

Method

The method of this could be variously described, but a easy effective means would be to ask a student to create a set of instructions that:

1. creates a program

2. Initializes the program

3. contains a logical sense to obtain a desired result, IE: if someone wanted to multiply 2 numbers and get a result.

Measurement

To asses how a students effectiveness was in creating this first:

1. Does the program compile without errors.

2. Does the program ask for input for the 2 variables to be multiplied.

3. Does the program give the correct desired answer for this function it is to serve.

4. Lastly the code in which it is written, was it initialized properly, does it only prompt the user for one occurring event, Does it ask the user to input a variable to end, does it continuously loop and not close itself without the user having to exit the program, there is a large list in structuring the means to a achieved goal and many ways to reach it, but in the end was it the most efficient.

Analysis

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