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; }
Завдання
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.
Рішення
solution
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 4