Laporan Akhir Lab TI PAA Pertemuan 1 Pengenalan Perancangan & Analisis Algoritma

Listing Program

#include<stdio.h>
#include<conio.h>
#define size 99
void sort (int a[],int siz)
                        {
                        int pass,hold,j;
                        for(pass=1;pass<=siz-1;pass++)
                        {
                                    for(j=0;j<=siz-2;j++){
                                                if(a[j+1]<a[j=2]){
                                                            hold = a[j+1];
                                                            a[j+1]=a[j+2];
                                                            a[j+2]=hold;
                                                }}}}
main()
{
            int x[size],i,uang,n,k,hasil[size];
            printf("PAA-ALGORITMA GREEDY\n");
            printf("\nMasukan berapa jenis koin : ");
            scanf("%d",&n);
            printf("\n\nMasukan Jenis Koin : \n");
            for(i=1;i<=n;i++)
                        {
                        printf("Koin ke %d : ",i);
                                    scanf("%d",&x[i]);
                        }
            sort(x,n);
            printf("\nKoin yang tersedia : \n");
            for(i=1;i<=n;i++)
                        {
                                    printf("%d",x[i]);
                                    printf("\n");
                        }
            printf("\n");
            printf("\nMasukan Nilai yang dipecah : ");
            scanf("%d",&uang);
            printf("\n");
            for(i=1;i<=n;i++)
                        {
                                    hasil[i]=uang/x[i];
                                    uang=uang%x[i];
                                    k=uang%x[i];
                        }
            for(i=1;i<=n;i++)
                        {
                                    printf("Koin %d",x[i]);
                                    printf("-an sebanyak : %d",hasil[i]);
                                    printf("\n\n");
                        }
            if(k!=0){
            printf("Tidak ada Solusi");
            }
            else{
            printf("Ada Solusi");
            }
           
            getch();
            return 0;

}

Logika Program

Pada pertemuaan kali ini saya akan membuat logika dar program yang saya buat. Disini saya menggunakan bahasa C++. Berikut adalah logikanya.
#include<stdio.h>
Dalam c++ jika kita menginginkan penggunaan input dan output, atau bisa diartikan sebagai standard library yang berfungsi untuk I/O  package maksudnya digunakan jika kita ingin pada program kita menggunakan fungsi standard input atau output bisa dikatakan seperti portable input/output package. Tanpa menggunakan library ini, kita tidak bisa menggunakan perintah-perintah input/output pada program kita.
#include<conio.h>
Pernyataan conio.h adalah library pada C yang digunakan untuk mengkoneksikan pernyataan clrscr() dengan program yang kita buat. Tanpa menggunakan library ini, kita tidak bisa menggunakan fungsi prototype seperti: gotoxy(), clrscr(), clreol(). Dan juga file header ini berfungsi untuk menampilkan hasil antarmuka kepada pengguna.
#define size 99
Library di atas berguna untuk menentukan size dari inputan banyak datanya adalah 99, artinya jika data lebih banyak dari 99, maka program akan berhenti mengeksekusi.
void sort (int a[],int siz)
Pernyataan diatas adalah main procedure (prosedur utama dalam program ini). Pada program ini, program utama berbentuk prosedur untuk mengurutkan data yang kita input, disini yang akan diurutkan adalah variable masukan dari int[] dan int.
{
Kurung kurawal pertama digunakan untuk memulai membuat program.

int pass,hold,j;
for(pass=1;pass<=siz-1;pass++){
for(j=0;j<=siz-2;j++){
if(a[j+1]<a[j+2]){
hold = a[j+1];
a[j+1]=a[j+2];
a[j+2]=hold;

Ini merupakan perulangan  pass dengan nilai awal 1, hingga pass  lebih kecil sama dengan siz lalu pass berulang secara increment . Iterasi i dengan nilai awal i=0, hingga i lebih kecil sama dengan variable siz-2 dan i berulang secara increment. Serta ada penyeleksian kondisi dimana jika  a indeks ke i+1 lebih kecil dari a indeks i+2, maka akan memberi nilai pada hold.
main()
Pernyataan di atas digunakan sebagai badan program. Fungsinya sama seperti public.static.void.main(String args[]) { pada bahasa pemrograman java.
int x[size],i,uang,n,k,hasil[size];
Pernyataan di atas digunakan untuk mendefinisikan variable yang akan digunakan dalam programnya. Tanda kurung siku [ ] menandakan variable tersebut bertipe array.
printf("\nMasukan berapa jenis koin : ");
Pernyataan printf di atas digunakan untuk mencetak tulisan yang ada diantara tanda kutip “ ”.                 \n digunakan untuk member jeda (enter) pada saat program dieksekusi.
scanf("%d", &n);
Pernyataan scanf digunakan untuk menyimpan angka yang kita input ketika program dieksekusi. Disini terdapat %d yang mengartikan data inputan akan ditampilkan dalam bentuk decimal, dan &n mempunyai arti data inputan akan disimpan sementara pada variable n.
printf("\n\nMasukan Jenis Koin : \n");
for (i=1;i<=n;i++){
printf("Koin ke %d : ",i);
scanf(" %d", &x[i]);

Pertama kita akan mencetak kalimat yg di dalam tanda kutip, lalu kita input jumlah koin yang diinginkan. Misalnya jenis koin yang kita input = 3. Maka untuk i sama dengan 1, i kurang dari sama dengan n, maka i akan bertambah 1. Maka selanjutnya akan menjalankan perintah menampilkan koin ke 1 lalu kita input angka begitupun seterusnya hingga koin ke 3.
sort(x,n);
printf("\nKoin yang tersedia (Rp): \n");

Setelah kita memasukkan jenis koin yang kita inginkan, maka program tersebut akan mencetak secara berurutan dari nominal terkecil hingga nominal terbesar, dan \n digunakan untuk memberi jeda atau enter.
for(i=1;i<=n;i++)
untuk I sam dengan 1, dan I kurang dari sama dengan n, maka I akan bertambah.
printf("%d",x[i]);
printf("\n");

Mencetak hasil dari angka atau jumlah koin yang kita inputkan tadi dan memberikan jeda(enter) untuk syntak berikutnya.
printf("\nMasukan Nilai yang dipecah : Rp ");
mencetak kalimat yang berada di dalam tanda kutip, lalu diberikan jeda untuk memproses syntak berikutnya.
scanf("%d", &uang);
printf("\n");

Digunakan untuk menyimpan angka yang kita input ketika program dieksekusi. %d yang mengartikan data inputan akan ditampilkan dalam bentuk decimal, dan &uang mengartikan data inputan akan disimpan sementara pada variable uang lalu memberikan jeda(enter) kepada syntak selanjutnya.
for(i=1;i<=1;i++) {
hasil[i]=uang/x[i];
uang=uang%x[i];
k=uang%x[i];  }

Pernyataan for di atas digunakan sebagai kondisi perulangan pada program, sedangkan pernyataan hasil[i]=uang/x[i]; digunakan sebegai rumus perhitungan untuk mendapatkan kombinasi koin apa saja yang digunakan untuk menukarkan koin yang ingin kita tukarkan dengan koin yang tersedia, lalu pernyataan uang=uang%x[i]; digunakan untuk menentukan berapa banyaknya kombinasi koin dalam pertukaran koinnya.

for(i=1;i<=1;i++)
untuk I sama dengan 1, I kurang dari sama dengan 1 maka I akan bertambah.
printf("hasil algoritma greedynya adalah : \n");
mencetak kalimat yang berada di dalam tanda kutip setelah itu membuat jeda(enter).
printf("koin %d", x[i]);
printf("-an sebanyak : %dkeping", hasil[i]);
printf("\n \n");

Untuk mencetak koi n yang kita inputkn sebelumnya untuk di pecah dengan hasil perhitungan dari rumus hasil[i]=uang/x[i]. Dan \n untuk memberikan jeda atau enter ke perintah selanjutnya.

if(k!=0){
printf("tidak ada solusi"); }
else{
printf("Ada solusi"); }

Jika k tidak sama dengan 0, maka pada layar akan muncul tulisan Tidak Ada Solusi namun jika k sama dengan 0 maka yang keluar adalah tulisan Ada Solusi.
getch();
Berguna unutk membaca sebuah karakter, bisa juga membaca tombol, getch() tidak akan menampilkan karakter dari tombol yang ditekan. Sebuah getch() bisa pula digunakan untuk menunggu sembarang tombol ditekan. Pada keadaan seperti ini, hasil dari fungsi ini tidak perlu diletakkan ke variable, atau dipascal dapat diartikan sebagai readln
return 0;
Angka 0 ini akan dikembalikan kepada sistem operasi. Nilai ini digunakan oleh sistem operasi untuk disimpan di variabel ERRORLEVEL pada MS DOS, dimana 0 artinya ‘sukses’.   

}

Kurung kurawal terakhir untuk mengakhiri program yang kita buat.



Output








Belum ada Komentar untuk "Laporan Akhir Lab TI PAA Pertemuan 1 Pengenalan Perancangan & Analisis Algoritma"

Posting Komentar

Electric Smart Cars - Rational Reasons and Results When Buying One There are many reasons for buying any electric smart car, hybrid electric or plugin hybrid electric vehicle. The soaring costs of gas is likely the biggest and most pressing issue when considering buying an electric car. The environment and the planet is another concern. Whatever the reason, buying any BEV, PHEV or green planet-friendly automobile instead of that fossil-fuel burning internal combustion engine car, we'll certainly have a positive effect on helping save the planet and save you money as well. In order to make a smart electric car buying decisions, it is important to understand what the different types of electric-powered vehicles, and how smart electric cars work. There are three types of electric assisted vehicle that utilize an electric motor of some kind. The battery electric vehicle (BEV) is as the name suggests-a battery powered vehicle. There is no other power source for the vehicle, no internal combustion engine (ICE) running on gasoline, and therefore the battery must be charged between uses, and will discharge during use until it runs out. At this point the vehicle can no longer run, so you'll need to be near a charging point before you run out of gas, I mean electric juice. Two types of hybrid electric vehicles offer the best of both the electric and the ICE vehicle worlds. The hybrid electric vehicle (HEV) uses an electric motor to either propel the car or to increase the power. Generally the result of this is to extend the distance that it can travel on a tank of fuel, giving the hybrid electric car better fuel economy. Lastly there is the plug-in hybrid electric vehicle (PHEV). This runs in a largely similar way to the HEV but with one major difference-the battery can be plugged into a charging point, in order to completely charge the battery to its maximum capacity. The HEV by comparison can only charge its battery with the current generated by its ICE, or through regenerative breaking (a process in which energy is reclaimed during breaking rather than lost). By fully charging the battery the use of electrical power can be prolonged, and the use of gasoline reduced, making the PHEV the more economical of the hybrid electric vehicles. The drive-train of a BEV is very simple-a battery powers the motor, which propels the electric vehicle. The hybrid electric vehicles will run an ICE and electric motor either in parallel or in series, with both the ICE and electric motor being able to move the electric or hybrid electric vehicle. A capacitor allows energy to be channeled back into the battery too, and in the case of the PHEV a separate charging circuit like that of the BEV is included to separately charge the hybrid electric vehicle. There are two types of battery that are used in BEV, PHEV and HEV cars. Nickel metal hydride batteries are an older technology, and one that suffers from battery degradation more quickly than others. Newer, lithium-ion batteries are far more efficient, as well as longer lasting in both electric and hybrid electric vehicles. They don't suffer from memory formation like nickel metal hydride batteries, and tend to be able to provide more power for the engine than the alternative. Older hybrid electric vehicles may still use lead-acid batteries, but these are generally now considered bad for the environment, and are no longer used. There are pros and cons to making the move to an electric or hybrid vehicle. They are cheaper to run than ICE cars and have good speed, and hybrid electric vehicles have good range too. But the BEV class can run generally for only up to 40-200 miles, leading to what is known as range anxiety. Hybrid electric vehicles overcome by using the ICE as well, giving vastly superior range. Another downside is that the batteries wear out and need replacing. This is an expensive part on the car, and on a BEV the battery failure means that the car will completely fail to run. A hybrid at least has its ICE on which to fall back. However, the overall running costs to the owner are far less than for a vehicle with an ICE. The electric or hybrid electric vehicle has less moving parts and so less chances of failure that needs repair. Fuel efficiency of a hybrid is hugely increased, saving money for every mile driven, and for a BEV is even less as electrical energy is cheaper than gas. One of the biggest benefits to these vehicles is to the planet. Our oil reserves are finite and dwindling, and their continued use in this way further pollutes the environment. Moving to electric or hybrid electric vehicles will drastically reduce the pollutants emitted, and will slow the rate at which our planet's natural resources are exhausted. As far as the economy is concerned, electric and hybrid vehicles could be very positive development. The production of large numbers of these vehicles would require the building or converting manufacturing factories, and the hiring of workers to staff the factories. Claims are often made that our economy is heavily reliant on oil, and that moving away from it would destroy us, but the truth is quite different. By embracing these technologies, our economy can shift its dependence from oil onto alternatives, just as our motoring needs do. An all-electric or hybrid vehicle may cost a little more to insure than a gas vehicle. Though a small saving is possible thanks to the improved risk profile of people who own electric vehicles, other costs are higher. However, repairing electric or hybrid vehicles currently costs more because there are fewer of these vehicles on the road, and because spare parts are less abundant. This increases repair costs, which insurance companies pass on to owners. Savings in running costs can help offset this. Options are varied when considering purchasing one of these cars, giving potential owners a good range of choice when it comes to the power, size and range of their vehicle. The following are currently available or soon to be released, highway ready environmentally-friendly cars. Full details are not available for some of those cars that are not yet on sale. The Nissan Leaf is an all electric car doing 100 miles per charge and up to 90 mph, and starting at $33,720. This is a modern looking car with a reasonable range, and a competitive pricing. The Tesla Roaster is also all-electric, with an incredible 245 miles per charge, 125 mph top speed, and costs starting at $101,500. This is a stunning looking car with an equally stunning performance-and a range like no other electric car. The Smart-ED all-electric model has a 98 mile maximum range, and a top speed of 60 mph. This small car will be perfect for city driving. Starting at $599 a month for a four year lease. Ford's own all electric car-the Ford Focus has yet to be released but is expected to have a range in excess of 100 miles per charge. This car will be available from late 2011, and looks to provide all of the high-tech options that people may want, in a very stylish exterior. Final price and other details have yet to be released. Chevrolet's Volt is a PHEV that is capable of speeds of 100 mph. Fuel economy depends on how often you charge the battery, with official figures released at 60 mpg using gas and electric combined. Prices start at $32,780, giving this a reasonable price tag along with good performance. Toyota's Prius is a PHEV that has an incredible range of 475 miles on a single tank of gas, when using combined gas and the electric motor. Unfortunately, since it won't be available till early 2012 there are no more details regarding performance and pricing. A full hybrid version of the Toyota Prius is also available, with a base price of $23,520. With a combined mileage of 50mpg and a top speed of 112 mph, it has enough power and efficiency for anyone. This is a tried and trusted hybrid car with a good reputation. Ford's Fusion has a hybrid version as well, with a starting price of $19,820. With a 700 mile range per full tank of fuel, and 41 mpg, it is powerful and sleek, and has the range to take you wherever you want to go. The Escalade hybrid from Cadillac is a luxury SUV, and so it's price tag is a little larger, at $74,135. Fuel efficiency is good for an SUV at up to 23 mpg and a range of up to 575 miles per tank. This SUV balances the needs of a larger family with the desire to be a little more environmentally friendly, and does so with incredible style.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel