-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_030.cpp
More file actions
29 lines (29 loc) · 905 Bytes
/
problem_030.cpp
File metadata and controls
29 lines (29 loc) · 905 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
//Write a program in c++ to display student's information using friend function
#include <iostream>
#include <string>
using namespace std;
class Student;
class StudentInfo {
public:
static void displayStudentInfo(const Student& student); // Friend function declaration
};
class Student {
private:
string name;
int rollNumber;
float marks;
public:
Student(const string& n, int roll, float m) : name(n), rollNumber(roll), marks(m) {}
friend void StudentInfo::displayStudentInfo(const Student& student);
};
void StudentInfo::displayStudentInfo(const Student& student) {
cout << "Student Information:" <<endl;
cout << "Name: " << student.name <<endl;
cout << "Roll Number: " << student.rollNumber <<endl;
cout << "Marks: " << student.marks <<endl;
}
int main() {
Student student("John", 12345, 95.5);
StudentInfo::displayStudentInfo(student);
return 0;
}