Percakapan dengan Gemini
Write c++ sample code a struct of sudent id, name, classroom, with 3 students member, and view on screen
Here is a clean and straightforward C++ sample code using a struct to represent a student, initializing three student records, and displaying them on the screen.
C++
#include <iostream>
#include <string>
// Define the Student structure
struct Student {
int id;
std::string name;
std::string classroom;
};
int main() {
// Create and initialize an array of 3 students
Student students[3] = {
{101, "Alice Smith", "Room A-12"},
{102, "Bob Jones", "Room B-08"},
{103, "Charlie Brown", "Room A-12"}
};
// Print the student records to the screen
std::cout << "================ STUDENT RECORDS ================\n";
for (int i = 0; i < 3; ++i) {
std::cout << "Student #" << (i + 1) << "\n";
std::cout << "ID: " << students[i].id << "\n";
std::cout << "Name: " << students[i].name << "\n";
std::cout << "Classroom: " << students[i].classroom << "\n";
std::cout << "------------------------------------------------\n";
}
return 0;
}
Tidak ada komentar:
Posting Komentar