Rabu, 05 November 2008

tutorial microsoft access 2003 in english

9/12/06 1
Microsoft Access Tutorial: Advanced
Part 1: Create Database
1. Start MS Access
From the Start menu click on
> Programs
> Microsoft Office
> Microsoft
Access 2003
2. Note the Getting Started task pane on
the right side of your screen.
3. Click on Create a new file.
4. The New File task pane will appear. Under New, click on Blank
Database.
5. Name the database contact_management and choose Desktop as the location. Click the
Create button.
A. Create Table in Design View
1. The contact_management : Database window
opens. Double click the Create table in design
view item. The Table1 : Table opens.
2. Begin entering field names starting with Call_ID.
Click in the Data Type box and from the pull down
menu select AutoNumber.
3. Click the Primary Key button on the Table Design toolbar. Each table MUST have a Primary
Key.
4. A Foreign Key field must be included to establish a relationship. A foreign key field is a
primary key taken from a foreign table (for example, the customer_ID field from the
Customers table would establish the relationship between the Customers table and the Calls
table). Give it a Number Data Type.
5. Continue adding field names from your preliminary field list until all are added.
6. Click the Save button. The Save As window opens. Name the table Calls. Click the OK button.
You have created the table structure for the Calls table from scratch. Let’s take a look.
9/12/06 2
7. From the Table Design toolbar, select the Datasheet View icon. The table datasheet
window opens. Check your list of fields for accuracy.
8. Close the table by clicking the X in the upper right corner.
9. You now see the contact_management : Database window. Now you will create tables by
importing data from a Microsoft Excel spreadsheet.
B. Importing Data
1. Go to File > Get External Data > Import. Browse to the Microsoft Excel file provided. Under
the Files of type drop down box, select Microsoft Excel (*.xls) in order to see the file. Highlight
the file name (e.g. Contacts.xls) and click the Import button.
2. The Import Spreadsheet Wizard window will open. Both worksheets are listed. You will have
to import each worksheet individually. Select the Customers worksheet and click the Next
button.
3. Check the box for First Row Contains Column Headings. Click Next. Choose the radio
button for saving In a New Table. Click Next.
4. You can specify information about each of the fields you are importing and modify field
information in the ‘Field Options’ area.
5. Highlight the ID column and check
the box Do not import field (Skip)
which will allow Access to create an
auto-number primary key. Click Next.
6. Click the radio button Let Access add
primary key. Click Next.
7. Name the table Customers and click
Finish. The wizard will confirm the
import pathway, click OK.
8. Open the Customers table in Design View and rename the primary key Customer_ID
9. Repeat steps 1-8 for other table(s) (for example, the Employees table with a primary key
Employee_ID).
10. Click on Datasheet View to view your data and table. Now you’ve created three tables, one
from scratch and two by importing.
Part 2: Implement Relationships
1. After all the tables are created, relationships need to be implemented.
9/12/06 3
2. From Tools on the menu, select the Relationships menu item.
3. The Relationships window opens. From Relationships on the menu, choose Show Table.
4. Select all tables from the Show Table window. To select all, shift click on the first entry and
then click on the last entry in the list. Click the Add button. Then click the Close button. The
tables are displayed in the Relationships window. Resize the tables so you can see all fields.
5. Select the Customer_ID (primary key) from the Customers table. Click and drag to the
Customer_ID field (foreign key)
in the Calls table. You have
created a relationship between the
2 tables by linking the primary key
in one to a foreign key in the other.
6. Select the Enforce Referential
Integrity check box. Click Create.
Referential Integrity means
records must exist in one table
because matching records
depend on them in some other
table.
7. Repeat these steps for all
relationships.
8. If it is necessary to edit a
relationship, double click on the
Relationship arrow and the
Edit Relationships window will
open.
9. Close the Relationships window.
Part 3: Creating Forms and Modifying Queries and Reports
A. Creating and Modifying Forms
1. Creating Forms
Forms allow you to enter records into your tables.
· Choose the Forms button from the left hand
column.
· Double click on Create form by using wizard.
One customer, many calls.
One employee, many calls,
many customers.
9/12/06 4
· Select Table: Calls from the Tables/Queries dropdown menu.
· Choose the >> button to select all the fields. Click Next.
· Select the Layout for the form. If you click on each one, a preview is displayed. Choose
Columnar. Click Next.
· Select Style: Standard. Click Next.
· Click Next again and name the form Calls Entry Form.
· Click Finish, form will display.
2. Modifying Forms
Combo Box: Typing in Values to Present a Pick List of Subjects
· In Design View, you can add radio buttons, pull down menus and input masks.
· Notice the Toolbox. Be sure the wizard icon is selected.
· If it is not displayed, click on the Toolbox icon on the toolbar.
· The Toolbox contains options that allow you to change the way data is entered. If you prefer
data entry to be by selection rather than typing, you must create a Combo Box for that field.
· To create a combo box, click on the Combo Box icon in the Toolbox.
· Click once in an open area inside the form. The Combo
Box Wizard will open. Select the radio button “I will
type in the values that I want.” Click Next.
· Click Next. Type in three values: Request, Complaint,
Compliment. Click Next.
· Choose the radio button “Store that value in this field”
and select call_subject. Click Next. Type in ‘Subject’ as
the field label for the Combo Box. Click Finish.
9/12/06 5
· The new Combo Box and Label will display on your form.
· To replace, select the old field label and field name (the actual name of the field in the table)
and hit Delete. Highlight the new Combo Box and Label and drag to original location. To
adjust position, click and drag.
Combo Box: Values from Table Lists Customer’s Name Instead of ID#
· To create a combo box, click on the Combo Box icon in the Toolbox.
· Click once in an open area inside the form. The Combo Box Wizard will open. Select the
radio button “I want the combo box to look up the values in a table or query.” Click Next.
· Notice that the radio button for Tables is selected. Highlight Table: Customers. Click Next.
· Sort by NameLast_cust
· Move over NameLast_cust and NameFirst_cust. Click Next.
· Make sure the Hide Key Column box is checked. Click Next.
· Select “Store that value in this field” and choose Customer_ID. Click Next.
· Label the combo box Customer. Click Finish. Replace old Customer_ID label and entry
box with new Customer combo box.
· Follow the same steps to replace the Employee_ID label and entry box with a new
Employee combo box.
· You will need to change the tab order. Choose View > Tab Order. Follow the instructions.
· Go to Form View to see the changes.
Input Mask
· Input masks (field template) can be used to
format data and provide some control over what
values can be entered. This helps enforce data
integrity.
· Right click on Call Date and go to Properties.
· Click the Data tab. Place your cursor in the
Input Mask row, then click on the ellipses (…).
The Input Mask Wizard will open. Highlight
the Data Look desired (for example, Short
Date). To see how the Input Mask looks, click
in the Try It box. Click Next.
9/12/06 6
· The Input Mask Wizard will allow you to substitute a placeholder character from a
dropdown list, if desired. Click Next. Click Finish.
3. Adding Records Using Forms
· Use the form to enter 3 calls. This will allow us to test the referential integrity of the
database later in the class.
B. Modifying Queries and Reports
1. Modifying Queries
Creating queries was covered in the MS
Access Basic class. The Basics handout has
more detailed instructions.
· Choose the Queries button from the left
hand column.
· Double click on Create query by using wizard and create a calls query by using all fields
from all three tables.
· In Design View, you can add or delete
fields from the query by dragging and
dropping. Field will be added in front
of cursor position.
· If you include a field but decide later
not to show it, just uncheck the Show
checkbox.
· You can enter your search Criteria in
the Criteria textbox of the appropriate
column. Or, you can enter a search
criteria prompt in brackets, such as
[Enter Last Name:]. Save query as
Last Name Query.
· Be aware that MS Access provides an expression builder to help with complicated queries.
Right click in the criteria column and choose Build to use the Expression Builder. For
example, to query calls made today, enter =Date( ). Look for examples in Help: Examples
of Filter Criteria
2. Modifying Reports
Reports were covered in the MS Access Basics class; refer to the handout for instructions on
how to create.
9/12/06 7
· Choose the Reports button from the left hand
column.
· Double click on Create report by using
wizard and create a report of your
choice.
· In Design View, you can modify title,
labels, and footers. Notice there are five
areas:
o Report Header
o Page Header
o Detail
o Page Footer
o Report Footer
· Report Header provides the title of the
report. To change the title, click within the text box and modify with the keyboard.
· Page Header lists the field labels. Click within the text box to modify field name. To
reposition the label, select it and then use arrow keys to adjust.
o Note that when you adjust label placement in Page Header, you need to also match
the adjustment in Detail.
· Detail controls the size and spacing of the fields in which data are displayed. To modify
position or width, use the same procedures mentioned in Page Header bullet.
· Footers are used to place information at the bottom of the page or report such as page
number, dates, and sums. For example, =Now( ) inserts the current date.
C. Setting Up Functions with Queries and Reports to Create a Count Query and Report
1. Create the Function Column in a Query
· Choose the Queries button from the left hand column
· Double click on Create query by using
wizard and create a “count” query
9/12/06 8
· Choose Table: Customers
· Select the first eight fields. Click Next.
· Click Next again. Name it Count Query.
Click Finish.
· Go to Design View
· Click the Totals icon on the toolbar
· Select Insert > Column
· In the new column, choose Customer_ID
from the pull down menu
· Change the Total row to Count by
selecting from the pull-down menu.
· Right click anywhere on the new column and choose Properties
· On Caption line type Count. Close Field Properties window.
· Click to run the query
· Each row will be counted as 1 in the Count column. Save changes. Close the Count Query.
2. Run the Function in a Report
· Choose the Reports button from the left hand column
· Click on Create report by using wizard
· Choose Query: Count Query. Select all fields. Click Next.
· Choose grouping, if needed. Click Next.
· Sort by NameLast_cust. Click Next.
· Choose Landscape. Click Next.
· Choose Corporate. Click Next.
· Name it Count Report. Click Finish.
9/12/06 9
· Go to Design View.
· Drag down the line below Report Footer
· Locate the Toolbox
· Click once on Textbox
· Place mouse in expanded Report Footer area. Click once.
· Rename the label by typing Count over it
· Type the function over the word Unbound
· =Sum(CountOfCustomer_ID)
· Click on Layout View
Part 4: Test Your Database
1. In the contact_management : Database window, double click on a table (for example, the
Employees table).
2. To test referential integrity, attempt to delete a record. Highlight a record by clicking on the
selected row. Either right click on the row and choose Delete Record, or use the Delete Record
icon on the top tool bar. You should not be allowed to delete because of referential integrity.
Part 5: Conclusion
1. With What You Know Now, You Can:
· Design and create simple databases using MS Access
· Design, create and modify MS Access forms, queries and reports.
2. Assignment – doing this takes practice!
· Design and create a database that you can use at work or home.
· Design, create and modify MS Access forms, queries and reports and check to be sure that
the results are accurate based on the data you put into your database.
5. Consultations Available
· Complex databases require the expertise of a professional database designer. UUHSC Data
Resource Center also provides consultations. Please see their website:
http://uuhsc.utah.edu/drc/summary.htm
· If you need assistance determining the level of expertise you need for your database, you
may set up a consultation with any of the course instructors.
· Call or email us if you have any questions.

seputar pemprograman bahasa c

Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
1
Welcome to Overview TURBO C
Pengenalan C
􀂾 Unsur-unsur bahasa C
􀂾 Deklarasi variabel & Type Data
􀂾 Statement dalam C
􀂾 Bentuk umum dari program C
􀂾 Tanda / Operator Aritmatik
􀂾 Menampilkan Hasil / Output Terformat
􀂾 Batch Mode, Interactive Mode, dan File-file Data
􀂾 Kesalahan-kesalahan Umum dalam Program C
Sejarah Singkat C
Akar dari bahasa C adalah dari bahasa BCPL yang
dikembangkan oleh Martin Richard pada tahun 1967. Bahasa
Ini memberikan ide kepada Ken Thompson yang kemudian
mengembangkan bahasa yang disebut dengan B pada tahun 1970.
Perkembangan selanjutnya dari bahasa B adalah bahasa C oleh
Dennis Richie sekitar 1970-an di Bell Telephone
Laboratories Inc. Bahasa C pertama kali digunakan di
komputer Digital Equipment Coorporation PDP-11 yang
menggunakan sistem operasi UNIX.
C adalah bahasa yang standar, artinya suatu program yang
ditulis dengan versi bahasa C tertentu akan dapat
dikompilasi dengan versi bahasa C yang lain dengan sedikit
modifikasi.
Unsur-unsur Bahasa C
Struktur dari program C merupakan kumpulan dari sebuah atau
lebih fungsi-fungsi. Fungsi pertama yang harus ada di
program C sudah ditentukan namanya yaitu bernama main ().
Suatu fungsi di program C dibuka dengan kurung kurawal buka
({) dan ditutup dengan kurung kurawal tutup (}). Di antara
kurung kurawal dapat dituliskan statemen-statemen program
C.
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
2
Struktur Program C
Preprocessor directive
main()
{
statemen-statemen; Fungsi utama
}
Fungsi_fungsi_lain()
{
statemen-statemen; Fungsi fungsi lain yang ditullis pemrogram komputer
}
Contoh program C yang sederhana
Berikut ini adalah suatu program C sederhana yang
strukturnya mengikuti struktur di atas :
/* Program C yang sederhana*/
#include
main()
{
float Celcius, Fahrenheit;
printf(“Masukkan Nilai Celcius ?”);
scanf(“%f, &Celcius);
Fahrenheit=Celcius*1.8+32; /*menghitung konversi*/
printf(“%f celcius adalah %f fahrenheit \n”, Celcius, Fahrenheit);
}
Jika program ini dijalankan akan didapatkan hasil :
Masukkan nilai celcius? 10
10.000000 celcius adalah 50.000000 fahrenheit
Deklarasi Variabel
Variabel adalah suatu pengenal yang digunakan untuk
menyimpan suatu nilai dan nilai dari variabel dapat
berubah-ubah selama proses dari program.
Deklarasi Variabel dapat dilakukan dengan menggunakan katakata
kunci seperti
int,float,double,char,long,register,short,signed dan
unsigned.
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
3
Berikut ini adalah beberapa contoh pendeklarasian variabelvariabel
:
int x, y /*mendeklarasikan variabel x dan y tipe integer*/
float a,b /*mendeklarasikan variabel a dan b tipe floating point*/
char huruf /*mendeklarasikan variabel huruf tipe karakter*/
double x /*mendeklarasikan variabel x tipe pecahan ketepatan ganda*/
long int x /*mendeklarasikan variabel x tipe numerik panjang*/
register x /*mendeklarasikan variabel x yang nilainya disimpan di register*/
Tipe Data
Tipe data dalam program C menyediakan lima macam tipe data
dasar, yaitu tipe data integer (nilai numerik bulat yang
dideklarasikan int), floating point (nilai numerik pecahan
ketepatan tunggal yang dideklarasikan dengan float),
double-precision (nilai numerik pecahan ketepatan ganda
yang dideklarasikan dengan double), karakter
(dideklarasikan dengan char), dan kosong (dideklarasikan
dengan void).
Tabel Tipe-tipe Data Dasar
Jangkauan Nilai
Tipe Lebar Dari Sampai dengan
int 16 bit -32768 32767
signed int
short int
signed short
int
unsigned int 16 bit 0 65535
unsigned
short int
long int 32 bit -2147483648 2147483649
signed long
int
unsigned long
int 32 bit 0 4294967296
float 32 bit 3.4E-38 3.4E+38
double 64 bit 1.7E-308 1.7E+308
long double 80 bit 3.4E-4932 1.1E+4932
char 8 bit -128 127
signed char
unsigned char 8 bit 0 255
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
4
Statemen Dalam C
Suatu statemen adalah pernyataan yang menyebabkan suatu
tindakan akan dilakukan oleh komputer. Tindakan tersebut
misalnya adalah tindakan untuk menghitung, menampilkan
hasil, menerima input fan lain-lain. Suatu statemen di
bahasa C ditulis dengan diakhiri oleh titik koma (;).
Statemen dapat berupa statemen kosong,statemen
ungkapan,statemen kendali dan statemen jamak.
Macam-macam Statemen
􀂋 Statemen Kosong
Disebut juga empty statement atau null statement,
adalah statemen yang hanya terdiri dari pengakhir
titik koma saja. Artinya, tidak ada tindakan yang akan
dilakukan.
􀂋 Statemen Ungkapan / Expression Statement
Merupakan statemen yang dibentuk dari suatu ungkapan
yang diakhiri dengan tanda titik koma (;).
Contoh :
fahrnheit = celcius*1.8+32;
++x;
dan sebagainya
Statemen Kendali / Control Statement
Merupakan statemen yang fungsinya mengendalikan proses
dari program. Statemen ini dibentuk dengan diawali
kata-kata kunci if,switch,for,do-while,goto,break,dan
continue.
Contoh :
if(N<0) printf(“Nilai N tidak boleh negatif!!\n”);
Statemen Jamak / Compound Statement
Adalah statemen yang terdiri dari gabungan beberapa
statemen tunggal yang ditulis berada di antara tanda
kurung kurawal (“{“ dan “}”)
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
5
Contoh :
if(D==0)
{
x1=-B/(2*A);
printf(“Dua Akar Real Kemabar:\n”);
printf(“X1=X2=%f \n”,X1);
else if (D>0)
{
x1=(-B+sqrt(D))/(2*A);
x2=(-B-sqrt(D))/(2*A);
printf(“Dua Akar real berlainan:/n”);
printf(“X1 = %f \n”,X1};
printf(“X2 = %f \n”,X2};
}
Operator Aritmatika
Bahasa C menyediakan sejumlah operator aritmatika seperti
pada tabel di samping.
Operator Maksud
* perkalian
/ pembagian
% pambagian modulus (sisa bagi)
+ pertambahan
- pengurangan
Operator * dan /
Operator * digunakan untuk perkalian dan / untuk pembagian.
Contoh :
#include
main()
{
int X,Y;
float Z;
X = 7;
Y = 3;
Z=X/Y;
Printf(“Nilai Z=%f”,Z);
}
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
6
Operator Modulus (%)
Operator ini hanya digunakan untuk nilai-nilai integer
saja, tidak dapat digunakan untuk operasi nilai pecahan
(float,double, ayau long double). Operator ini akan
menghasilkan sisa dari pembagian dari dua buah nilai
integer.
Contoh :
#include
Main()
{
int X,Y,Z;
X = 7;
Y = 3;
Z=X%Y;
printf(“Nilai Z=%d\n”,Z);
}
Menampilkan Output Terformat
Jika fungsi outchar() dan puts() menampilkan hasil tanpa
dapat diatur bentuknya, karena tidak menggunakan kode
format, maka fungsi printf() dapat digunakan untuk
memformat bentuk dari tampilannya. Fungsi printf() dapat
digunakan untuk menampilkan hasil yang diatur formatnya,
karena fungsi ini menggunakan kode-kode format.
Tabel kode-kode format untuk fungsi printf()
Kode Format Kegunaan
%c Menampilkan sebuah karakter
%s Menampilkan nilai string
%d Menampilkan nilai desimal integer
%i Menampilkan nilai desimal integer
%u
Menampilkan nilai desimal integer tak
bertanda
%x Menampilkan nilai heksadesimal integer
%o Menampilkan nilai oktal integer
%f Menampilkan nilai pecahan
%e
Menampilkan nilai pecahan dalam notasi
saintifik
%g
Sebagai pengganti %f atau %e tergantung
yang terpendek
%p
Menampilkan suatu alamat memori untuk
pointer
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
7
Kode-kode format tersebut semuanya ditulis dengan huruf
kecil dan tidak benar jika ditulis dengan huruf besar.
Misalnya : kode format “%C” merupakan bentuk yang salah.
Batch Mode, Interactive Mode dan Data-data file
• Interactive mode - pemakai saling berhubungan dengan
program dan tipe data ketika program sedang
dijalankan.
• Batch mode - program meneliti data nya dari suatu file
data yang telah disipakan terlebih dahulu sebagai
ganti saling berinteraksi dengan pemakai nya .
Contoh Batch Mode dalam Mengkonversi dari Mil ke Kilometer
#include
#define KMS_PER_MILE 1.609
Int
main(void)
{
double miles,kms;
scanf(“%if”,&miles);
printf(“Jarak dalam Mil adalah : %.2f.\n”,miles);
kms = KMS_PER_MILE*miles;
printf(“Sama dengan %.2f Kilometer.\n”, kms);
return (0);
}
Input Redirection
􀂄 Contoh di atas menunjukkan penulisan kembali program
konversi dari mil ke kilometer dalam bentuk batch.
􀂄 Kita mengasumsikan di sini bahwa input standard
dihubungkan dengan suatu data batch sebagai ganti
keyboard.
􀂄 Dalam kebanyakan sistem, asosiasi ini dapat terpenuhi
secara relatif dengan mudah melalui input/output
redirection yang menggunakan perintah sistem operasi.
􀂄 Sebagai contoh, dalam sistem operasi UNIX dan MS.DOS,
kita dapat menginstruksikan program kita untuk
mengambil file dari mydata dengan menempatkan simbol
yang menyebabkan
compile kita dan program yang terhubung untuk
dieksekusi. Jika baris perintah digunakan secara
normal metric untuk menjalankan program ini, baris
perintah yang baru akan menjadi :
metric Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
8
Program Style Echo Prints vs. Prompts
Dalam contoh program sebelumnya, pernyataan
scanf(“%1f”,miles);
didapat/kan suatu nilai mil dari baris pertama dalam file.
Karena input program datang dari suatu file data,
tidak usah mendahului statemen ini dengan suatu prompt
pesan. Sebagai ganti, kita mengikuti panggilan ke
scanf dengan statemen
printf(“Jarak dalam Mil adalah : %.2f.\n”,miles);
Statemen echo prints atau tampilan nilai hanya
tersimpan dalam mil dan menyediakan suatu rekaman data
yang digerakkan oleh program.
Tanpa itu, tidak akan mudah mengetahui nilai scanf
yang diperoleh dari mil.
Kapan pun kita mengkonversi suatu program interaktif
ke suatu program batch,pastikan kita mengganti masingmasing
prompt dengan suatu echo prints setelah scanf.
Output Redirection
􀁺 Kita dapat juga mengalihkan output dari program ke
suatu file sebagai ganti layar. Kemudian kita dapat
mengirimkan file output ke printer untuk memperoleh
suatu salinan output program. Dalam UNIX atau MS DOS,
gunakan simbol >myoutput untuk mengarahkan kembali
output dari layar ke file myoutput. Dijalankan dengan
baris perintah sebagai berikut:
metric>myoutput
yang akan menjalankan compule dan kode yang terhubung
dengan program metric, mengambil input program dari
keyboard dan menulis program output ke file myoutput.
Akan tetapi, interaksi dengan program yang berjalan
akan sulit karena semua program output termasuk semua
pesan prompt, akan dikirim ke file output. Akan lebih
baik menggunakan baris perintah :
metric myoutput
yang mengambil input program dari file mydata dan
mengirim program output ke output file ke file myoutput.
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
9
Program Konversi Mil ke Km dengan File Bernama
#include
#define KMS_PER_MILE 1.609
Int
main(void)
{
double miles,kms;
FILE *inp,*outp;
inp=fopen(“b:distance.dat”, “r”);
outp=fopen (“b:distance.out”, “w”);
fscanf(inp,“%if”,&miles);
fprintf(outp, “Jarak dalam Mil adalah : %.2f.\n”,miles);
kms = KMS_PER_MILE*miles;
fprintf(outp,“Sama dengan %.2f Kilometer.\n”, kms);
fclose(inp);
fclose(outp);
return (0);
}
Kontrol Program File Input dan Output
Sebagai alternatif untuk input output redirection, C
mengijinkan program untuk menamakan secara eksplisit sebuah
file dari file yang akan diambil inputnya dan file yang
akan dikirimi output. Contoh di atas menampilkan sebuah
versi konversi jarak yang mengambil input dari data yang
bernama b:distance.dat dan mengirim hasilnya ke dalam file
yang bernama b:distance.out
Sebuah program yang memanipulasi spesifik file harus
terlebih dahulu mendeklarasikan variabel file pointer yang
digunakan untuk menyimpan informasi penting untuk
mengijinkan akses ke file. Dalam contoh sebelumnya,
pernyataan :
FILE *inp, *outp;
mendeklarasikan bahwa variabel file pointer inp dan
outp akan memegang informasi pengijinan akses ke input
progtam dan file output. Sistem operasi harus mempersiapkan
file untuk input atau output sebelum mengijinkan akses.
Persiapan ini adalah tujuan dari fungsi fopen dalam
pernyataan di bawah ini :
Bahan ajar Pemtrograman Terstruktur
http://dwi.its-sby.edu/PemrogramanTerstuktur/Materi Pemrograman Terstruktur Bab-2.pdf
http://dwi.its-sby.edu/the_untold_stories/
10
Inp=fopen(“b:distance.dat”,”r”)
outp=fopen (“b:distance.out”,”w”);
Tugas pertama pernyataan opens (mempersiapkan akses) file
b:distance.dat sebagai sumber daru input program dan
menyediakan nilai akses penting dalam variabel file pointer
inp. “r” dalam perintah pertama fopen mengindikasikan bahwa
kita ingin membaca atau men-scan data dari file yang
terbuka karena perintah tugas kedua pernyataan meliputi
“w”, mengindikasikan keinginan kita untuk menulis ke dalam
b:distance.out,outp adalah diinisialkan sebagai output file
pointer.
Dua pernyataan selanjutnya mendemostrasikan penggunaan dari
fungsi fscanf dan fprintf mengequivalenkan kedua fungsi
tersebut dengan fungsi scanf dan printf.
fscanf(inp, “%1f”,&miles);
Fprintf(outp, “Jarak dalam mil adalah : %.2f\n”, miles);
Kesalahan-kesalahan Umum dalam C
• Kesalahan Pemula
• Kesalahan Penggunaan
• String Errors
• Kesalahan Input/Output

Turbo C Source code for Instant Insanity Game

/*

  What: Instant Insanity Game source in Turbo C. GPL(C)
=======================
Col1 Col4*4
3 3 3 3 Row1
405 405 405 405 Row2
1 1 1 1 Row3
2 2 2 2 Row4
=======================
c:\mosh\games>tcc -If:\tcc30\include -Lf:\tcc30\lib instanti.cpp
*/

#include "cubeinit.cpp"

int cube[4][6]; /* four cubes with six faces */

enum { W,R,G,B } virtual_colors;
static int screen_colors[5] = {WHITE, RED,GREEN,BLUE,YELLOW};

void setpuzzle(int p){
int i,k;
static int puzzle[1][4][6] = {
{{W,W,W,G,R,B},{G,W,G,R,B,R},{W,W,B,R,G,B},{B,W,G,G,B,R}},
};
for(i=0;i<6;i++)
for(k=0;k<4;k++)
cube[k][i]=puzzle[p%(sizeof(puzzle)/sizeof(cube))][k][i];
}

int sameface(int cube[4][6]){ /* return 0, if all sides have different colors */
int i,j,k,dup=0;
for(i=0;i<4;i++)
for(j=i+1;j<4;j++)
for(k=0;k<4;k++)
dup += (cube[i][k]==cube[j][k]);
return dup;
}

void putcharc(int row, int kol, int c){
int t;
textcolor(screen_colors[c]);
mvaddch(row,kol,'0'+c);
}

void drawcubes(int cc){
int i;
clrscr();
for(i=0;i<4;i++){
putcharc(4+i*4 ,1,cube[i][3]);
putcharc(4+i*4 ,2,cube[i][0]);
putcharc(4+i*4-1 ,3,cube[i][4]);
putcharc(4+i*4+1 ,3,cube[i][5]);
putcharc(4+i*4 ,3,cube[i][1]);
putcharc(4+i*4 ,4,cube[i][2]);
if(i==cc)
putcharc(4+i*4,5,4);
}
}

void upcube(int cc){
int t=cube[cc][3];
cube[cc][3]=cube[cc][0]; cube[cc][0]=cube[cc][1];
cube[cc][1]=cube[cc][2]; cube[cc][2]=t;
}
void rocube(int cc){
int t=cube[cc][3];
cube[cc][3]=cube[cc][4]; cube[cc][4]=cube[cc][1];
cube[cc][1]=cube[cc][5]; cube[cc][5]=t;
}
void main(){
chtype ch=' ';
int cc=0; /* current cube to operate on */
initscr(); cbreak(); noecho(); refresh();
setpuzzle(0);
drawcubes(cc);

do{
textcolor(FGCOL); mvaddch(24,0,':');
clrtoeol(); mvaddch(24,1,ch); ch = mvgetch(24,2); clrtoeol();
amessage("ok.");
switch(ch){
case 'L': if(--cc<0)cc=3; break;
case 'R': if(++cc>3)cc=0; break;
case 'l': upcube(cc); break;
case 'r': upcube(cc); upcube(cc); upcube(cc); break;
case 'u': rocube(cc); break;
case 'd': rocube(cc); rocube(cc); rocube(cc); break;
case '1': cc=0; break;
case '2': cc=1; break;
case '3': cc=2; break;
case '4': cc=3; break;
}
if( sameface(cube) == 0 ){
printf("Done\n");
}
drawcubes(cc);
}while(ch!='q');
clear(); refresh();
endwin();
}

Selasa, 04 November 2008

source code c++ pengurangan & penjumlahan matrik

#include

void main()
{
int A[2][2],B[2][2],C[2][2],D[2][2];
int i,j;

// Matiks A
printf(”Masukan matriks A\n”);
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
{printf(”input data matriks A[%i][%i]: “,i+1,j+1);
fflush(stdin);scanf(”%i”,&A[i][j]);
}
}
printf(”————————————————\n”);

// Matiks B
printf(”Masukan matriks B\n”);
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
{printf(”input data matriks B[%i][%i]:”,i+1,j+1);
fflush(stdin);scanf(”%i”,&B[i][j]);
}
}
printf(”————————————————\n”);

// Proses Penjumlahan Matriks (Matriks C)
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
{C[i][j]=A[i][j]+B[i][j];
}
}
printf(”Maka Penjumlahan Matrik: \n”);
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
printf(”%6i”,C[i][j]);printf(”\n”);
}
printf(”\n\n”);
printf(”————————————————\n”);

// Proses Pengurangan Matriks (Matriks D)
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
{D[i][j]=A[i][j]-B[i][j];
}
}
printf(”Maka Pengurangan Matriks: \n”);
for(i=0;i<2;i++)
{for(j=0;j<2;j++)
printf(”%6i”,D[i][j]);printf(”\n”);
}
printf(”\n\n”);
}

source code pascal menghitung pangkat

program Bilangan_pangkat;
uses wincrt;
var
a,b,hasil,i :integer;
begin
ClrScr;
write(’ Nilai Pokok (a)= ‘);
readln(a);

write(’ Nilai Pangkat (b)= ‘);
readln(b);

hasil:=1;

for i:=1 to b do
begin
hasil:=hasil*a;
end;

writeln;
writeln(’ Maka, Hasil kali a sampai b= ‘,a,’ pangkat ‘,b);
write(’ = ‘);
writeln(hasil);
end.