Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Attributes of the Class | Fundamentals of OOP in C++
C++ OOP

Swipe to show menu

book
Attributes of the Class

syntax.h

syntax.h

copy
1234
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.cpp

main.cpp

copy
12345678910111213
class Student { public: int age; }; int main() { Student bob; Student ann; bob.age = 25; ann.age = 33; }
Task

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) and gpa (float).
  • Create an object of the Student class.
  • Assign appropriate values to the attributes name, gpa, and email of the created instance.

Solution

solution.cpp

solution.cpp

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 3.13

book
Attributes of the Class

syntax.h

syntax.h

copy
1234
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.cpp

main.cpp

copy
12345678910111213
class Student { public: int age; }; int main() { Student bob; Student ann; bob.age = 25; ann.age = 33; }
Task

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) and gpa (float).
  • Create an object of the Student class.
  • Assign appropriate values to the attributes name, gpa, and email of the created instance.

Solution

solution.cpp

solution.cpp

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

close

Awesome!

Completion rate improved to 3.13

Swipe to show menu

some-alt