Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
498 B
1
Indexable
#include <stdio.h>

// Deklarasi class
class Car {
  public:
    char brand[50];
    char model[50];
    int year;
    void info() {
        printf("%s %s (%d)\n", brand, model, year);
    }
};

int main() {
    // Membuat objek dari class Car
    Car myCar;
    // Mengisi nilai atribut objek myCar
    strcpy(myCar.brand, "Toyota");
    strcpy(myCar.model, "Corolla");
    myCar.year = 2020;
    // Memanggil fungsi info dari objek myCar
    myCar.info();
    return 0;
}