Course Material - Computer Fundamentals
Course Material - Computer Fundamentals
TERMINOLOGIES:
Software – Programs
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.
PROCESS OUTPUT
INPUT
Page 1 of 32
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 computer’s 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.) Must contain only letters, numbers and/or an underscore.
b.) Must begin with a letter.
c.) Must Stop either with a letter or a number.
d.) Must be unique that is, not a name of another variable.
e.) 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:
Arithmetic Expressions
Hierarchy or Priority of Operators
Page 2 of 32
Computer Fundamentals
Examples:
1.) 10 + 4 * 8
= 10 + 32
= 42
2.) 50 % 6 – 5
=2–5
= -3
3.) 20 / 4 * 9
=5*9
= 45
String Expressions
Examples:
1.) “3” + “4” = “34”
2.) “Cris” + “tina” = ”Cristina”
Examples of incorrect usage of the + operator:
“3” + 4 100 + “Peso”
Relational Expressions
Examples:
Logical Expressions
Hierarchy or Priority of Operators
Page 3 of 32
Computer Fundamentals
X !X
FALSE TRUE
TRUE FALSE
X Y X && Y
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE
X Y X || Y
FALSE FALSE FALSE
FALSE TRUE TRUE
TRUE FALSE TRUE
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.) IF Statement
2.) WHILE Statement
3.) FOR Statement
Exercises:
1.) 11 % 2 + 3 * 7 –2
2.) 100 % 5 % 3 % 2
3.) – (45 / 9) * 6 + 4
4.) (5 + 7) % (10 * 2 – 5) / (15 – (8 – 6 % 4))
5.) (8 + 21 % (18 – 5 * 3)) % (17 – (6 + 13 % 5))
6.) (12 == 12 % 2 * 2) && !(( 5 > 3) && (8<3))
7.) (6 > 3) && (8 != 8) || !(10 <= 10)
8.) 15 / 3 == 15 % 3
9.) 5 != 11 / 2
Page 4 of 32
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
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
Page 5 of 32
Computer Fundamentals
Terminal Symbol
Preparation Symbol
Processing Symbol
Decision Symbol
Input/Output Symbol
Onpage Connector
Offpage Connector
Page 6 of 32
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
Page 7 of 32
Computer Fundamentals
C++ SPECIFICS
Data Types
Page 8 of 32
Computer Fundamentals
C++ SPECIFICS
Compound Operators
The following are the compound Operators in C++: *=, /=, %=, +=, and - =
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.
#include<iostream.h>
Sample Program 1 :
int main()
num1++; cout<<num1++<<endl;
Page 9 of 32
Computer Fundamentals
Sample Program 2 :
#include<iostream.h>
int main()
++num1; cout<<++num1<<endl;
/*This program will prompt the user to input length and width
of a rectangle and compute and output its area*/
//Programmer: CRISTINA A. PASCUA 1
2
#include<iostream.h>
int main() 3
{ int length, width, area;
4
5
6
cout<<“Input length and width of a rectangle: “;
cin>>length>>width; 7
area = length * width;
cout<<“ Area of a rectangle = “<<area;
8
return 0;
} 9
Page 10 of 32
Computer Fundamentals
syntax: cin>>variable_name;
cin>>var1>>var2>>var3;
example: cin>>num;
cin>>num1>>num2>>num3;
Page 11 of 32
Computer Fundamentals
1.) Create a flowchart and a C++ program that will input temperature in Celsius and
output the corresponding temperature in Fahrenheit.
Fahrenheit = 9 (Celsius) + 32
5
Flowchart
C++ Program
F=0 F = 0;
cout<<” Input temperature in Celsius: ”;
cin>> C;
Input C F = (9.0 / 5.0) * C + 32;
cout<< “Temperature in Fahrenheit:”<<F<<endl;
return 0;
F = (9.0/5.0) * C + 32 }
Output F
Stop
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
Page 12 of 32
Computer Fundamentals
gross bill of the customer and the amount given by the customer to the waiter. It must
output the customer’s total bill and change (if there’s any).
Flowchart
C++ Program
Start
#include<iostream>
Declarations using namespace std;
num GBill, Amt, change, TBill
int main()
{ int GBill, Amt, change, TBill;
TBill = 0
TBill = 0;
change = 0
change = 0;
cout<< ” Input Gross Bill and Amount Given: ”;
Input GBill, Amt cin>> GBill>> Amt;
TBill = GBill + GBill * 0.1 + GBill * 0.05;
change = Amt – Tbill;
Output TBill, change cout<< “Total Bill = ”<< Tbill<<endl;
cout<< “Change = ”<< change<<endl;
return 0;
}
TBill = Gbill + Gbill *0.1 + Gbill * 0.05
change = Amt - TBill
Stop
C++ Program
#include <iostream>
using namespace std;
int main()
{ double DO, AC;
AC = 0;
3.) Ten young men agreed to purchase a gift worth 10,000 Pesos for their super idol. In
cout<< ” Input number of men who dropped out: ”;
addition, they agreed to continue with their plan even if at least one of them drops out.
cin>> DO;
AC = (1000.00 * DO) / (10 – DO);
cout “Additional Contribution =”<< AC<<endl;
Page 13 of 32
return 0;
}
Computer Fundamentals
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
Output AC
Stop
4.) Create a flowchart and a C++ program that would input an integer number and then
output its one’s digit or the right most digit.
Page 14 of 32
Computer Fundamentals
Flowchart
Start C++ Program
#include<iostream>
Declarations using namespace std;
num number, RDigit
int main()
{ int num, RDigit;
RDigit = 0 RDigit = 0;
cout<< ” Input an integer number: ”;
cin>> num;
Input number
RDigit = num % 10;
cout<< “It’s rightmost digit is ”<<RDigit<<endl;
return 0;
RDigit = number % 10
}
Output RDigit
Stop
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
Page 15 of 32
Computer Fundamentals
flowchart and a C++ program that takes the employee’s old salary as input and then
output the amount of retroactive pay (balance) due the employee and his new salary as
well.
#include <iostream>
Start
using namespace std;
Retro = 0;
NS = 0;
Retro = 0
cout<<” Input employees old salary: ”;
NS = 0
cin>>OS;
Retro = (OS * 0.155) * 2;
Input OS NS = OS + OS * 0.155;
cout<<“Retroactive pay = ”<<Retro<<endl;
cout<<“New salary = ”<<NS<<endl;
Retro = (OS *0.155) *2 return 0;
NS = OS + OS * 0.155 }
Output Retro, NS
Stop
6.) Create a flowchart and a C++ program that would input numeric values to A, B, C, D
Page 16 of 32
Computer Fundamentals
and exchange their values such that A goes to B, B goes to C, C goes to D, and D goes
to A.
Output A, B, C, D
Stop
Page 17 of 32
Computer Fundamentals
1.) Create a flowchart and a C++ program that will prompt the user to input two
numbers and output the highest number entered.
Stop
2.) Create a flowchart and a C++ program that would input an integer number and then
Page 18 of 32
Computer Fundamentals
Flowchart
Start
Declarations
num number
Input number
If
number % 2 == 0
Y Output
“even number” A
N
Output
“odd number”
A
Stop
C++ Program
#include<iostream>
using namespace std;
int main()
{ int num
if (num % 2 == 0)
cout<< “ The number you’ve entered is an even number”<<endl;
else
cout<< “ The number you’ve entered is an odd number”<<endl;
return 0;
}
3.) Workers at Kookaburra Factory have a regular working hours of 30 hours per week
Page 19 of 32
Computer Fundamentals
and are paid $ 10.00 per hour. However, if the workers rendered more than 30 hours
per week, the excess hours are paid 75% more. Create a flowchart and a C++ program
that would input the number of hours rendered by a worker in one week and output his
net salary.
Flowchart
Start
Declarations
NHrs, Salary
Input NHrs
If N
Salary = NHrs *10 A
NHrs > 30
Y
Salary = 300 + (NHrs – 30) * 17.50
A
Output Salary
Stop
C++ Program
#include <iostream>
using namespace std;
int main()
{ double NHrs, Salary;
follows:
100 to 120 km/h = 3,000.00 Php
121 km/h and above = 5, 000 Php
Create a flowchart and a C++ program to input the car’s speed and then output
the fine, if there’s any.
5.) In the game of JACK N POY each of the two player choose either a scissors (code
X), paper (code P), or stone (code S). If one chooses scissors and the other chooses
stone then stone wins. If one chooses paper and the other stone then paper wins. If one
chooses paper and the other scissors then scissors wins. If they both choose the same
then the result is a tie. Create a flowchart or a C++ program that will input two character
codes corresponding to the object selected and then output either the message
“PLAYER 1 WINS” or “PLAYER 2 WINS”.
Page 21 of 32
Computer Fundamentals
1.) Create a flowchart/C++ program that will generate the following number series:
10, 5, 9, 10, 8, 15, 7, 20, 6, and 25
Flowchart
Start
Declarations
num X, Y
X = 10 C++ Program
Y=5 #include<iostream>
using namespace std;
int main()
Output X, Y { int X, Y;
X = 10;
Y = 5;
X=X–1 do
Y=Y+5 {
cout<< X<<endl<<Y<<endl;
X = X – 1;
Y = Y + 5;
} while (X >= 6);
while Y return 0;
X >= 6 }
N
Stop
2.) Create a flowchart/C++ program that will generate the following number series:
Page 22 of 32
Computer Fundamentals
Flowchart
#include <iostream>
Declarations using namespace std;
num X, Y, Sum
int main()
{ int X, Y, Sum;
X=0
Y=1 X = 0;
Sum = 1 Y = 1;
Sum = 1;
do
Output Sum {
cout<< Sum<<endl;
Sum = X + Y;
Sum = X + Y X = Y;
X=Y Y = Sum;
Y = Sum } while (Sum <= 55);
return 0;
}
while Y
Sum <= 55
N
Stop
3.) Create a flowchart/C++ program that will generate the following number series:
Page 23 of 32
Computer Fundamentals
Flowchart
Start
C++ Program
Declarations
#include <iostream>
num X, Y
using namespace std;
while Y
Y <= 46
Stop
4.) Create a flowchart/C++ program that will input five numbers and output how many of
Page 24 of 32
Computer Fundamentals
ctr = ctr + 1
Declarations
Num number, ctr, ctre, ctro
while Y
ctr <= 5 B
ctr = 1
ctre = 0
ctro = 0 N
B Output ctro, ctre
Input number
Stop
If Y ctre = ctre + 1 A
number % 2 == 0
ctro = ctro + 1
C++ Program
#include <iostream>
using namespace std;
int main()
{ int num, ctr=1, ctro=0, ctre=0;
do
{
cin>> num;
if (num % 2 == 0)
ctre = ctre + 1;
else
ctro = ctro + 1;
ctr = ctr + 1;
} while (ctr <= 5);
cout<< ctro<<endl<<
5.) Create a flowchart/C++ ctre<<endl;
program that will input five numbers and output how many of
return 0;
}
Page 25 of 32
Computer Fundamentals
Flowchart
A
Start
ctr = ctr + 1
Declarations
num number, ctr, crtp, ctrn
while Y
ctr <= 5 B
ctr = 1
ctrp =0
ctrn = 0 N
B Output ctrp, ctrn
Input number
Stop
If Y
ctrp = ctrp + 1 A
number > 0
N
ctrn = ctrn + 1
C++ Program
#include <iostream>
using namespace std;
int main()
{ int num, ctr=1, ctrp=0, ctrn=0;
do
{
cin>> num;
if (num > 0)
ctrp = ctrp + 1;
else
ctrn = ctrn + 1;
ctr = ctr + 1;
} while (ctr <= 5);
cout<<ctrp<<endl<<ctrn<<endl;
6.) Create a flowchart/C++ program that will input 10 alphabetic characters and output
return 0;
}
Page 26 of 32
Computer Fundamentals
how many of the characters entered were vowels and consonants. Disregard characters
that are not alphabetic.
7.) Create a flowchart/ C++ program that will input 5 numbers and output the highest
number entered.
8.) Create a flowchart/ C++ program that will input 6 score for quizzes (0-100).
Eliminate the lowest quiz and compute and output the average of the five remaining
quizzes.
ARRAYS
ARRAYS - a series of simple variables grouped together under one single variable.
int Score[5];
Notice that a total of 5 adjacent slots are allotted because the array is declared as size 5.
In effect, array SCORE can hold 5 different values at the same time.
There are certain rules to follow when using subscripts and they are as follows:
Page 27 of 32
Computer Fundamentals
* Subscript must be between 0 and the size of the array minus 1 which in this case
12.
* Subscript must be either an integer constant, numeric variable with integer value
or an arithmetic expression with integer value or an arithmetic expression with
integer result. The above is a character array variable which violates the rule just
mentioned.
* The resulting answer of 15 exceeds the size of the array which was defined as
TOTAL is ARRAY [12]
Score[0] = 10
Score[1] = 20 + 30
Score[3] = X / 5
Page 28 of 32
Computer Fundamentals
Score[4] = X
To assign the content of element number 4 to element number 3, the statement is:
Score[3] = Score[4]
To assign the result of multiplying the content of element number 4 to element number 2
and putting the result in element number 1, the statement is:
To assign zero to all the elements of array Score, the statement is:
ctr = 0
while (ctr<5)
begin
Score[ctr] = 0
ctr = ctr + 1
end
Page 29 of 32
Computer Fundamentals
1.) Create a flowchart/C++ program that would accept 10 numbers and then display
all 10 numbers together with its total.
Flowchart
Start A
Flowchart
Declarations ctr = 0
num NUM[10], ctr, sum
Output NUM[ctr]
ctr = 0
sum = 0
ctr = ctr + 1
Input NUM[ctr]
N
while Output sum
Y
ctr < 10
N Stop
A
C++ Program
#include <iostream>
using namespace std;
int main()
{ int NUM[10];
int ctr=0, sum=0;
do
{
cin>> NUM[ctr];
sum = sum + NUM[ctr];
ctr = ctr + 1;
} while (ctr <10);
ctr =0;
do
{
cout<< NUM[ctr];
ctr = ctr + 1;
} while (ctr < 10);
cout<<“The total of all the numbers entered = “<<sum<<endl;
return 0;
} Page 30 of 32
Computer Fundamentals
2.) Create a flowchart/C++ program that would assign numbers 8-15 to an array of 8
elements. The program must then display the contents of the array starting from
the last element.
Flowchart A
Start
ctr = 7
Declarations
num Num[8], ctr, value
Output NUM[ctr]
ctr = 0
value = 8 ctr = ctr - 1
NUM[ctr] = value
value = value + 1
ctr = ctr + 1 while Y
ctr >= 0
while Y N
ctr <= 7
Stop
N
A
C++ Program
#include <iostream>
using namespace std;
int main()
{ int NUM[8];
int ctr=0, value=8;
do
{
NUM[ctr] = value;
value = value + 1;
ctr = ctr + 1;
} while (ctr <=7);
ctr=7;
do
{
cout<< NUM[ctr];
ctr = ctr – 1;
} while (ctr >= 0);
return 0; Page 31 of 32
}
Computer Fundamentals
Exercises:
1.) Create a flowchart and a C++ program that will declare an array named A with 10
elements. Prompt the user to input values into its first five cells and copy the
numbers entered into its last five cells. Finally, output the content of array A.
2.) Create a flowchart and a C++ program that will input values to array A[10] and
array B[10]. Exchange their values in reverse order and output the new content
of arrays A and B.
3.) Create a flowchart and a C++ program that will declare an array named NUM
with 10 elements. Compute its product such that all the elements in the odd
subscripts will be your multiplicand and all the elements in the even subscript will
be your multiplier. Placed the product into the array named PROD with 5
elements and finally output the content of array PROD.
4.) Create a flowchart and a C++ program that will prompt the user to input numbers
into array C and the input should be terminated by a zero sentinel. Output the
contents of array C and also the highest and the lowest number entered.
Page 32 of 32