100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
NOTES - Computer Programming 143 R100,00
Add to cart

Class notes

NOTES - Computer Programming 143

 174 views  6 purchases

Notes covering Computer Programming 143 at Stellenbosch University.

Preview 3 out of 22  pages

  • April 12, 2021
  • 22
  • 2019/2020
  • Class notes
  • Dr kamper
  • All classes
book image

Book Title:

Author(s):

  • Edition:
  • ISBN:
  • Edition:
All documents for this subject (1)
avatar-seller
alex2021
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 ) ;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller alex2021. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R100,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53022 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R100,00  6x  sold
  • (0)
Add to cart
Added