Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ Step 1: Define a structure that includes a total of 3 members using these da

ID: 3761862 • Letter: C

Question

c++

Step 1: Define a structure that includes a total of 3 members using these data types: string, integer, double Step 2: Declare an array of structures with 3 elements and initialize the array with data of your choosing. Step 3: Declare a second array of structures with 2 elements. Step 4: Call a function and ask the user to input the data for the second array with 2 elements. (Be sure your instructions to the user are clear.) Step 4: Call a function to print both arrays being sure to label the output clearly. The arrays should be brought in as constants. Note: When passing arrays of structures, the function heading is the same as with any other array: datatype array name [ ]

Explanation / Answer

#include<iostream.h>
#include<conio.h>
struct emp
{
   char name[20];
   int empid;
   double sal;
};

void input(emp p[],int n)
{
   int i;
   for(i=0;i<2;i++)
   {
   cout<<"Enter name ";
   cin>>p[i].name;

   cout<<"Enter employee ID ";
   cin>>p[i].empid;

   cout<<"Enter employee Salary ";
   cin>>p[i].sal;
   }
}

void disp(emp p)
{
   cout<<p.name<<endl;
   cout<<p.empid<<endl;
   cout<<p.sal<<endl;
}
void main()
{
   struct emp e[3];
   int i;

   for(i=0;i<3;i++)
   {
       cout<<"Enter name ";
       cin>>e[i].name;

       cout<<"Enter employee ID ";
       cin>>e[i].empid;

       cout<<"Enter employee Salary ";
       cin>>e[i].sal;
   }

   struct emp ep[2];
   //for(i=0;i<2;i++)
   //{
       input(ep,2);
   //}

   for(i=0;i<3;i++)
   {
       disp(e[i]);
   }

   for(i=0;i<2;i++)
   {
       disp(ep[i]);
   }
   getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote