Sei sulla pagina 1di 18

Computer Fundamentals

TERMINOLOGIES:
Program - A set of instructions, written in a specific programming language, which a
computer follows in processing data, performing an operation, or solving a logical
problem.
Software Programs
Hardware - Physical component of a computer
DATA vs. INFORMATION
DATA a collection of facts relating to events that take place. These facts could be in
the form of numbers, letters, special symbols or combination of these.
INFORMATION data that has been organized and processed so that it is meaningful.
It is essential for effective performance of management functions of planning, organizing,
directing, and controlling for effective internal operations and external reporting.
DATA PROCESSING CYCLE
The process of converting data into useful and meaningful information:

INPUT

PROCESS

OUTPUT

THE PROGRAMMING CYCLE


1.)
2.)
3.)
4.)
5.)
6.)
7.)

Defining the Problem


Developing Software Requirements
Designing the Program
Coding the Program
Checking out the program by Testing and Debugging
Installing and Maintaining the Program
Documentation

Program Elements and Structure


1.)
Constants Literal Value that does not change during program execution. It can
be of the numeric or string type.
Numeric Constant - may be an integer (whole number) or a real number (with a
decimal place). It may be preceded by a positive or negative sign.
Examples:
10
-28
+3.4
-0.413
0
201

Page 1 of 18

Computer Fundamentals
Note: No other characters must or can appear together with the constants. The
following are examples of incorrect numeric constants:
10,000

$14.3

10mi/hr

1/2

String Constant A character or group of characters enclosed in double quotation


marks ( ). The numbers 0-9, letters a-z or A-Z and all special characters like a space,
% $ - _ & etc. may be included.
Examples:
C

Tina

1225

B & L

Note: The entire string constant must always be enclosed in double quotation marks,
one before the first character and one after the last character (no more no less). The
following are examples of incorrect string constants:
Cristina A. Pascua

ACT

Power Plant

2.) Variables Is a portion of the computers main memory used to store a numeric or
string constant. The value stored in the variable must be given a unique variable name
but it can only hold one value at a given time.
Variable names must conform to the following requirements:
a.)
b.)
c.)
d.)
e.)

Must contain only letters, numbers and/or an underscore.


Must begin with a letter.
Must Stop either with a letter or a number.
Must be unique that is, not a name of another variable.
Must not be a keyword like IF, WHILE and the like.

Note: Variable names are case sensitive, that is, upper and lower case letters are
differentiated. For example the variable TOTAL is not the same as total.
The following are example of incorrect
variable name:
Year code

10ctr

#5

Total=

3.) Expressions is a group of program elements consisting of operands and


operators. Operands can be a constant, variable, and or an array element. Operators
can be arithmetic, logical, relational and/or string. Expressions always yield a value of
a certain type depending on the type of expressions used.
Arithmetic Expressions
Hierarchy or Priority of Operators
1.)
2.)
3.)

Expressions in parenthesis
*/%
+-

Page 2 of 18

Computer Fundamentals
Examples:
1.)

10 + 4 * 8
= 10 + 32
= 42

2.)

50 % 6 5
=25
= -3

3.)

20 / 4 * 9
=5*9
= 45

String Expressions
Examples:
1.)
2.)

3 + 4 = 34
Cris + tina = Cristina

Examples of incorrect usage of the + operator:


3 + 4

100 + Peso

Relational Expressions
Greater than
Less than
Greater than or equal to

>
<
>=

Less than or equal to


Not equal
Is equal to

3 <= 5

Temp1 != Temp2

<=
!=
==

Examples:
Ctr1 > 10

Examples of incorrect Relational Expressions:


30 <= X <= 40

43 >

< 50

Logical Expressions
Hierarchy or Priority of Operators
1.)
2.)
3.)
4.)

Expressions in parenthesis
Not (!)
And (&&)
Or (||)

Page 3 of 18

Computer Fundamentals

TRUTH TABLE FOR NOT(!)


X
FALSE
TRUE

!X
TRUE
FALSE

TRUTH TABLE FOR AND(&&)


X
FALSE
FALSE
TRUE
TRUE

Y
FALSE
TRUE
FALSE
TRUE

X && Y
FALSE
FALSE
FALSE
TRUE

TRUTH TABLE FOR OR(||)


X
FALSE
FALSE
TRUE
TRUE

Y
FALSE
TRUE
FALSE
TRUE

X || Y
FALSE
TRUE
TRUE
TRUE

Examples:
15 >= 10 && 15 <= 20
T
&&
T
T
Statements are keywords, which perform a predefined procedure. The following
statements are available:
1.)
2.)
3.)

IF Statement
WHILE Statement
FOR Statement

Exercises:
1.)
2.)
3.)
4.)
5.)
6.)
7.)
8.)
9.)

11 % 2 + 3 * 7 2
100 % 5 % 3 % 2
(45 / 9) * 6 + 4
(5 + 7) % (10 * 2 5) / (15 (8 6 % 4))
(8 + 21 % (18 5 * 3)) % (17 (6 + 13 % 5))
(12 == 12 % 2 * 2) && !(( 5 > 3) && (8<3))
(6 > 3) && (8 != 8) || !(10 <= 10)
15 / 3 == 15 % 3
5 != 11 / 2

Page 4 of 18

Computer Fundamentals

Exercises:
10.) Number of enrollees exceeded 5,000 students.
11.) HEIGHT is at least 170 cm.
12.) REVENUE is at most 80% of SALES.
13.) X is either 6, 8 , or 10
14.) X is any number except 1, 2, and 3.
15.) X is between 100 and 200.
FLOWCHARTS
- A graphic form of an algorithm.
- A diagram of a sequence of steps that a program must perform to produce the
desired output.
- Traditional tool of programmers which allow flexibility in terms of detail to be
included.
TYPES OF FLOWCHARTS
1.) System Flowchart present the total picture without worrying about taking
care of every detail.
2.) Program Flowcharts depicts a main segment of a complete computer
program.
FLOWCHARTING GUIDELINES
1.) Always use the ANSI standard symbols.
2.) Construct your flowcharts to read from top to bottom and left to right.
3.) Do not crisscross flow lines (used labeled connectors and use arrowheads to
indicate direction of the flow.
4.) Make the messages and labels in the flowchart symbol direct and descriptive.
5.) Strive for neatness, clarity and simplicity.

Page 5 of 18

Computer Fundamentals

BASIC FLOWCHARTING SYMBOLS

Terminal Symbol

Preparation Symbol

Processing Symbol

Decision Symbol

Input/Output Symbol

Predefined Process Symbol

Onpage Connector

Offpage Connector

Flow Direction Lines

Page 6 of 18

Computer Fundamentals

Punched Card

Magnetic Tape

Online Storage

Document Printout

PSEUDOCODE
- An outline of a program.
- There is no real formatting or syntax rules for pseudocode.
- It cannot be compiled nor executed.

A SIMPLE PSEUDOCODE
This pseudocode will prompt the user to input length and width of a rectangle and
compute and output its area
start
Declarations
num length
num width
num area
output Input length and width of a rectangle:
input length
input width
area = length * width
output Area of a rectangle = , area
stop

Page 7 of 18

Computer Fundamentals
C++ SPECIFICS
Data Types
Type

Size

Range of Values

unsigned short int


short int
unsigned long int
long int
int
unsigned int
char
bool
float
double

2 bytes
2 bytes
4 bytes
4 bytes
4 bytes
4 bytes
1 bytes
1 bytes
4 bytes
8 bytes

0 to 65, 535
-32,768 to 32,767
0 to 4, 294,967,295
-2,147,483,648 to 2,147,483,647
-2,147,483,648 to 2,147,483,647
0 to 4, 294,967,295
256 characters
true or false
1.2e-38 to3.4e38
2.2e-308 to 1.8e308

Escape Sequence Character


Character combinations consisting of a backslash (\) followed by a letter or by a
combination of digit is called "escape sequences."

Escape Sequence
\a
\b
\f
\n
\r
\t
\v
\'
\"
\\
\?
\ ooo
\x hh
\x hhhh

Represents
Bell (alert)
Backspace
Formfeed
New line
Carriage return
Horizontal tab
Vertical tab
Single quotation mark
Double quotation mark
Backslash
Literal question mark
ASCII character in octal notation
ASCII character in hexadecimal notation
Unicode character in hexadecimal notation
if this escape sequence is used in a widecharacter constant or a Unicode string
literal.
For example, WCHAR f = L'\x4e00' or
WCHAR b[] = L"The Chinese character for
one is \x4e00".

Page 8 of 18

Computer Fundamentals
C++ SPECIFICS

Compound Operators
In addition to basic Arithmetic operators, compound operators are available in C++.
The following are the compound Operators in C++: *=, /=, %=, +=, and - =
Normal Arithmetic Expression

Arithmetic Expression Using Compound


Operators

Var = Var * 2

Var *= 2

Var = Var / 3

Var /= 3

Var = Var % 5

Var %= 5

Var = Var + 4

Var += 4

Var = Var 1

Var -= 1

Unary Operators (Prefix and Postfix)


The available unary operators in C++ are ++ which increments a variable by 1 and - which decrements a variable by 1. It can be written as PREFIX or before the variable or
POSTFIX after the variable.
PREFIX Example:

++X

or

--X

POSTFIX Example:

X++

or

X--

Sample Program 1 :

#include<iostream.h>
int main()
{
int num1=1, num2=2;
num1++;
++num2;

cout<<num1++<<endl;
cout<<num2++<<endl<<endl;

}
Value of num1 = 2 and value of num2 = 3

Page 9 of 18

Computer Fundamentals

Sample Program 2 :

#include<iostream.h>
int main()
{
int num1=1, num2=2;
++num1;
num2++;

cout<<++num1<<endl;
cout<<++num2<<endl<<endl;

}
Value of num1 = 3 and value of num2 = 4

A SIMPLE C++ PROGRAM

/*This program will prompt the user to input length and width
of a rectangle and compute and output its area*/
1
//Programmer: CRISTINA A. PASCUA

#include<iostream.h>
int main()
{ int length, width, area;

3
4

5
6

cout<<Input length and width of a rectangle:


7 ;
cin>>length>>width;
area = length * width;
cout<< Area of a rectangle = <<area;

8
9

return 0;
}

Page 10 of 18

Computer Fundamentals

ELEMENTS OF A C++ PROGRAM


1.)
2.)
3.)
4.)
5.)
6.)

7.)
8.)
9.)

comment represented by // for a single line comment


and /* */ for multiple line comments.
compiler directives
main function
variables
data types
data types includes the following: int, float, double, char
special characters
; - terminates a statement
, - separates variable names of the same type
() used in function declaration and function call
{ } begin and end symbol
expressions can be arithmetic, relational and logical
reserved word cannot be used as a user defined identifier.
example: return, int, float, double, char, for, while, do, etc.
statements - any line terminated by a semicolon

Basic input statement used in C++ is cin

syntax: cin>>variable_name;
cin>>var1>>var2>>var3;
example: cin>>num;
cin>>num1>>num2>>num3;
Basic output statement used in C++ is cout

syntax: cout<<variable_name;
cout<<var1<<var2<<var3;
cout<<string;
cout<<string<<variable_name;
example: cout<<num;
cout<<num1<<num2<<num3;
cout<<Hello Philippines Mabuhay!;
cout<<Sum = <<sum;

Page 11 of 18

Computer Fundamentals

SEQUENTIAL PROGRAM STRUCTURE

1.) Create a flowchart and a C++ program that will input temperature in Celsius and
output the corresponding temperature in Fahrenheit.
The formula is a follows:
Fahrenheit = 9 (Celsius) + 32
5
Flowchart

Start

Declarations
num F, C

C++ Program
#include <iostream >
using namespace std;
int main()
{
double F, C;

F=0

F = 0;
cout<< Input temperature in Celsius: ;
cin>> C;
F = (9.0 / 5.0) * C + 32;
cout<< Temperature in Fahrenheit:<<F<<endl;
return 0;

Input C

F = (9.0/5.0) * C + 32

Output F

Stop

Page 12 of 18

Computer Fundamentals

2.) Pepperoni++ Pizza House charges 10% service charge and 5% sales tax on the
gross bill of the customer. Create a flowchart and a C++ program that would input the
gross bill of the customer and the amount given by the customer to the waiter. It must
output the customers total bill and change (if theres any).
Flowchart
Start
Declarations
num GBill, Amt, change, TBill

TBill = 0
change = 0
Input GBill, Amt

Output TBill, change

TBill = Gbill + Gbill *0.1 + Gbill * 0.05


change = Amt - TBill

C++ Program
#include<iostream>
using namespace std;
int main()
{ int GBill, Amt, change, TBill;
TBill = 0;
change = 0;
cout<< Input Gross Bill and Amount Given: ;
cin>> GBill>> Amt;
TBill = GBill + GBill * 0.1 + GBill * 0.05;
change = Amt Tbill;
cout<< Total Bill = << Tbill<<endl;
cout<< Change = << change<<endl;
return 0;
}

Stop

Page 13 of 18

Computer Fundamentals

3.) Ten young men agreed to purchase a gift worth 10,000 Pesos for their super idol. In
addition, they agreed to continue with their plan even if at least one of them drops out.
Create a flowchart and a C++ program that would input the number of men who dropped
out (assume 0 to 9 only) and output how much more will each have to contribute toward
the purchase of the gift.
Flowchart

Start
Declarations
num DO, AC

AC = 0
Input DO

C++ Program
#include <iostream>
using namespace std;
int main()
{ double DO, AC;
AC = 0;
cout<< Input number of men who dropped out: ;
cin>> DO;
AC = (1000.00 * DO) / (10 DO);
cout Additional Contribution =<< AC<<endl;
return 0;
}

AC = (1000.00 * DO) / (10-DO)

Output AC

Stop

Page 14 of 18

Computer Fundamentals

4.) Create a flowchart and a C++ program that would input an integer number and then
output its ones digit or the right most digit.
Flowchart
Start

Declarations
num number, RDigit
RDigit = 0
Input number

RDigit = number % 10

C++ Program
#include<iostream>
using namespace std;
int main()
{ int num, RDigit;
RDigit = 0;
cout<< Input an integer number: ;
cin>> num;
RDigit = num % 10;
cout<< Its rightmost digit is <<RDigit<<endl;
return 0;
}

Output RDigit

Stop

Page 15 of 18

Computer Fundamentals

5.) Workers at a particular company were given a 15.5% salary increase. Moreover, the
increase was retroactive for 2 months, that is, effective two months ago. Create a
flowchart and a C++ program that takes the employees old salary as input and then
output the amount of retroactive pay (balance) due the employee and his new salary as
well.

Flowchart
Start

Declarations
num OS, Retro, NS

Retro = 0
NS = 0

Input OS

Retro = (OS *0.155) *2


NS = OS + OS * 0.155

C++ Program
#include <iostream>
using namespace std;
int main()
{ double OS, Retro, NS;
Retro = 0;
NS = 0;
cout<< Input employees old salary: ;
cin>>OS;
Retro = (OS * 0.155) * 2;
NS = OS + OS * 0.155;
cout<<Retroactive pay = <<Retro<<endl;
cout<<New salary = <<NS<<endl;
return 0;
}

Output Retro, NS

Stop

Page 16 of 18

Computer Fundamentals

6.) Create a flowchart and a C++ program that would input numeric values to A, B, C, D
and exchange their values such that A goes to B, B goes to C, C goes to D, and D goes
to A.
Flowchart
Start

Declarations
num A, B, C, D, Temp

Temp = 0
Input A, B, C, D
Temp = A
A=D
D=C
C=B
B = Temp

C++ Program
#include <iostream>
using namespace std;
int main()
{ int A, B, C, D, Temp;
cout<< Input values for A, B, C, and D: ;
cin>> A>> B>> C>> D;
Temp = A;
A = D;
D = C;
C = B;
B = Temp;
cout<< A<<endl<< B<<endl<< C<<endl<< D<<endl;
return 0;
}

Output A, B, C, D

Stop

Page 17 of 18

Computer Fundamentals

Page 18 of 18

Potrebbero piacerti anche