100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Notas de lectura

NOTES - Computer Programming 143

Puntuación
-
Vendido
6
Páginas
22
Subido en
12-04-2021
Escrito en
2019/2020

Notes covering Computer Programming 143 at Stellenbosch University.

Institución
Grado










Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
12 de abril de 2021
Número de páginas
22
Escrito en
2019/2020
Tipo
Notas de lectura
Profesor(es)
Dr kamper
Contiene
Todas las clases

Temas

Vista previa del contenido

A.Grey




1. Input unit (keyboard, mouse) – obtains user input info from input devices
2. Output unit (screen, printer) – outputs user/processed info and results
3. Arithmetic logic unit (ALU) – performs arithmetic calculations and logic decisions; implemented as part of CPU
4. Central processing unit (CPU) – supervises and coordinates the other sections of the computer
5. Memory unit (RAM) – volatile, rapid access, low capacity, expensive; stores program and input info temporarily
6. Secondary storage unit (disks) – cheap, long-term, high-capacity storage; stores inactive programs and data


• Machine languages – strings of numbers giving machine-specific instructions (e.g. +13001646)
• Assembly languages – English-like abbreviations representing elementary computer operations; translated via
assemblers (e.g. LOAD BASEPAY, ADD OVERTIMEPAY…)
• High-level languages – codes similar to everyday English; use mathematical notations; translated via compilers
(e.g. grossPay = basePay + overtimePay)


• Programmer can create own functions
• Advantage: programmer knows exactly how it works; disadvantage: time consuming
• Programmers often use the C library functions (use as building blocks)
• Advantage: saves time; disadvantage: must know exactly how library works

including a program development environment (CodeBlocks), the
language and the C Standard Library
edit -> pre-process -> compile -> link -> load -> execute




• \n new line
• \t horizontal tab
• \a alert (sounds system bell)
• \\ backslash (inserts a backsplash character in a string)
• \” double quote (inserts double quote in a string)
• \’ single quote (inserts single quote in a string)
• \r position curser at beginning of current line
• \? Inserts a question mark character


• Variable names (identifiers) consist of letters, digits (cannot begin with a digit) and underscores
• Case sensitive & should not use C keywords
• Declarations must occur before executable statements
• Variables must be declared at the beginning/top of a block
• Every variable has a name, type, size and a value
• Whenever a new value is placed into a variable, it replaces (and destroys) the previous value
• Reading variables from memory does not change them
• All variables must be declared before they can be used
• Types
• int – integer d
• char – character c for “a”, d for number value in memory
• char[ ] – string s
• float – decimal f (e for scientific notation)
• double – decimal lf (“long float”)

== is equal to > greater than
!= is not equal to < less than
>= greater than or equal to
<= less than or equal to

,• Pseudocode
• Flow diagrams
• Rectangle: indicates any type of action
• Oval: indicates beginning or end of a program or section of code
• Diamond: indicates decision is to be made

• Sequence structures: built into C; programs executed sequentially by default
• Selection structures: if, if…else, switch
• Repetition structures: while, do…while, for
Single-entry/single-exit control structures connect exit point of one control structure to entry point of next (makes
programs easy to build)

(single-entry/single-exit)
• A decision can be made on any expression
• If result is 0: then false
• If result is nonzero: then true
• E.g.
if ( 2 < 3 )
{
printf( “2 is less than 3” );
}


• Specifies an action to be performed when the condition is true (if) and when it is false (else)
• Test multiple cases by placing if…else selection statements inside if…else selection statement – once condition is
met, rest of statements skipped
• E.g.
if ( 2 < 3 )
{
printf( “2 is less than 3” );
}

else
{
printf( “2 is not less than 3” );
}


• Repetition structure
• Programmer specifies an action to be repeated while some condition remains true
• while loop repeated until condition becomes false
• E.g.
int product;
while ( product <= 200 )
{
product = 2 * product;
}

Senitel-controlled repetition: indefinite repetition (not known beforehand how many times loop will execute)
• Senitel value indicates “end of data” ------ doesn’t count as a value
E.g.
while ( grade != 0 ) {……

, • Explicit and implicit conversion
E.g. // total and counter are integers, average is a float
average = ( float ) total / counter;


• Assignment operators abbreviate assignment expressions
c = c + 3; can be abbreviated using the addition assignment operator to c += 3
• Statements of the form
variable = variable operator expression;
can be rewritten as
variable operator = expression;
• Examples of other assignment operators
• d=d–4 … d -= 4
• e=e*5 … e *= 5
• f=f/3 … f /= 3
• g=g%9 … g%= 9
• Increment operator (++)
• Can be used instead of c+=1 … c++;
• Decrement operator (--)
• Can be used instead of c-=1 … c--;
• Preincrement
• Operator is used before the variable (++c or –-c)
• Variable is changed before the expression it is in is evaluated
• i.e. ++a increments a by 1 then uses the new values of a in the expression where a resides
• Postincrement
• Operator is used after the variable (c++ or c--)
• Expression executes before the variable is changed
• i.e. a++ uses the current value of a in the expression where a resides, then increments a by 1

for ( initialization; condition; increment) { ….
* initialization and incrementation/decrement can be comma-
separated lists….e.g. for ( x = 0, y = 0; x+y <=10; x++, y++ )
* if the loop condition is initially false, then the body of the for
statement is not performed; control proceeds with the next
statement after the for statement
* a control variable is often printed, or used inside for body
but is not necessary




• Similar to while structure
• Condition for repetition tested after the body of the loop is performed (all actions are performed at least once)
E.g.
do
{
statement(s);
} while ( condition ) ;
$6.13
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
alex2021

Conoce al vendedor

Seller avatar
alex2021 Stellenbosch University
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
6
Miembro desde
4 año
Número de seguidores
5
Documentos
2
Última venta
1 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes