100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

NOTES - Computer Programming 143

Rating
-
Sold
6
Pages
22
Uploaded on
12-04-2021
Written in
2019/2020

Notes covering Computer Programming 143 at Stellenbosch University.

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Course

Document information

Uploaded on
April 12, 2021
Number of pages
22
Written in
2019/2020
Type
Class notes
Professor(s)
Dr kamper
Contains
All classes

Subjects

Content preview

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.09
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
alex2021

Get to know the seller

Seller avatar
alex2021 Stellenbosch University
Follow You need to be logged in order to follow users or courses
Sold
6
Member since
4 year
Number of followers
5
Documents
2
Last sold
1 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions