【发布时间】:2020-12-20 05:47:36
【问题描述】:
#include <iostream.h>
#include <conio.h>
class Employee{
int Id;
string Name;
string Post;
public:
long int Salary;
void GetDetails();
void DisplayDetails();
friend void MaxSalary();
};
void Employee::GetDetails(){
cout << "\nEnter Employee Id : ";
cin >> Id;
cout << "\nEnter Employee Name : ";
cin.ignore();
getline(cin,Name);
cout << "\nEnter Employee Post : ";
cin.ignore();
getline(cin,Post);
cout << "\nEnter Employee Salary : ";
cin >> Salary;
}
void Employee::DisplayDetails(){
cout << "\nEmployee Id : " << Id;
cout << "\nEmployee Name : " << Name;
cout << "\nEmployee Post : " << Post;
cout << "\nEmployee Salary : " << Salary;
}
void MaxSalary(Employee a[], int x){
long int max;
for(int j=0; j<x; j++){
if(a[j].Salary>a[j+1].Salary)
max=a[j].Salary;
}
cout<<"Maximum Salary = "<<max<<endl;
}
int main()
{
int n, i;
cout<<"Enter Number of Employees : ";
cin>>n;
Employee E[n];
cout<<"\n\n----------ENTER DETAILS OF EMPLOYEES----------\n\n";
for(i=0;i<n;i++){
cout<<"\n\n Enter details of Employee "<<i+1<<endl;
E[i].GetDetails();
}
cout<<"\n\n----------DETAILS OF EMPLOYEES----------\n\n";
for(i=0;i<n;i++){
cout<<"\n\n Details of Employee "<<i+1<<endl;
E[i].DisplayDetails();
}
MaxSalary(E[n], n );
return 0;
}
【问题讨论】:
-
请使用tour,阅读How to Ask 并使用stackoverflow.com/editing-help 转至edit 您的帖子。事实上,它会阻止用户回答。
-
@KyleWang,我感谢您的努力,但在这种情况下,它教给我们一个错误的教训,即只有这篇文章的格式是一个问题。
-
请提供minimal reproducible example并相应地编辑帖子
-
这个问题没有关注你遇到的具体编程问题。 “做。这是我的代码。”不是问题。
-
@generic_opto_guy 提出这个问题和代码的事实都表明代码没有做它应该做的事情。因此,它与代码审查无关。
标签: c++ class oop friend-function