-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent data
More file actions
47 lines (40 loc) · 985 Bytes
/
student data
File metadata and controls
47 lines (40 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
int age;
string course;
public:
// Constructor to initialize data members
Student(string n, int a, string c) {
name = n;
age = a;
course = c;
}
// Function to display student details
void display() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Course: " << course << endl;
}
};
int main() {
string name, course;
int age;
// Input student details
cout << "Enter student name: ";
getline(cin, name);
cout << "Enter student age: ";
cin >> age;
cin.ignore(); // Ignore newline character in buffer
cout << "Enter student course: ";
getline(cin, course);
// Create student object
Student student1(name, age, course);
// Display student details
cout << "\nStudent Details:\n";
student1.display();
return 0;
}