Question:
Write a C++ program that stores and siplays following employee data of
a company in structures:
- Employee ID (int)
- Employee Name (string)
- Email (string)
- Designation (char)
- Salary (float)
- Projects (array of strings)
Your code must contain following:
- Pointer to structure
- Array of Structure
- Structure variable
Source Code:
#include<iostream>
#include<string>
using namespace std;
struct EmployeeData
{
int Eid;
string Ename;
string Eemail;
string Desig;
float salary{};
string projects[10];
};
int main()
{
cout<<endl;
struct EmployeeData *E,d;
E=&d;
int i=0;
int counter=0;
char a;
do
{
cout<<"
DETAIL OF EMPLOYEE #"<<i+1<<"
"<<endl;
cout<<"Employee ID: ";
cin>>(*E).Eid;
cout<<"Employee Name: ";
cin>>(*E).Ename;
cout<<"Employee Email: ";
cin>>(*E).Eemail;
cout<<"Designation: ";
cin>>(*E).Desig;
cout<<"Salary: ";
cin>>(*E).salary;
cout<<"Projects: ";
cin>>(*E).projects[i];
cout<<"To print detail of all employees press p: ";
cin>>a;
i++;
counter++;
}
while(a!='p');
cout<<"Employee ID"<<"Name"<<"Email"<<"Designation"<<"Salary"<<"Projects"<<endl;
{
cout<<(*E).Eid[i]<<(*E).Ename[i]<<(*E).Eemail[i]<<(*E).Desig[i]<<(*E).salary[i]<<(*E).projects[i]<<endl;
}
return 0;
}
Errors:
10 15 C:UsershpDesktopUntitled1.cpp [Warning] non-static data
member initializers only available with -std=c++11 or -std=gnu++11
10 14 C:UsershpDesktopUntitled1.cpp [Warning] extended initializer
lists only available with -std=c++11 or -std=gnu++11
10 15 C:UsershpDesktopUntitled1.cpp [Warning] extended initializer
lists only available with -std=c++11 or -std=gnu++11
C:UsershpDesktopUntitled1.cpp In function 'int main()':
48 21 C:UsershpDesktopUntitled1.cpp [Error] invalid types
'int[int]' for array subscript
48 83 C:UsershpDesktopUntitled1.cpp [Error] invalid types
'float[int]' for array subscript
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…