TLDRai.com Too Long; Didn't Read AI TLDWai.com Too Long; Didn't Watch AI
Tạo bản tóm tắt không giới hạn với AI!
Nâng cấp lên Pro US$ 7.0/m
Không có chức năng hạn chế

#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.
Người dùng PRO nhận được bản tóm tắt chất lượng cao hơn
Nâng cấp lên Pro US$ 7.0/m
Không có chức năng hạn chế
Tóm tắt văn bản Tóm tắt văn bản từ tập tin Tóm tắt văn bản từ trang web

Nhận đầu ra chất lượng tốt hơn với nhiều tính năng hơn

Trở thành CHUYÊN NGHIỆP