📌  相关文章
📜  C程序使用Structure打印员工详细信息

📅  最后修改于: 2021-06-01 00:56:14             🧑  作者: Mango

在此程序中,我们将使用Structure阅读并显示n名员工的详细信息。员工详细信息,如姓名,年龄,电话号码,薪水将被打印出来。

方法 :

Declare variables using Structure

Read details of all employees like employee name, 
age, phone number and salary.

Display all the details of employees

以下是显示员工详细信息的CPP程序:

// CPP program to print details of employees
// using Structure
#include 
using namespace std;
  
struct employee {
    string ename;
    int age, phn_no;
    int salary;
};
  
// Function to display details of all employees
void display(struct employee emp[], int n)
{
    cout << "Name\tAge\tPhone Number\tSalary\n";
    for (int i = 0; i < n; i++) {
        cout << emp[i].ename << "\t" << emp[i].age << "\t"
             << emp[i].phn_no << "\t" << emp[i].salary << "\n";
    }
}
  
// Driver code
int main()
{
    int n = 3;
    // Array of structure objects
    struct employee emp[n];
  
    // Details of employee 1
    emp[0].ename = "Chirag";
    emp[0].age = 24;
    emp[0].phn_no = 1234567788;
    emp[0].salary = 20000;
  
    // Details of employee 2
    emp[1].ename = "Arnav";
    emp[1].age = 31;
    emp[1].phn_no = 1234567891;
    emp[1].salary = 56000;
  
    // Details of employee 3
    emp[2].ename = "Shivam";
    emp[2].age = 45;
    emp[2].phn_no = 1100661111;
    emp[2].salary = 30500;
  
    display(emp, n);
  
    return 0;
}

输出 :

Name     Age    Phone Number   Salary
Chirag   24     1234567788      20000
Arnav    31     1234567891      56000
Shivam   45     8881101111      30500
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”