In: Computer Science
Create a C++ program that creates instances of a Struct using an Array (you can choose the number of instances to create). You can also use either user input or an initialization list to initialize 3 peoples names. Make sure that the values stored in each member are printed to the screen.
C++ code for above problem:
#include <iostream>
using namespace std;
struct Person {
    string name;
    int salary;
    int personId;
};
int main() {
    Person e[3]; //instance of structure using
array.
    for(int i=0;i<3;i++)
    {
    cout << "Enter name of employee : ";
    cin>>e[i].name;
    cout << "Enter salary of employee :
";
    cin >> e[i].salary;
    cout << "Enter employee code : ";
    cin >> e[i].personId;
    cout<<endl<<endl;
    }
    // Printing person details
    cout << "\n*** Person Detail ***" <<
endl;
    for(int i=0;i<3;i++){
    cout << "Name : " << e[i].name
<< endl << "Salary : " << e[i].salary <<
endl;
    cout << "PersonId : " <<
e[i].personId<<endl<<endl;
    }
    return 0;
}
Output:
