TLDRai.com Too Long; Didn't Read AI TLDWai.com Too Long; Didn't Watch AI
AI ဖြင့် အကန့်အသတ်မရှိ အကျဉ်းချုပ်များ ပြုလုပ်ပါ။
PRO သို့ အဆင့်မြှင့်ပါ။ US$ 7.0/m
ကန့်သတ်လုပ်ဆောင်ချက်များမရှိပါ။

#include <iostream>#include <string>class Person {public: std::string name; int age; Person(std::string n, int a) : name(n), age(a) {} void printInfo() { std::cout << "Name: " << name << ", Age: " << age << std::endl; }};int main() { Person person1("John", 30); person1.printInfo(); return 0;}```This code defines a simple `Person` class with private data members (`name` and `age`) and public member functions (`printInfo()`). The constructor initializes the object's state, and the `printInfo()` function prints out the object's name and age.In the `main()` function, an instance of the `Person` class is created with the name "John" and age 30. Then, the `printInfo()` member function is called to print out John's information.Output:```Name: John, Age: 30```### Code Explanation* The `class Person` declaration defines a new class named `Person`.* Inside the class, we have two private data members: * `std::string name;`: This is a string variable that will store the person's name. * `int age;`: This is an integer variable that will store the person's age.* The constructor `Person(std::string n, int a) : name(n), age(a) {}` initializes the object's state. It takes two parameters: `n` (the person's name) and `a` (the person's age). These parameters are used to initialize the `name` and `age` data members.* The `printInfo()` function is a public member function that prints out the person's information. It uses the `std::cout` object to print the name and age, followed by a newline character (`\n`) using the `std::endl` manipulator.* In the `main()` function: * We create an instance of the `Person` class with the name "John" and age 30: `Person person1("John", 30);` * We call the `printInfo()` member function on the `person1` object to print out John's information: `person1.printInfo();`This code demonstrates basic concepts in C++, including classes, constructors, and member functions. It also shows how to create an instance of a class and use its member functions to perform specific tasks.
PRO အသုံးပြုသူများသည် အရည်အသွေးမြင့် အနှစ်ချုပ်များကို ရရှိသည်။
PRO သို့ အဆင့်မြှင့်ပါ။ US$ 7.0/m
ကန့်သတ်လုပ်ဆောင်ချက်များမရှိပါ။
စာသားအကျဉ်းချုပ် ဖိုင်မှ စာသားကို အကျဉ်းချုပ်ပါ။ ဝဘ်ဆိုဒ်မှ စာသားကို အကျဉ်းချုပ်ပါ။

ပိုမိုကောင်းမွန်သော လုပ်ဆောင်ချက်များဖြင့် အရည်အသွေးကောင်းမွန်သော ရလဒ်များကို ရယူလိုက်ပါ။

PRO ဖြစ်လာပါ။