Jumat, 22 Maret 2013
refleksi minggu ke-2
Dateng lagi dehhh sabtu 16 maret 2013.huuuuuuuaaaaaaaaa KESIANGAN (semalem tidur jam 3 nyelesaiin tugas minggu lalu), kuliah jam 7 teng dan aku jam ¹/² tujuhh baru bangunn.. Gubrakkkkk Glodakkkk glodakkkk mandi, dandan, dll dipaket hemat Cuma 10 menit. Saat nya beraksi dengan “kang mas” sebutan kepada motor Honda kesayangan, tercinta, terbaik, tersetia, termengerti aku, dan ter ter ter lainnya. Meluncurrrrrrrrrrr tapi gak pake noss 5 menit sampe parkiran,dengan tenaga ekstra lari naik tangga, geal geol ngos ngosan sampe kelas. Huuuuu tarik napas, hembuskan, tarik napas, hembuskan… haaaaa baru deh bernafas lagii dan berkata “Alhamdullillah gak telat”. Gak lama Bapakke dateng, Teng teng,, dimulai deh pelajaran minggu kedua. Dan dan ternyata lebih lebih lebih mengejutkan lagi, kita dituntun untuk ngerjain tugas perkelompok dan kita dituntut untuk kerja tanpa ada yang nganggur satu pun. Selesaiiii pulang bawa bekal tugas lagii, dan belajar dari pengalaman minggu lalu gak mau lagi ahh ngerjainn tugas nunggu hari –H, kapok Lombok aku .Dan saatnya kita menanti pertemuan minggu ketiga dengan harap harap cemas (h²C ).
tugas alpro -3
Counting
Problem
Given a set
of nstudent’s examination marks (in
the range 0 to 100) make a count of the number of students that passed the
examination. A pass is awarded for all marks of 50 and above.
Algorithm description
1. Prompt then read the number of marks
to be processed
2. Initialize count to zero.
3. While there are still marks to be
processed repeatedly do
(a) Read next mark.
(b) If it is a pass (i.e.≥50)then add one
to count.
4. Write out total number of passes.
Pascal implementation
Program passacount (input, output);
Conts passmark=50;
Var count {contains number of passes on
terminitation},
i {current number of marks processed},
m
{current mark},
n {total number of marks to be processed}: integer;
begin {count the number of passed (>=50)
in a set of marks}
writeln (‘enter a number of marks n on a separate
line followed by the marks’);
readln (n);
assert
: n >=0}
count := 0;
i := 0;
{invariant: count = number of marks in
the first I read that are >= passmark ᴧ i=<n}
While i<n do
Begin {read next mark, test it for pass and
update count if necessary}
i := i + 1;
read (m);
if eoln (input) then
readln;
if m >= passmark then
count := count +1
end;
{assert: count = number of passes in the
set of n marks read}
Writeln (‘number
of passes =’, count)
End.
Notes on design
1. Initially, and each time through the
loop, the variable count represents the number of passes so far encountered. On
termination (when i=n) count represents the total number of passes in the set.
Because i is incremented by 1 with each iteration, eventually the condition
i<n will be violated and the loop will terminate.
2. It was possible to use substitution
to improve on the original solution to the problem. The simplest and most
efficient solution to a problem is usually the best all-round solution.
3. An end-of-line test is included to
handle multiple lines of data.
Applications
All forms of
counting.
refleksi minggu -1
semangatt pagi datang menghampiri, eng ing eng,,,,,, saat nya bersiap untuk berangkat kuliah disabtu pagi 09 maret 2013,, jam 06.30 cusssssssssssss deh ke kampus tercinta. Diperjalanan ±10 menit sekalian deh ngebayangin yang kata ny kuliah “Alpro” itu menegangkan dan penuh dengan kejutan. Sampe deh di parkiran, rutinitas biasanya (parkir,kampus,naik tangga, ruang). Jreenggg sampe dikelas eh ternyata pak dosen udah stand bay diruangan.. Jam 07.00 tepat kuliah dimulai, “WOW” baru pertama nemu Pak dosen yang kayak beginian,, susah dah pokoknya diungkapkan dengan kata kata, yang penting suasanane menegangkan sampe ndoplong semua (hahhahha). Kuliah selesai dan ditutup dengan tugas. Alhamdullillah…….
tugas alpro 3 chapter -3
Top-Down Design with Functions
1. Develop your program solutions from existing information. Use the system
documentation derived from applying the software development method as
the initial framework for the program.
■ Edit the data requirements to obtain the main function declarations.
■ Use the refined algorithm as the starting point for the executable statements
in the main function.
2. If a new problem is an extension of a previous one, modify the previous program
rather than starting from scratch.
3. Use C’s library functions to simplify mathematical computations through the
reuse of code that has already been written and tested. Write a function call
(consisting of the function name and arguments) to activate a library function.
After the function executes, the function result is substituted for the
function call.
4. Use a structure chart to show subordinate relationships between subproblems.
5. Utilize modular programming by writing separate function subprograms to
implement the different subproblems in a structure chart. Ideally, your main
function will consist of a sequence of function call statements that activate the
function subprograms.
6. You can write functions without arguments and results to display a list of
instructions to a program user or to draw a diagram on the screen. Use a function
call consisting of the function name followed by an empty pair of parentheses
() to activate such a function.
7. Write functions that have input arguments and that return a single result to
perform computations similar to those performed by library functions. When
you call such a function, each actual argument value is assigned to its corresponding
formal parameter.
8. Place prototypes (similar to function headings) for each function subprogram
before the main function, and place the function definitions after the
main function in a source file. Use (void) to indicate that a function has
no parameters.
Tugas alpro 3 chapter-2
Overview of C
2.1
C Language Elements
Preprocessor
Directives
preprocessor
directive a
C program line beginning with # that provides an instruction to the preprocessor. preprocessor a system program that modifies a C program
prior to its compilation library a collection of useful functions and symbols that may be
accessed by a program
/*
*
Converts distances from miles to kilometers.
*/
#include
<stdio.h>
/* printf, scanf definitions */
#define
KMS_PER_MILE 1.609
/* conversion constant */
int
main(void)
{
double
miles,
/*
distance in miles kms;
/* equivalent distance in kilometers */
/*
Get the distance in miles. */
printf("Enter
the distance in miles> ");
scanf("%lf",
&miles);
/*
Convert the distance to kilometers. */
kms
= KMS_PER_MILE * miles;
/*
Display the distance in kilometers. */
printf("That
equals %f kilometers.\n", kms);
return
(0);
constant macro a name that is
replaced by a particular constant value before the program is sent to the compiler
comment
text
beginning with /* and ending with */ that provides supplementary information
but is ignored by the preprocessor and compiler.
Syntax Displays for Preprocessor Directives
#include Directive for Defining Identifiers from
Standard Libraries
SYNTAX: #include <standard header file>
EXAPLES: #include
<stdio.h>
#include
<math.h>
INTERPRETATION: #include
directives tell the preprocessor where to find the
meanings of standard identifiers used in the program. These meanings are
collected in files called standard header files. ThMe header
file stdio.h contains information about standard input and output
functions such as scanf and printf. Descriptions of common
mathematical functions are found in the header file math.h .
We will investigate header files associated with other standard libraries in
later chapters.
#define
Directive for Creating Constant Macros
SYNTAX: #define
NAME value
EXAMPLES: #define
MILES_PER_KM 0.62137
#define PI 3.141593
#define MAX_LENGTH 100
INTERPRETATION: The C
preprocessor is notified that it is to replace each use of the identifier
NAME
by value . C program statements cannot
change the value associated with NAME .
Function main
declarations
the
part of a program that tells the compiler the names of memory cells in a program
executable statements program executable statements
program lines that are
converted
to
machine language instructions and executed by the computer
EXAMPLE: int
main(void)
{
printf("Hello
world\n");
return (0);
}
Reserved Words
reserved word a word that has
special meaning in C
Standard Identifiers
standard identifier
a
word having special meaning but one that a programmer may redefine (but redefinition is
not
recommended!)
2.2 Variable Declarations and Data Types
Variable Declarations
variable a name associated
with a memory cell whose value can change variable declarations statements that communicate
to the compiler the names of variables in the program and the kind of
information stored in each variable.
Data Types
data type a set of values
and operations that can be performed on those values.
Data Type
double A
real number has an integral part and a fractional part that
are separated by a decimal point. In
C, the data type double is used to represent
real numbers (for example, 3.14159 , 0.0005 , 150.0 ). You can store a
real number
in a type double variable, perform
the common arithmetic operations (add,
subtract, multiply, and divide), and
compare them.
The ASCII Code
ASCII code a particular code
that specifies the integer representing each char value.
Assignment Statements
assignment
statement an
instruction that stores a value or a computational result in a variable
Input/Output Operations and Functions
input operation an instruction
that copies data from an input device into memory output operation an instruction
that displays information stored in memory input/output function a C function that
performs an input or output operation. function call calling or
activating a function. function argument enclosed in
parentheses
following
the function
name;
provides
information
needed by
the
function
format string in a call to printf, a string of characters enclosed in quotes ("), which specifies the form
of the
output
line
print list in
a call to
printf, the variables or expressions
whose
values
are displayed
placeholder a
symbol
beginning
with % in
a
format string that indicates where to display the output value newline escape sequence
the character sequence \n, which is used
in a format string to terminate an
output
line.
Syntax
Display for printf Function Call
SYNTAX: printf(
format string, print list );
printf( format
string );
EXAMPLES: printf("I
am %d years old, and my gpa is %f\n",
age, gpa);
printf("Enter
the object mass in grams> ");
1. Every C program has preprocessor
directives and a main function. The main
function contains variable
declarations and executable statements.
2. Variable names must begin with a
letter or an underscore (the latter not recommended)
and consist of letters, digits, and
underscore symbols. A reserved
word cannot be used as an identifier.
3. C’s data types enable the compiler
to determine how to store a particular
value in memory and what operations
can be performed on that value.
Three standard data types are int , d ouble , and char . The data type of
each
variable must be declared.
4. The executable statements are
derived from the algorithm and are translated
into machine language. Assignment
statements are used to perform
computations and store results in
memory. Function calls are used to get
data (function scanf ) and to display
values stored in memory (function
printf ).
Selasa, 19 Maret 2013
tugas alpro -3 chapter 1
Overview Of Computers and Programming
1.1 Electronic Computers Then and Now
These early computers used vacuum tubes as their basic electronic component.
Technological advances in the design and manufacture of electronic components
led to new generations of computers that were considerably smaller, faster, and less
expensive than previous ones.
• The Intel Atom processor chip contains the full circuitry of a central processing unit in an integrated circuit whose small size and low power requirements make it suitable for use in mobile internet devices
• (Intel Corporation Pressroom Photo Archives) computer chip (microprocessor chip) a silicon chip containing the circuitry for a computer processor
hardware the actual computer equipment software the set of programs associated with a computer program a list of instructions that enables a computer toperform a specific task binary number a number whose digits are 0 and 1
1.2 Computer Hardware
Essentially, most consist of the following
components:
■ Main memory
■ Secondary memory, which includes storage devices such as hard disks, CDs,
DVDs, and flash drives
■ Central processing unit
■ Input devices, such as keyboards, mouses, touch pads, scanners, joysticks
■ Output devices, such as monitors, printers, and speakers
Memory
Memory is an essential component in any computer. memory cell an individual storage location in memory address of a memory cell the relative position of a memory cell in the computer’s main memory contents of a memory cell the information stored in a memory cell, either a program instruction or data stored program concept a computer’s ability to store program instructions in main memory for execution
byte the amount of storage required to store a single character bit a binary digit; a 0 or a 1
1000 Memory Cells in Main Memory 00101100 Byte Bit
Relationship Between a Byte and a Bit data storage setting the individual bits of a memory cell to 0 or 1, destroying its previous contents data retrieval copying the contents of a particular memory cell to another storage area random access memory (RAM) the part of main memory that temporarily stores programs, data, and results.
read-only memory (ROM) the part of main memory that permanently stores programs or data volatile memory memory whose contents disappear when the computer is switched off secondary storage units such as disks or flash drives that retain data even when the power to the drive is off disk thin platter of metal or plastic on which data are represented by magnetized spots arranged in tracks optical drive device that uses a laser to access or store data on a CD or DVD
flash drive device that plugs into USB port and stores data bits as trapped electrons file named collection of data stored on a disk directory a list of the names of files stored on a disk subdirectory a list of the names of files that relate to a particular topic.
Central Processing Unit
central processing unit (CPU) coordinates all computer operations and performs arithmetic and logical operations on data fetching an instruction retrieving an instruction from main memory, register high-speed memory location inside the CPU multiprocessor a computer with more than one CPU.
Input/Output Devices
cursor a moving place marker that appears on the monitor
function keys special keyboard keys used to select a particular operation; operation selected depends on program being used
mouse an input device that moves its cursor on the computer screen to select an operation
icon a picture representing a computer operation
hard copy a printed version of information
Computer Networks
local area network(LAN) computers, printers, scanners, and storage devices connected by cables for intercommunication
digital subscriber line ( DSL connection ) or fiber-optics telephone line, the associated file server the computer in a network that controls access to a secondary storage device such as a hard disk
wide area network (WAN) a network such as the Internet that connects computers and LANs over a large geographic area
World Wide Web (WWW) a part of the Internet whose graphical user interfaces make associated network resources easily navigable graphical user
interface (GUI) pictures and menus displayed to allow user to select commands and data
modem a device that converts binary data into audio signals that can be transmitted between computers over telephone lines
DSL connection (digital subscriber line) a high-speed Internet connection that uses a telephone line and does not interfere with simultaneous voice communication on the same line
cable Internet access two-way highspeed transmission of Internet data through two of the hundreds of channels available over the coaxial cable that carries cable television signals
1.3 Computer Software
Operating System
operating system (OS) software that controls interaction of user and computer hardware and that manages allocation of computer resources
booting a computer loading the operating system from disk into memory
Application Software
application software used for a specific task such as word processing, accounting, or database management
install make an application available on a computer by copying it to the computer’s hard drive.
Computer Languages
machine language binary number codes understood by a specific CPU
assembly language mnemonic codes that correspond to machine language instructions
high-level language machine-independent programming language that combines algebraic expressions and English symbols
compiler software that translates a highlevel language program
into machine language source file file containing a program written in a high-level language; the input for a compiler syntax grammar rules of a programming language object file file of machine language instructions that is the output of a compiler linker software that combines object files and resolves crossreferences to create an executable machine language program
integrated development environment (IDE) software package combining a word processor, compiler, linker, loader, and tools for finding errors.
Executing a Program
input data the data values that are scanned by a program
program output the lines displayed by a program
1.4 The Software Development Method
Software Development Method
1. Specify the problem requirements.
2. Analyze the problem.
3. Design the algorithm to solve the problem.
4. Implement the algorithm.
5. Test and verify the completed program.
6. Maintain and update the program.
abstraction the process of modeling a problem by extracting the essential variables and their relationships algorithm a list of steps for solving a problem top-down design breaking a problem into its major subproblems and then solving the subproblems stepwise refinement development of a detailed list of steps to solve a particular step in the original algorithm desk checking the step-by-step simulation of the computer execution of an algorithm.
1.5 Applying the Software Development Method
CASE STUDY Converting Miles to Kilometers
PROBLEM
Your summer surveying job requires you to study some maps that give distances in
kilometers and some that use miles. You and your coworkers prefer to deal in metric measurements. Write a program that performs the necessary conversion.
ANALYSIS
The first step in solving this problem is to determine what you are asked to do. You
must convert from one system of measurement to another, but are you supposed to
convert from kilometers to miles, or vice versa? The problem states that you prefer
to deal in metric measurements, so you must convert distance measurements in miles
to kilometers. Therefore, the problem input is distance in miles and the problem
output is distance in kilometers . To write the program, you need to know the relationship
between miles and kilometers. Consulting a metric table shows that one mile
equals 1.609 kilometers.
The data requirements and relevant formulas are listed below. miles identifies
the memory cell that will contain the problem input and kms identifies the memory
cell that will contain the program result, or the problem output.
DATA REQUIREMENTS
Problem Input
miles /* the distance in miles*/
Problem Output
kms /* the distance in kilometers */
Relevant Formula
1 mile = 1.609 kilometers
DESIGN
Next, formulate the algorithm that solves the problem. Begin by listing the three
major steps, or subproblems, of the algorithm.
ALGORITHM
1. Get the distance in miles.
2. Convert the distance to kilometers.
3. Display the distance in kilometers.
Now decide whether any steps of the algorithm need further refinement or whether
they are perfectly clear as stated. Step 1 (getting the data) and step 3 (displaying a
value) are basic steps and require no further refinement. Step 2 is fairly straightforward,
but some detail might help:
Step 2 Refinement
2.1 The distance in kilometers is 1.609 times the distance in miles.
We list the complete algorithm with refinements below to show you how it all
fits together. The algorithm resembles an outline for a term paper. The refinement
of step 2 is numbered as step 2.1 and is indented under step 2.
ALGORITHM WITH REFINEMENTS
1. Get the distance in miles.
2. Convert the distance to kilometers.
2.1 The distance in kilometers is 1.609 times the distance in miles.
3. Display the distance in kilometers.
Let’s desk check the algorithm before going further. If step 1 gets a distance
of 10.0 miles, step 2.1 would convert it to 1.609 _ 10.00 or 16.09 kilometers. This
correct result would be displayed by step 3.
FIGURE 1.13 Miles-to-Kilometers Conversion Program
1. /*
2. * Converts distance in miles to kilometers.
3. */
4. #include /* printf, scanf definitions */
5. #define KMS_PER_MILE 1.609 /* conversion constant */
6.
7. int
8. main(void)
9. {
10. double miles, /* input - distance in miles. */
11. kms; /* output - distance in kilometers */
12.
13. /* Get the distance in miles. */
14. printf(“Enter the distance in miles> ”);
15. scanf(“%lf”, &miles);
16.
17. /* Convert the distance to kilometers. */
18. kms = KMS_PER_MILE * miles;
19.
20. /* Display the distance in kilometers. */
21. printf(“That equals %f kilometers.\n”, kms);
22.
23. return (0);
24. }
Sample Run
Enter the distance in miles> 10.00
That equals 16.090000 kilometers.
1.6 Professional Ethics for Computer Programmers
Privacy and Misuse of Data
computer theft (computer fraud) Illegally obtaining money by falsifying information in a computer database
Computer Hacking
virus Code attached to another program that spreads through a computer’s disk memory, disrupting the computer or erasing information
worm A virus that can disrupt a network by replicating itself on other network computers
Plagiarism and Software Piracy
software piracy Violating copyright agreements by illegally copying software for use in another computer
Misuse of a Computer Resource
Computer system access privileges or user account codes are private property.
These privileges are usually granted for a specific purpose—for example, for work to
be done in a particular course or for work to be done during the time you are a student
at your university. The privilege should be protected; it should not be loaned to
or shared with anyone else and should not be used for any purpose for which it was
not intended. When you leave the institution, this privilege is normally terminated
and any accounts associated with the privilege will be closed.
Computers, computer programs, data, and access (account) codes are like any
other property. If they belong to someone else and you are not explicitly given permission
to use them, then do not use them. If you are granted a use privilege for a
specific purpose, do not abuse the privilege or it will be taken away.
Legal issues aside, it is important that we apply the same principles of right and
wrong to computerized property and access rights as to all other property rights and
privileges. If you are not sure about the propriety of something you want to do, ask
first. As students and professionals in computing, we set an example for others. If
we set a bad example, others are sure to follow.
Langganan:
Postingan (Atom)