Attributes of the Class
syntax
class Name { public: Type AttributeName; };
Public attributes and methods in a class can be directly accessed using the dot operator (.
) on an object of the class.
main
class Student { public: int age; }; int main() { Student bob; Student ann; bob.age = 25; ann.age = 33; }
Tarefa
Swipe to start coding
You are working with a Student
class and need to enhance its structure and usage.
- Add two additional attributes to the
Student
class:name
(string) andgpa
(float). - Create an object of the
Student
class. - Assign appropriate values to the attributes
name
,gpa
, andemail
of the created instance.
Solução
solution
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 4