IT Solution

Tuesday, 27 August 2013

Program c++ Struct

August 27, 2013 Posted by Bops No comments
Struktur Data (Semester 3)
Program Struct_Mobil
 Posted by: Muhammad Nazih

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void cetak(); //--soal 1c
typedef struct Mobil{ //--soal 1a
        string seri;
        string warna;
        float harga;
        Mobil(string s,string w,float h){               //--soal 1b
                seri=s;
                warna=w;
                harga=h;
                }
        Mobil(){
        }

}Honda,Toyota;
//variable global
Mobil data_mobil[3];

int main(){
        Honda h1("jazz","merah",500000000);
        Honda h2("Avanza","hitam",800000000);
        Toyota t1("City","putih",200000000);
        //memasukan data ke dalam array
        data_mobil[0]=h1;
        data_mobil[1]=h2;
        data_mobil[2]=t1;
        cetak();
        return 0;
}
void cetak(){
 cout<<setw(30)<<"|Seri:"<<setw(10)<<"|Warna"<<setw(10)<<"|harga:"<<setw(10)<<"|"<< endl;
 for(int i=0;i<3;i++){
 cout<<setw(10)<<data_mobil[i].seri<<setw(10)<<data_mobil[i].warna<<setw(10)<<data_mobil[i].harga<<endl;
 }
}
-- INSERT --

0 comments:

Post a comment

Terimakasih telah bergabung di blog saya.

Featured post

Game PC (BMW M3)