Beruflich Dokumente
Kultur Dokumente
Compiled by:
SKSU Mission
The University shall primarily provide advanced instruction and professional training in
science and technology, agriculture, fisheries, education and other relevant fields of
study. It shall also undertake and extension services, and provide progressive
leadership in its areas of specialization.
1
TABLE OF CONTENT
Topic
2
Activity 3: Supply the actual binary bits
Activity 4: Supply the normalized value and resulting exponent
Activity 5: Supply the complete binary
Practice and Application
Activity 6: Do it yourself
Closure
Activity 7: Show Me the Value
Lesson 4: Addition and Subtraction Instructions
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Valid or Invalid
Setting the Context
Activity 2: Valid or Invalid
Activity 3: Carry or No carry
Activity 4: Zero or Not Zero
Activity 5: Positive or Negative
Activity 6: Carry, Sign, and Zero
Practice and Application
Activity 7: Do it yourself
Lesson 5: Direct Memory Operands
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Valid or Invalid
Activity 2: Valid or Invalid
Setting the Context
Activity 3: Hexadecimal Value
Activity 4: Hexadecimal Value
Activity 5: Hexadecimal Value
Activity 6: Hexadecimal Value
Practice and Application
Activity 7: Do it yourself
Part II: VC++
Lesson 6: Introduction to Hardware and Software
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: H or S
Setting the Context
Activity 2: Guess Me
Activity 3: 8-bit to decimal and hex
Activity 4: 16-bit to decimal and hex
Activity 5: ASCII codes in decimal, hex and binary
Activity 6: Solve for x
Practice and Application
3
Activity 7: Interpretation
Lesson 7: A First Look at a C++ Program
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: True or False
Setting the Context
Activity 2: Identification
Activity 3: True or False
Activity 4: Always, Sometimes, or Never
Activity 5: Fill in the Blank
Activity 6: Encircle Me
Activity 7: True or False
Practice and Application
Activity 8: Do it yourself
Lesson 8: Variables and Constants
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Encircle Me
Setting the Context
Activity 2: True or False
Practice and Application
Activity 3: Do it yourself
Lesson 9: Arithmetic Expressions
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Find the Output
Setting the Context
Activity 2: Fix the Bug
Activity 3: True or False
Activity 4: Fill in the Blank
Practice and Application
Activity 5: Write a program
Lesson 10: Arrays, apvector and apmatrix Classes
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: True or False
Setting the Context
Activity 2: Valid or Invalid
Practice and Application
Activity 3: Test my Program
Activity 4: Fix the Bug
4
Lesson 11: Logical Expressions and If-else Statements
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Fill in the Blank
Setting the Context
Activity 2: Write a function
Activity 3: Simplify
Practice and Application
Activity 4: Problem Solving
Lesson 12: Iterative Statements: while, for, do-while
Introduction
Learning Outcome
Activating Prior Knowledge
Activity 1: Find my Behavior
Setting the Context
Activity 2: Fill in the Blank
Activity 3: Write a Function
Practice and Application
Activity 4: Problem Solving
5
Part I
Lesson
Introduction
Every number system uses positional notation i.e., each position in which a digit is
written has a different positional value. Each position is power of the base, which is 2 for
binary number system, and these powers begin at 0 and increase by 1.
Hexadecimal number system uses base 16. The digits range from 0 to 15. By
convention, the letters A through F is used to represent the hexadecimal digits
corresponding to decimal values 10 through 15. Main use of hexadecimal numbers in
computing is for abbreviating lengthy binary representations. Basically hexadecimal
number system represents a binary data by dividing each byte in half and expressing the
value of each half-byte.
Learning Outcomes
At the end of the lesson the students can solved the following types of
problems:
a. Identify positional values for an 8-bit binary numbers;
b. Write the equivalent binary and hexadecimal representation of decimal
number;
c. Convert decimal to binary, binary to decimal, hexadecimal to decimal,
binary to hexadecimal, and hexadecimal to binary; and
d. Solved any number system to its desired base.
Bit Value 1 1 1 1 1 1 1 1
Position value as 128
a power of base 2
Bit number 7 6 5 4 3 2 1 0
6
Complete Me
Directions: Complete the table by writing the equivalent binary and hexadecimal
representation of decimal number. Decimal number 2 was already done for
you.
1. 2 = 6. 12 =
2. 7 = 7. 15 =
3. 5 = 8. 16 =
4. 8 = 9. 20 =
5. 9 = 10. 27 =
7
Conversion: Binary to Decimal
Directions: Write each of the following binary numbers in decimal:
1. 00000101 = 6. 00011100 =
2. 00001111 = 7. 00110000 =
3. 00010000 = 8. 00100111 =
4. 00010110 = 9. 01000000 =
1. 00000101 = 6. 00011100 =
2. 00001111 = 7. 00110000 =
3. 00010000 = 8. 00100111 =
4. 00010110 = 9. 01001000 =
1. 0005h = 6. 001C =
2. 000Fh = 7. 0030h =
3. 0010h = 8. 0027h =
4. 0016h = 9. 0048h =
8
5. 000Bh = 10. 0063h =
1. 00D5h = 6. 041Ch =
2. 002Fh = 7. 0B30h =
3. 0110h = 8. 06DFh =
4. 0216h = 9. 1AB6h =
Comprehension Check
Problem Solving
Directions: Convert the following number system to its desired base. Number 1 is
provided for you. Write your Solution and answer in the space provided.
1. 37410 to base2
Solution:
374/2 = 0 Answer: 1011101102
187/2 = 1
93/2 = 1
44/2 = 0
23/2 = 1
11/2 = 1
5/2 = 1
2/2 = 0
=1
9
2. 37410 to base8
Solution:
3. 75348 to base2
Solution:
4. CAFE16 to base10
Solution:
10
5. 25368 to base16
Solution:
DO it yourself
Directions:
a. 11 = c. 111011 =
b. 1101 = d. 0101 =
a. 11= c. CEF =
b. A1 = d. BA9 =
a. 11 = c. 42 =
b. 4000 = d. 4095 =
a. 10110 + 01101 =
b. 11001 + 00101 =
11
c. 10110 01101 =
d. 11111 01011 =
a. BBCA270C d. 5FCA5243
+AE223464 +AE223464
b. E3BA265F e. 80000000
+ E045B9A9 +7FFFFFFF
a. E9B20F5D f. 6D4AFBC0
+FE605C8D +F89ABCDE
Closure
Individual Work
Directions:
12
Lesson
SIGNED INTEGER
Introduction
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. write the equivalent negative binary numbers of positive numbers;
b. write signed decimal integers in 8-bit binary notation;
c. identify the valid 16-bit signed decimal integers; and
d. perform subtraction of unsigned decimal number.
My negative side
Directions: Write the equivalent negative binary number of the following positive number.
Number 1 was already done for you.
1.
Number +53 00110101
Reverse the bits 11001010
Add 1 1
Number -53 11001011
2.
13
3.
4.
5.
1. -2 5. +15
11111110
2. -7 6. -1
3. -128 7. -56
4. -16 8. +127
14
Find my match
Directions: Match column A to column B by drawing a line connecting to its equivalent
decimal. Number 1 was already done for you provided.
Column A Column B
1. 11111111 1. +15
2. 11110000 2. -16
3. 10000000 3. +85
4. 10000001 4. -4
5. 00001111 5. -1
6. 10101111 6. -127
7. 11111100 7. -128
8. 01010101 8. -81
Valid or Invalid
Directions: Which of the following integers are valid 16-bit signed decimal integers?
Write your answer in the box provided.
(Indicate V=valid, I=invalid)
1. +32469 = 4. +32785 =
2. +32767 = 5. -32785 =
3. -32768 = 6. +65535 =
15
Positive or Negative
Directions: Indicate the sign of each of the following 16-bit hexadecimal integers:
Write your answer in the box provided.
(indicate P=positive, N=negative)
1. 7FB9h =
2. 8123h =
3. 0D000h =
4. 649Fh =
16-bit Hexadecimal
Directions: Write each of the following signed decimal integers as a 16-bit hexadecimal
value. Write your answer in the box provided.
1. -42 5. -32768
2. -127 6. -1
3. -4096 7. -8193
4. -16 8. -256
15
Practice and Application
Do it yourself
Directions: Perform the subtraction with the following unsigned decimal numbers by
taking the 10s complement of the subtrahend. Number 1 was already done
for you.
Solution:
(M>=N)
First take 10s complement on 1321:
10^4 1321 = 9999 1321 + 1 = 8679
Then sum the numbers together:
M = 5250
10s complement of N = +8679
Sum = 13929
Discard end carry = -10000
Answer = 3929
Solution:
16
3. 20 40 (2 digits)
Solution:
Solution:
17
Closure
Individual Work
Directions: Perform the subtraction with the following unsigned binary numbers by
taking the 2s complement of the subtrahend. Write your answer in the box
provided.
Solution:
Solution:
18
Lesson
FLOATING-POINT BINARY
Introduction
Floating point numbers are numbers that contain a fractional part i.e. they contain
a decimal point with numbers after it. They are called floating point because the point can
float or move when the number is expressed using scientific notation.
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. convert fractions to decimal base;
b. write the equivalent base10 fraction and base10 decimal of binary
floating-point numbers;
c. write the actual binary bits used for an 8-bit exponent in the IEEE Short
Real format; and
d. perform floating point addition on the following pairs of values, which
are written in scientific notation.
1. 0.10112
2. 0.21438
19
3. 101.1012
4. 0.00012
5. 101010.11112
20
Supply the actual binary bits
Directions: For each of the following exponent values, shown here in decimal, supply the
actual binary bits that would be used for an 8-bit exponent in the IEEE Short
Real format. The first answer has been supplied for you:
Do it yourself
Directions:
1. Perform floating point addition on the following pairs of values, which are written
in scientific notation. Assume that there are only 5 places of accuracy in the
mantissa. Show your solution.
a. 7. 3892 * 1017
+1.8901 * 1019
c. 7. 3892 * 1014
+1.8901 * 1027
2. Perform Floating point multiplication on the following pairs of values: Show your
soluition.
a. 7. 3892 * 1014
*1.8901 * 1027
b. 3.6000 * 1014
* 5.0000 * 1017
22
Closure
23
Lesson
Introduction
The ADD and SUB instructions are used for performing simple addition/subtraction
of binary data in byte, word and double word size i.e., for adding or subtracting 8-bit, 16-
bit or 32-bit operands, respectively.
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the validity of MOV instruction;
b. identify the validity of unsigned operands; and
c. distinguish carry or no carry, zero or not zero flags.
Directions: Indicate whether or not each of the following MOV instructions is valid:
(notate: V = valid, I = invalid)
24
Setting the Context
Valid or Invalid
Directions: Indicate whether or not each of the following instruction is valid.
(notate: V = valid, I = invalid) Assume that all operands are unsigned.
Carry or No carry
Directions: What will be the value of the Carry flag after each of the following instruction
sequences has executed?
(notate: CY = carry, NC = no carry)
2. mov bh, 2
sub bh, 2
3. mov dx, 0
dec dx
4. mov
al, 0DFh
add
al, 32h
5. mov
si, 0B9F6h
sub
25
si, 9874h
6. mov
cx, 695Fh
sub
cx, A218h
Positive or Negative
Directions: What will be the value of the sign flag after each of the following instruction
sequences has executed?
(notate: PL = positive, NG = negative)
26
sub
si, 9874h
1. mov
ax, 620h
sub
ah, 0F6h
2. mov
ax, 720h
sub
ax, 0E6h
3. mov
ax, 0B6D4h
add
al, 0B3h
27
Practice and Application
Do it yourself
Directions: Create a program that ask two digits from the user, stores the digits in the
EAX and EBX register respectively, adds the values, stores the result in a
memory location res and finally displays the result. Write your code in the box
provided. Use extra sheet of paper if the code doesnt fit in the box.
28
Lesson
Introduction
A direct memory operand specifies the data at a given address. The instruction
acts on the contents of the address, not the address itself. Except when size is implied
by the operand, you must specify the size of a direct memory operand so the instruction
accesses the correct amount of memory. Any location in memory can be a memory
operand as long as a size is specified (or implied) and the location is fixed. The date at
the address can change, but the address cannot. By default, instructions that use direct
memory addressing use the DS register.
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the validity of MOV instruction;
b. write the hexadecimal value of MOV instructions; and
c. create programs that can store data in the memory.
Valid or Invalid
Directions: Indicate whether or not each of the following MOV instructions is valid:
(notate: V = valid, I = invalid)
Use the following data declarations for Question -4. Assume that the offset of byteVal is
00000000h, and that all code runs in Protected mode.
.data
byteVal BYTE 1,2,3,4
wordVal WORD 1000h, 20000h, 3000h, 4000h
dwordVal DWORD 12345678h, 34567890h
aString BYTE ABCDEFG, 0
1. Mov 4. mov
29
ax, byteVal si, aString
2. Mov 5. mov
dx, wordVal esi, offset
aString
3. Mov 6. mov
ecx, dwordVal al, byteVal
Valid or Invalid
Directions: Indicate whether or not each of the following MOV instructions is valid:
(notate: V = valid, I = invalid)
1. mov 4. mov
eax, offset si, dwordVal
byteVal
2. mov 5. mov
dx, wordVal+2 esi, offset
aString+2
3. mov 6. mov
ecx, offset al, offset
dwordVal byteVal+1
Hexadecimal Value
Directions: Indicate the hexadecimal value moved to the destination operand by each of
the following MOV instructions: (If any instruction is invalid, indicate I as the
answer.)
1. mov 4. mov
ax, offset esi, offset
byteVal wordVal
2. mov 5. mov
dx, wordVal esi, offset
aString
30
3. mov 6. mov
ecx, dwordVal al, aString+2
Hexadecimal Value
Directions: Indicate the hexadecimal value moved to the destination operand by each of
the following MOV instructions: (If any instruction is invalid, indicate I as the
answer.)
1. mov 4. mov
eax, offset esi, offset
byteVal+2 wordVal+4
2. mov 5. mov
dx, wordVal+4 esi, offset
aString-1
3. mov
ecx, dwordVal+4
Hexadecimal Value
Directions: Indicate the hexadecimal value moved to the destination operand by each of
the following MOV instructions: (If any instruction is invalid, indicate I as the
answer.)
Use the following data declarations for Questions 5-6. Assume that the offset of byteVal
is 0000:
31
.data
byteVal BYTE 3 DUP(0FFh),2,"XY"
wordVal WORD 2 DUP(6),2
dwordVal DWORD 8,7,6,5
dwordValSiz WORD ($ - dwordVal)
ptrByte DWORD byteVal
ptrWord DWORD wordVal
1. mov 4. mov
eax, offset si, dwordValSiz
wordVal
2. mov 5. mov
dx, wordVal+4 al, byteVal+4
3. mov
ecx, dwordVal+4
Hexadecimal Value
Directions: Indicate the hexadecimal value moved to the destination operand by each of
the following MOV instructions: (If any instruction is invalid, indicate I as the
answer.)
1. mov 5. mov
ax, dwordVal+2 esi, ptrWord
2. mov 6. mov
dx, wordVal-2 edi, offset
dwordVal+2
3. mov
eax, ptrByte
32
Practice and Application
Do it yourself
Directions: Create a program that store name Zara Ali in the data section of the memory.
Then changes its value to another name Nuha Ali programmatically and
displays both the names. Write your code in box provided.
33
Part II
Lesson
Introduction
Hardware and Software have a symbiotic relationship, this means that without
software hardware is very limited; and without hardware, software wouldnt be able to rum
at all. They need each other to fulfill their potential.
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the software and hardware part of a computer system;
b. write the equivalent hex and decimal number of binary number system;
c. write the ASCII codes of the characters in decimal, hex and binary; and
d. Interpret the hex dump of an ASCII data file.
H or S
Directions: Are the following entities or devices part of a computer systems hardware
(H) or software (S). Write your answer in the blank provided.
34
Setting the Context
Guess Me
Directions: Answer what is ask. Write your answer in the space provided.
3. A 12 bit A/D converter digitizes amplitudes of an analog signal into 12-bit numbers.
How many different digitized amplitude values are possible?
________________________________________
4. 16-bit addresses can directly address 64KB of memory. How much memory (in
MB) is directly addressable with 32-bit addresses? ______________________
Example:
35
16-bit to decimal and hex
Directions: Assume that these 16-bit binary numbers represent unsigned integers in the
usual way, with the least significant bit on the right. Write the decimal value
and the hex representation of these binary numbers.
Example:
Solve for x
Directions: Solve for x, where x is a (decimal) number. A character in single quotes
represents the ASCII code for that character:
1. 5 x = O x = _____________
2. G + x = g x = _____________
3. x + j = [ x = _____________
36
Interpretation
Directions: Interpret the following hex dump of an ASCII data file:
1. 45 4E 47 4C 49 53 48 2D-49 54 41 4C 49 41 4E 20 ______________
2. 44 49 43 54 49 4F 4E 41-52 59 0D 0A 77 61 6E 74 ______________
3. 20 20 20 20 76 6F 6C 65-72 65 0D 0A 61 20 20 20 ______________
4. 20 20 20 20 75 6E 0D 0A-49 20 20 20 20 20 20 20 ______________
5. 69 6F 0D 0A 70 72 6F 67-72 61 6D 20 70 72 6F 67 ______________
6. 72 61 6D 6D 61 0D 0A 74-68 69 73 20 20 20 20 71 ______________
7. 75 65 73 74 6F 0D 0A 74-6F 64 61 79 20 20 20 6F ______________
8. 67 67 69 0D 0A 6C 6F 76-65 20 20 20 20 61 6D 61 ______________
9. 72 65 0D 0A ______________
37
Lesson
Introduction
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the statements required in C++ syntax or optional C++ style;
b. identify the valid names of a C++ programs; and
c. construct and restrict C++ program.
True or False
Directions: Mark True or False. Refer to the following program:
#include <iostream.h>
#include apstring.h
int main ()
{
apstring firstName;
cout <<Please enter your first name:;
cin >> firstname;
cout <<firstname
<<,
38
<<
<< Congratulations on your first program!
<<endl;
return 0;
}
Identification
Directions: Identify the following statements as referring to required C++ syntax or
optional C++ style:
True or False
Directions: Mark True or False.
Encircle Me
Directions: Circle all names below that can be used as valid names in a C++ program
without generating a syntax error (even though they may be stylistically awful):
40
True or False
Directions: Mark True or False.
Do it yourself
Directions:
return 0;
}
41
Restructure the program so that the main program prompts the user and displays
the result but the actual conversion is performed in a separate function:
double CslToFahr (double x);
42
Lesson
Introduction
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. understand the basic structure of the C++ program;
b. understand and use the basic data types;
c. recognize and use the keywords and variables;
d. understand and use the constant, character and escape sequence; and
e. understand and use the C typecasting/promotion.
Encircle Me
Directions: Circle the number of syntactically valid declaration:
43
Setting the Context
True or False
Directions: Mark true or false:
Do it yourself
Directions:
1. Assuming that the unsigned short data type is implemented as a two-byte binary
value, what is the largest possible value that an unsigned short variable can
hold? Give your answer as a decimal integer.
44
Lesson
ARITHMETIC EXPRESSIONS
Introduction
Variables and constants of integral and floating point types can be combined into
expressions using arithmetic operators. The arithmetic operators are listed in the following
table:
Operators Description
45
% Modulus
(
remainder from integer division
operands must be integeral
)
++ Increment by one;
can be prefix or postfix;
as postfix has highest precedence
-- Decrement by one;
can be prefix or postfix;
as postfix has highest precedence
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the output program of different C++ statements;
b. fix the bugs of C++ program; and
c. write C++ program.
46
Setting the Context
1. const short days = 365, hours = 24, mins = 60, secs = 60;
cout <<Seconds in a year =
<<hours *mins*secs*double(days)<<endl;
3. short x, y;
cout <<Enter two integers x and y:;
cin>>x>>y;
x *=double (x);
y *=double (y);
double sq_radius = x+y;
if (sq_radius>250000)
cout<<(x,y) is outside the circle\n;
47
True or False
Directions: Mark true or false:
#include <iostream.h>
#include <iomanip.h>
Int main ()
{
Int mins;
cout<< Enter the number of minutes:;
cin>>mins;
cout<<___________________________________<<:
<<setfill (0) // set output fill character to 0
return 0;
}
48
Practice and Application
Write a program
Directions:
1. Write a program that supports the following dialog with the user (the users input
is show in bold):
Enter deposit amount (dollar) ==> 900
Enter annual interest rate (%) ==> 6
Use a variable of an integral type to hold the initial balance entered by the user;
allow amount between 1 and $1,000,000. Use the simple interest formula: the
balance at the end of the year is equal to the balance at the beginning of the year
times (1+rate), where the rate is expressed as a decimal.
49
2. Write a program that prompts the user for his travel distance, the cars gas
mileage (mpg) and the price of gas, and displays the estimated cost of gas for
the trip.
50
Lesson
Introduction
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. identify the rules of apvector and apmatrix classes;
b. identify the validity of apvector and apmatrix declaration; and
c. create a C++ program and fix the error.
True or False
Directions: Mark true or false:
51
Setting the Context
Valid or Invalid
Directions: Write valid or invalid in the following declaration:
Test my Program
Directions: Enter the following declarations and assignments into a test program, compile,
and find out which of them cause problems:
#include apvector.h
apvector<int> a; ___________
apvector<int>b(100); ___________
apvector<double> x (100); ___________
a = b; ___________
x = b; ___________
x = double (b); ___________
52
Fix the bug
Directions: The following statements should double the values of the elements of the array
scores. Find the bug.
int i;
apvector<int> scores(16);
.
i = 0;
// repeat as long as i does not exceed 16:
while (i <= 16) {
scores [i] *=2;
i++;
}
53
Lesson
Introduction
Thus far, most of our labs have dealt solely with the sequence construct. In the sequence
construct each statement is executed in the order in which it occurs in the program.
However, many times our actions are dependent on certain conditions. For instance, if it
is raining outside, then you will take an umbrella. But if the sun is shining, you will leave
the umbrella at home. Similarly, a program might need to execute one statement if one
condition occurs, and execute a different statement if another condition occurs. For
example, if the account balance falls below 0, issue a statement saying the customer is
overdrawn, otherwise continue processing checks. In this lab you will learn how to write
C++ conditions (logical expressions), and you will learn one way of controlling which C++
statement is executed next (the if statement).
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
54
Activating Prior Knowledge
1. bool is digit(char d)
// Returns true if d is a digit (in ASCII code), false otherwise.
{
return _______________________________________________
}
2. bool isalpha(char c)
// Returns true if c is a letter (in ASCII code),
// false otherwise.
{
return ________________________________________________
____________________________________________
}
3. int HexToDec(char hexdigit)
// Returns the decimal value of the corresponding hexadecimal
// digit, where "hexdigit" is a character '0''9' or 'A''F'
// (in ASCII code).
// Returns 1, if "hexdigit" is not a valid hex digit.
// Examples: HexToDec('3') returns 3;
// HexToDec('B') returns 11;
// HexToDec('X') returns 1;
{
int x = 1;
if ( ______________________________________________________ )
55
_________________________________________________;
else if ( ________________________________________________ )
_______________________________________________________;
return x;
}
Write a function
Directions:
1. Write a function
double Max (double x, double y);
that returns the larger of the values x and y (or either, if they are equal).
2. Write a function
bool Later (int moth1, int day1, int year1, int month2, int day2, int year2);
that returns true if the second date is later than the first and false otherwise.
56
Simplify
Directions: Simply the following logical expression:
1.
if (!(x == 7) && !(x > 7))
________________________________________________
2.
bool inside = !((x < left) || (x > right) || (y < top)
|| y > bottom));
________________________________________________
3.
bool no = (ch[0] == 'N' && ch[1] == 'O') ||
(ch[0] == 'n' && ch[1] == 'o') ||
(ch[0] == 'n' && ch[1] == 'O');
________________________________________________
_________________________________________________
57
Practice and Application
Problem Solving
Directions:
1. Priority mail costs $3.00 for the first two pounds and $1.00 for each additional
pound or fraction. First class mail costs 32 cents for the first ounce and 23 cents
for each additional ounce or fraction, up to 11 ounces, after which priority rates
apply. Fill in the blanks in the following function:
58
2. Using the rules of short-circuit evaluation, correct the following statement to
prevent accessing elements of the array with subscripts out of bounds:
const int ROWS = 32, COLS = 32;
apmatrix<char> grid(ROWS, COLS);
59
Lesson
C++ provides three iteration statements while, do-while, for. Each of these iterates until
its termination expression evaluates to zero (false), or until loop termination is forced with
a break statement.
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. understand and use the syntax of while, for, and do-while in creating
C++ program;
b. write appropriate function for iterative statement; and
c. solved and create C++ computer programming problems that involves
while, for, and do-while.
60
Activating Prior Knowledge
Find my Behavior
Directions: Describe the behavior of the following program: Write your answer in the box
provided.
#include <iostream.h>
int main()
{
int count = 0;
while (count <= 1) count += 0.1;
cout << count << endl;
return 0;
}
1. Fill in the blanks in the following function that sets the elements of an array to the
integers 1 through n, where nis the length of the array:
void SetSequence (apvector<int> &v)
61
int i, n = ___________________;
for (_____________________________________________________)
__________________________________________________;
}
2. Fill in the blanks in the following function:
Write a Function
Directions:
1. Write a function
double pow(double x, int n);
that returns the value of xn
. Assume that x 0, n 0.
62
2. double Polynomial(const apvector<double> &a, double x)
// Returns the value of the nth degree polynomial
// P(x) = a[0] + a[1]*x + a[2] * x^2 + ... + a[n] * x^n.
// Assumes that the length of a is n+1.
{
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
}
3. Write a function that returns the value of the largest positive element in a 2-D
array, or 0 if all its elements are negative:
double PositiveMax(const apmatrix<double> &m)
// Returns the value of the largest positive element in
// the matrix m, or 0, if all its elements are negative.
{
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
}
63
Practice and Application
Problem Solving
64
Write a test program that defines and initializes (or lets the user enter) two arrays
and displays their long sum.
65
Part III
Lesson
JAVA Programming
Introduction
Java is an object-oriented language similar to C++, but simplified to eliminate
language features that cause common programming errors. Java source code files (files
with a .java extension) are compiled into a format called bytecode (files with a .class
extension), which can then be executed by a Java interpreter. Compiled Java code can
run on most computers because Java interpreters and runtime environments, known as
Java Virtual Machines (VMs), exist for most operating systems, including UNIX, the
Macintosh OS, and Windows. Bytecode can also be converted directly into machine
language instructions by a just-in-time compiler (JIT). In 2007, most Java technologies
were released under the GNU General Public License
Learning Outcome
At the end of the lesson the students can solved the following types of
problems:
a. understand the basic structure of JAVA programming language;
b. understand and use java classes, methods, arrays, and basic
operation in creating java program; and
c. solved and create java computer program.
True or False
Directions: Write T if the statement is True otherwise F if False:
1. The modulus operator (%) in Java can be used only with variables of integer type.
66
3. All bitwise operations are carried out with the same level of precedence in Java.
4. The operations y >> 3 and y >>> 3 produce the same result when y > 0.
5. consider the statement "x = (a > b) ? a : b"; then the value of x is 27, if a = 18 and
b = 27.
8. The "switch" selection structure must end with the default case.
9. For the expression (y >= z && a == b) to be true, at least one of (y >= z) and (a ==
b) must be true.
10. A break statement must always be present in the default case of a "switch"
selection structure.
11. Variables declared inside a for loop are limited in scope to the loop.
12. An array in the Java programming language has the ability to store many different
types of values.
13. An individual array element from an array of type int, when passed to a method is
passed by value.
67
14. Objects of a super class can always be assigned to a subclass reference.
17. A static method can refer to any instance variable of the class.
18. All interface methods must be declared as public when implemented in a class.
19. Methods can be overloaded with a difference only in the type of the return variable.
20. A method in a class declared as static can only access static class members.
21. A method in a class declared as static may be invoked simply by using the name
of the method alone.
23. Java does not allow a method with the same signature in a subclass, as a method
in the super class.
68
27. A method declared as final can be overridden by subclasses if it is also declared
as static.
28. A method that is overridden in the subclass must retain the same return type and
parameter list.
Multiple Choice
Directions: Write the letter of your choice only:
71
13. If you want to assign a value of 99 to the variable year, then which of the
following lines can be used within an tag?
a. number = getParameter(99)
b. < number = 99 >
c. < param = radius value = 99 >
d. < param name = number value = 99 >
e. < param number = 99 >
14. Given file is a File object, which of the following are legal statements to create a
new file?
(A) file.create();
(B) FileOutputStream fos = new FileOutputStream(file);
(C) FileWrter out = new FileWriter(file);
(D) FileInputStream fis = new FileInputStream(file);
(E) RandomAccessFile raf = new RandomAccessFile(file);
a. (B), (C) & (E)
b. (A), (B), (D) & (E)
c. (B), (C) & (D)
d. (B), (D) & (E)
e. (B) & (C)
15. Which of the following statements about abstract methods/classes in Java are
true?
1. An abstract class cannot be instantiated.
2. Constructors cannot be abstract.
3. A subclass of an abstract class must defined the abstract methods.
4. Static methods may be declared abstract.
a. Line 1, line 2 and line 3 only
b. Line 1 only
c. Line 1 and line 2 only
d. Line 2 only
e. All are true
16. Which keyword can protect a class in a package from accessibility by the
classes outside the package?
a. don't use any keyword at all (make it default)
b. private
c. protected
d. final
17. We would like to make a member of a class visible in all subclasses regardless of
what package they are in. Which one of the following keywords would achieve
this?
a. private
b. protected
c. private OR protected
d. public
72
18. The use of protected keyword to a member in a class will restrict its visibility as
follows:
a. Visible in all classes in the same package and subclasses in other packages.
b. Visible only in the class and its subclass in the same package.
c. Visible only inside the package.
d. Visible only in the class where it is declared.
19. Which of the following are not keywords?
(A) NULL
(B) implements
(C) protected
(D) extended
(E) string
a. (C), (D) & (E)
b. (A), (D) & (E)
c. (D) & (E)
d. (D)
20. Which of the following are keywords?
(A) switch
(B) integer
(C) default
(D) boolean
(E) object
a. (B) & (C)
b. (A) & (C)
c. (D)
d. (E)
21. Which of the following keywords are used to control access to a class member?
(A) default
(B) abstract
(C) protected
(D) interface
(E) public
a. (C) & (E)
b. (A), (C) & (E)
c. All of these.
d. (B), (C) & (E)
22. The keywords reserved but not used in the initial version of Java are:
(A) union
(B) const
(C) inner
(D) goto
(E) boolean
(F) synchronized
73
a. (C) & (E)
b. (A), (C) & (E)
c. (B),(C) & (D)
d. All of these.
23. Consider the following code:
class ClassA
a. (A)
b. (A) & (D)
75
c. (B)
d. (A) & (C
33. Determine the output when the value of x is zero:
if(x >= 0)
if(x > 0)
System.out.println("x is positive");
else
System.out.println("x is negative");
a. "x is negative"
b. "x is positive"
c. "x is positive" and "x is negative"
d. None of these
34. The control expression in an "if" statement must be:
a. an expression with type integer
b. an expression with either the type boolean or integer
c. an expression with either the type boolean or integer with value 0 or 1
d. an expression with type Boolean
35. To print the value of a variable "x" of type int, which of the following expressions
can be used:
(A) System.out.println("x = " + x);
(B) System.out.println("x = " + String.valueOf(x));
(C) System.out.println("x = " + Integer.toString(x));
(D) System.out.println("x = " + (new Integer(x)).toString());
a. (A)
b. (C) & (E)
c. (A) & (B)
d. (C) & (D)
e. None of the above
41. The method int func(int i, int j)
a. (B) & (C)
b. (C) & (D)
c. (A), (B), (C) & (E)
d. (A), (B) & (E)
e. None of these
42. Which error does the following code contain: class Class1
a. There is no error
b. Method func1() must be declared as static
c. Class Class1 has not been declared public
d. Class1 should be declared as abstract
43. What will be the output of the following program?
class Main1
a. XXX
b. YYY
77
c. Error. Won't compile
d. XXX followed by YYY
44. What will be the output of the following program?
class Main2
a. XXX
b. XXX followed by YYY
c. YYY
d. Error. Won't compile
45. What is java_g used for?
a. Using the jdb tool
b. Executing a class with optimization turned off
c. To provide information about deprecated methods
d. None of these
46. With javadoc, which of the following denotes a javadoc comment?
a. //#
b. /**
c. /*
d. //**
47. Which of the following command lines options generates documentation for all
classes and methods?
a. -protected
b. -public
c. -verbose
d. -encoding
e. -private
48. Which javadoc tag is used to denote a comment for a method parameter?
a. @method
b. @parameter
c. @param
d. @argument
e. @value
49. Which of the following statements are valid array declaration?
(A) int number();
(B) float average[];
(C) double[] marks;
(D) counter int[];
a. (A)
b. (B) & (C)
c. (A) & (C)
d. (D)
78
50. Consider the following code
int number[] = new int[5]; After execution of this statement, which of the following
are true?
(A) number[0] is undefined
(B) number[5] is undefined
(C) number[4] is null
(D) number[2] is 0
(E) number.length() is 5
a. (A) & (E)
b. (C) & (E)
c. (B), (D) & (E)
d. (E)
Flash Card
Directions:
Answer: ______________________
10. What will be the output of the following code snippet?
int x = 10;
int y = 20;
if((x||(x=5)>10)
System.out.println(x);
else
System.out.println(y);
Answer: ______
11. Show the output of the following code:
int a, b;
a = 5;
b = 10;
if(a > 5)
if(b > 5)
{
System.out.println("b is " +b);
}
else
80
System.out.println("a is " +a);
Answer: _______
12. State the output of the following code:
int a = 10;
int b = 5;
if(a > b)
{
if(b > 5)
System.out.println("b is " +b);
}
else
System.out.println("a is " +a);
Answer: _____________
13. What is the output of the following code:
int m = 100;
while(true)
{
if(m < 10)
break;
m = m - 10;
}
System.out.println("m is " +m);
Answer: _________
14. What is the output of the following code:
int m = 100;
while(true)
{
if(m < 10)
continue;
m = m - 10;
}
System.out.println("m is " +m);
Answer: ________________
15. Use a single line of code, complete the following class so that it returns x+y if the
value of x is equal to y, otherwise returns 0:
Public class XY
Answer: ____________________
81
Do it yourself
Directions:
82
3. Write a Java program to declare two integer variables, one float variable, and one
string variable and assign 10, 12.5, and "Java programming" to them respectively.
Then display their values on the screen.
Hello Dara!
Write your code here:
83
5. Write Java program to allow the user to input two integer values and then the
program prints the results of adding, subtracting, multiplying, and dividing among
the two values.
To generate a random number, you can use the Random class of java.util
package. You may use the abs() method of Math class to make sure you can get
only a positive number.
Write your code here:
84
7. Write Java program to allow the user to input two float values and then the program
adds the two values together. The result will be assigned to the first variable.
8. Write Java program to allow the user to input the amount of deposit, yearly interest
rate (percentage), and income tax(percentage). Then the program will calculate
the amount of interest that the person earns in the year. See the example output
below:
85
Write your code here:
9. Write Java program to allow the user to input his/her age. Then the program will
show if the person is eligible to vote. A person who is eligible to vote must be older
than or equal to 18 years old.
86
10. Write a Java program to determine whether an input number is an even number.
The program will read three types of scores(quiz, mid-term, and final scores) and
determine the grade based on the following rules:
-if the average score >=90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
Quiz score: 80
Mid-term score: 68
Final score: 90
Your grade is B.
87
Write your code here:
12. Write a Java program to calculate the revenue from a sale based on the unit price
and quantity of a product input by the user.
The discount rate is 10% for the quantity purchased between 100 and 120 units,
and 15% for the quantity purchased greater than 120 units. If the quantity
purchased is less than 100 units, the discount rate is 0%. See the example output
as shown below:
88
Write your code here:
13. Write a Java program by using two for loops to produce the output shown below:
*******
******
*****
****
***
**
89
Write your code here:
14. Write Java program to prompt the user to choose the correct answer from a list of
answer choices of a question.
The user can choose to continue answering the question or stop answering it.
See the example below:
a. int
b. continue
c. break
d. exit
Enter your choice: b
Incorrect!
Again? press y to continue:
Write your code here:
90
15. By using do while loop, write Java program to prompt the user to choose the
correct answer from a list of answer choices of a question.
The user can choose to continue answering the question or stop answering it.
See the example below:
a. int
b. continue
c. break
d. exit
Enter your choice: b
Incorrect!
Again? press y to continue:
Write your code here:
91
Answer Key:
Part I.
Lesson 1.
Activity 1: Fill in the Blank
Bit Value 1 1 1 1 1 1 1 1
Position value as 128 64 32 16 8 4 2 1
a power of base 2
Bit number 7 6 5 4 3 2 1 0
Activity 2: Complete Me
Decimal Number Binary Representation Hexadecimal Representation
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
6. 2 = 00000010 6. 12 = 00001100
7. 7 = 00000111 7. 15 = 00001111
8. 5 = 00000101 8. 16 = 00010000
9. 8 = 00001000 9. 20 = 00010100
10. 9 =00001001 10. 27 = 00011011
6. 00000101 = 5 6. 00011100 = 28
7. 00001111 = 15 7. 00110000 = 48
8. 00010000 = 16 8. 00100111 = 39
9. 00010110 = 22 9. 01000000 = 64
92
10. 00001011 = 11 10. 01100011 = 99
Activity 5: Binary to Hexadecimal
Lesson 2.
Column A Column B
9. 11111111 1. +15
10. 11110000 2. -16
93
11. 10000000 3. +85
12. 10000001 4. -4
13. 00001111 5. -1
14. 10101111 6. -127
15. 11111100 7. -128
16. 01010101 8. -81
7. +32469 = V
8. +32767 = V
9. -32768 = V
10. +32785 = I
11. -32785 = I
12. +65535 = I
5. 7FB9h = P
6. 8123h = N
7. 0D000h = N
8. 649Fh = P
Lesson 3.
Activity 2: Base 10 Fraction and Decimal
94
Activity 3: Supply the actual binary bits
Exponent (E) Binary Representation
2 10000001
5 10000100
0 01111111
-10 01110101
128 11111111
-1 01111110
Lesson 4.
Activity 1: Valid or Invalid
95
19. mov ip,ax = I 19. mov 123, dh = I
10. mov si, cl = I 20. mov ss, ds = I
9. mov bh, 2
NC
sub bh, 2
11. mov
CY
al, 0DFh
add
al, 32h
12. mov
NC
si, 0B9F6h
sub
si, 9874h
13. mov
cx, 695Fh
CY
sub
cx, A218h
4. mov
ax, 620h CY, PL, NZ
sub
ah, 0F6h
5. mov
ax, 720h NC, PL, NZ
sub
ax, 0E6h
6. mov
CY, NG, NZ
97
ax, 0B6D4h
add
al, 0B3h
Lesson 5.
Activity 1: Valid or Invalid
4. Mov I
4. mov I
ax, byteVal si, aString
5. Mov 5. mov
V V
dx, wordVal esi, offset
aString
6. Mov 6. mov
ecx, dwordVal V al, byteVal V
4. mov 4. mov
eax, offset V si, dwordVal I
byteVal
5. mov 5. mov
dx, wordVal+2 V esi, offset V
aString+2
6. mov 6. mov
V I
ecx, offset al, offset
dwordVal byteVal+1
Activity 3: Hexadecimal Value
4. mov 4. mov
ax, offset esi, offset
byteVal wordVal
000000000h 00000014h
5. mov 5. mov
dx, wordVal esi, offset
aString
1000h
43h (C)
6. mov 6. mov
ecx, dwordVal al, aString+2
12345678h 0000000Ch
14. move di, offset
98
wordVal
00000004h
4. mov 4. mov
eax, offset esi, offset
byteVal+2 wordVal+4
00000002h 00000008h
5. mov 5. mov
dx, wordVal+4 esi, offset
aString-1
3000h
00000013h
6. mov
ecx, dwordVal+4
3456780h
4. mov 4. mov
eax, offset si, dwordValSiz
wordVal
00000006h 0010h
5. mov 5. mov
dx, wordVal+4 al, byteVal+4
0002h 58h (X)
6. mov
ecx, dwordVal+4
0000007h
5. mov 6. mov
dx, wordVal-2 edi, offset
5958h (YX) dwordVal+2
000000Eh
99
6. mov
eax, ptrByte
00000000h
Part II.
Lesson 6.
Activity 1. H o S
1. Operating system _____S______
2. CPU ____H_______
3. Compiler _____S______
4. Program editor _____S______
5. IDE _____S______
6. GUI (Graphical User Interface) _____S______
7. Assembler _____S______
8. Bus _____H______
9. RAM ______H_____
10. ROM _______H____
11. File ______S_____
12. Modem _______H____
Part III.
1. F 11. F 21. F
2. F 12. F 22. F
3. F 13. T 23. F
4. T 14. F 24. T
5. T 15. T 25. F
6. T 16. T 26. F
7. F 17. F 27. T
8. F 18. T 28. T
9. F 19. F 29. F
10. F 20. T
1. a 5. d 9. c
2. d 6. d 10. d
3. c 7. d 11. d
4. a 8. b 12. b
100
13. d
14. a 35. d
15. c 36. a
16. a 37. e
17. c 38. b
18. a 39. b
19. b 40. d
20. b 41. d
21. d 42. d
22. c 43. c
23. d 44. b
24. d 45. b
25. d 46. b
26. c 47. e
27. b 48. c
28. b 49. b
29. a 50. c
30. c
31. a
32. b
33. a
34. d
1. o
2. 161
3. x = x<0?-x:x
4. n4 = 40; is unreachable
5. 200
6. six:33
7. null
8. s =
9. (i=10) is the problem
10. 10
11. a is 5
12. No output
13. m is 0
14. No output; Infinite loop
15. return(x == y)?x+y:0;
19
Activity 4: Do it
yourself
System.out.println("*****");
19
int ("The value of a
resulta,results,result static void after adding:"+a);
m; caculateValues(){
float resultd;
Scanner sc=new int a; }
Scanner(System.in) Random rn=new
; Random(); }
System.out.print("E a=1+Math.abs(rn.n
nter a:"); extInt()%6); 8. import java.util.*;
a=sc.nextInt(); System.out.println( public class
System.out.print("E "The result: "+a); JavaExercises
nter b:"); {
b=sc.nextInt(); public static void
resulta=a+b; } main(String[] args)
results=a-b; {
caculateInterest();
resultm=a*b; }
}
resultd=(float)a/b; 7. import java.util.*;
System.out.println( public class static void
"The result of JavaExercises caculateInterest(){
adding is {
"+resulta); float amount_dep,
public static void
System.out.println( rate, tax,
main(String[] args) interest_earned,
"The result of { tax_amount;
subtracting is
caculateValues(); Scanner sc=new
"+results); Scanner(System.in);
}
System.out.println( System.out.print("Ent
"The result of er the amount of
multiplying is static void deposit:");
"+resultm); caculateValues(){ amount_dep=sc.nextF
System.out.println( loat();
float a; System.out.print("Ent
"The result of
er yearly interest
dividing is float b;
rate:");
"+resultd); Scanner sc=new rate=sc.nextFloat();
Scanner(System.in) interest_earned=amo
; unt_dep*(rate/100);
} System.out.print(" //amount of interest
before tax calculation
Enter a:");
} System.out.print("Ent
a=sc.nextFloat(); er income tax rate:");
6. public class System.out.println tax=sc.nextFloat();
JavaExercises ("The value of a tax_amount=interest_
{ earned*(tax/100);
before adding:"+a);
public static void interest_earned-=tax;
System.out.print("
main(String[] args) //the final interest
{ Enter b:"); earned
caculateValues(); b=sc.nextFloat(); System.out.println("T
} a+=b; he interest earned in
System.out.println the
19
year:"+interest_earned main(String[] args) mid_score,final_sc
); { ore,avg;
determineEven(); Scanner sc=new
} Scanner(System.in)
}
;
} static void System.out.print("
9. determineEven(){ Quiz score:");
import java.util.*; quiz_score=sc.next
public class Float();
int num=0;
JavaExercises System.out.print("
Scanner sc=new Mid-term score:");
{
Scanner(System.in) mid_score=sc.next
public static void
; Float();
main(String[] args)
{ System.out.print("E System.out.print("F
checkEligibility(); nter a number:"); inal score:");
} num=sc.nextInt(); final_score=sc.next
if(num%2==0) Float();
static void System.out.println( avg=(quiz_score+
checkEligibility(){ "It is an even mid_score+final_sc
number."); ore)/3;
int age; else
Scanner sc=new System.out.println( if(avg>=90)
Scanner(System.in) "It is an odd System.out.println(
; number."); "Your grade A.");
System.out.print(" else if((avg>=70)
What is your && (avg<90))
age?"); System.out.println(
} "Your grade B.");
age=sc.nextInt();
if(age>=18) else if((avg>=50)
} && (avg<70))
System.out.println(
"You are eligible to System.out.println(
vote."); "Your grade C.");
else else if(avg<50)
System.out.println( 11. import java.util.*; System.out.println(
"You are not public class "Your grade F.");
eligible to vote."); JavaExercises else
{ System.out.println(
public static void "Invalid");
} main(String[] args)
{
} showGrade(); }
10. import java.util.*; }
public class }
static void 12. import java.util.*;
JavaExercises
showGrade(){ public class
{
public static void JavaExercises
float quiz_score,
20
{ revenue- int i,j;
public static void =discount_amount; for(i=0;i<=6;i++){
main(String[] args) } for(j=1;j<=7-i;j++)
{ System.out.print("*
calculateSale(); else ");
} if(quantity>120) System.out.println(
{ "");
}
static void discount_rate=(floa
calculateSale(){ t)15/100;
}
revenue=unitprice*
float unitprice=0f; quantity; }
int quantity=0; discount_amount= 14.
float revenue=0f; revenue*discount_ import java.io.*;
float rate;
discount_rate=0f, revenue- public class
discount_amount= =discount_amount; JavaExercises
0f; } {
public static void
Scanner sc=new System.out.println( main(String[] args)
Scanner(System.in) "The revenue from {
; sale:"+revenue+"$" selectChoice();
System.out.print("E ); }
nter unit price:"); System.out.println(
unitprice=sc.nextFl "After static void
oat(); discount:"+discoun selectChoice(){
System.out.print("E t_amount+"$("+dis
nter quantity:"); count_rate*100+" String choice;
quantity=sc.nextInt %)"); String con="y";
(); } try{
BufferedReader
if(quantity<100) } br=new
revenue=unitprice* BufferedReader(ne
quantity; w
else 13. public class
InputStreamReader
if(quantity>=100 JavaExercises
(System.in));
&& quantity<=120) {
public static void System.out.println(
{ "What is the
discount_rate=(floa main(String[] args)
{ command keyword
t)10/100; to exit a loop in
printStars();
revenue=unitprice* Java?");
}
quantity; System.out.println(
discount_amount= static void "a.quit");
revenue*discount_ printStars(){ System.out.println(
rate;
21
"b.continue"); nter your choice:");
System.out.println( } choice
"c.break"); =br.readLine();
System.out.println( }
"d.exit"); 15. import java.io.*; if
(choice.compareTo
public class ("c")==0)
JavaExercises {
while
{ System.out.println(
(con.compareTo("y
public static void "Congratulation!");
")==0) }
{ main(String[] args)
{ else if
selectChoice(); (choice.compareTo
System.out.print("E ("q")==0 ||
}
nter your choice:"); choice.compareTo(
choice static void "e")==0)
=br.readLine(); selectChoice(){ { System.out.printl
n("Exiting...!");
if String choice; break; }
(choice.compareTo String con; else
("c")==0) try{ System.out.println(
{ BufferedReader "Incorrect!");
System.out.println( br=new
"Congratulation!"); BufferedReader(ne System.out.print("
w Again? press y to
}
InputStreamReader continue:");
else if
(System.in)); con =br.readLine();
(choice.compareTo } while
("q")==0 || System.out.println(
"What is the (con.compareTo("y
choice.compareTo( ")==0);
command keyword
"e")==0)
to exit a loop in
{ System.out.printl Java?"); }catch(IOExceptio
n("Exiting...!"); System.out.println( n e){}
break; } "a.quit");
else System.out.println(
System.out.println( "b.continue"); }
"Incorrect!"); System.out.println(
"c.break"); }
System.out.print(" System.out.println(
Again? press y to "d.exit");
continue:");
con =br.readLine();
} do
{
}catch(IOException
System.out.print("E
e){}
22
References:
ebook:
M. Litvin and G. Litvin, Workbook to Accompany C++ for You++, Skylight
Publishing, 1998
Kip R. Irvine. 2008, Assembly Language Workbook, Prentice-Hall
Addison-Wesley, (2013), The C++ Programming Language (4th Edition)
Backman, K., (2012), Structured Programming with C++
Bronson, G.J., (2006), Program Development and Design using C++
Intenet:
http://www.skylit.com.