Create Simple Student Class
C++
Easy
2 views
Problem Description
Design a Student class with basic data members (name,age,rollno) and member functions to display details.
Logic: Use class to group related data and functions together
Official Solution
class Student {
public:
string name;
int age;
int rollNo;
void displayInfo() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Roll No: " << rollNo << endl;
}
};
void question1_student_class() {
Student s1;
s1.name = "Raj Kumar";
s1.age = 20;
s1.rollNo = 101;
s1.displayInfo();
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!