Intan's Weblog

Bermain dengan Program C++

Posted on: October 21, 2010

Setelah tadi makan siang dengan cumi…dan sayur, kali ini aku coba share program C++ yang sederhana, smoga bermanfaat untuk para newbie programmer yang ingin mendalami bahasa C++.
cekidot gan….😀

Program ke-1 aku kasih nama first.cpp :
#include

int main()
{
printf(“This is output from my first program!\n”);
return 0;
}

trus aku compile deh via terminal ubuntu 10.04 (versi ubuntu yg aku punya saat ini loh..), nih…cara compile-nya :
pertama, kita masuk ke terminal dulu, klik menu Applications -> Accessories -> Terminal
trus cari file first.cpp, kebetulan file first.cpp punya aku adanya di folder C+program yang ada di desktop, nah…tinggal ketik, dan penampakannya seperti ini gan…

compile first.cpp

compile via terminal ubuntu

next…, program ke-2, garfield.cpp :

#include

using namespace std;

struct item // a struct data type

{
int keep_data;
};

int main(void)

{
item John_cat, Joe_cat, Big_cat;

int garfield; // a normal variable

John_cat.keep_data = 10; // assigning values

Joe_cat.keep_data = 11;

Big_cat.keep_data = 12;

garfield = 13 ;

// displaying data

cout<<"Data value for John_cat is "<<John_cat.keep_data<<"\n";

cout<<"Data value for Joe_cat is "<<Joe_cat.keep_data <<"\n";

cout<<"Data value for Big_cat is "<<Big_cat.keep_data<<"\n";

cout<<"Data value for garfield is "<<garfield<<"\n";

cout<<"Press Enter key to quit\n";

// system("pause");

}

compile lagi via terminal ubuntu,
intan@intan-laptop:~/Desktop/C+program$ g++ garfield.cpp -o garfield
intan@intan-laptop:~/Desktop/C+program$ ./garfield

hasilnya:

Data value for John_cat is 10
Data value for Joe_cat is 11
Data value for Big_cat is 12
Data value for garfield is 13
Press Enter key to quit

(bersambung … )

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: