1. how is c++ structure different from array?
2.how to define syntax,create,use and store data in struct variable?..
3. how to create an array of structure?..

i need some refenrences or brief answers..tnx...

Recommended Answers

All 2 Replies

char yes_no = '\0';
char again = '\0';
int counter = 0;

struct Employee
{
     string first_name;
     string last_name;
     int phone_number;
     bool is_salary;
     float pay_rate;
     char dept;
} emp_array[20];

do
{
     cout << "\nenter first name: ";
     cin >> emp_array[i].first_name;

     cout << "\nenter last name: ";
     cin >> emp_array[i].last_name;
 
     cout << "\nenter phone no. ";
     cin >> emp_array[i].phone_number;

     cout << "\nSalaried?  (Y/N) ";
     cin >> yes_no;

     if(toupper(yes_no) == 'Y')
     {
          emp_array[i].is_salary = true;
     }
     else
     {
          emp_array[i].is_salary = false;
     }

     cout << "\nenter pay rate: ";
     cin >> emp_array[i].pay_rate;

     cout << "\nenter dept.  (a)ccounting, (h)uman resources, (q)uality assurance: ";
     cin >> dept;

     cout << "\nWould ye' like to enter another employee? (Y/N) ";
     cin >> again;

     counter++;

}while(toupper(again) == 'Y' && counter < 20);

1. how is c++ structure different from array?

structures may contain dissimilar data items, whereas array cannot.

2.how to define syntax,create,use and store data in struct variable?..

struct mydata
{
   int item1;
   int item2;
   char item3;
};


mydata a;
a.item1=0;
//so on

3. how to create an array of structure?..

mydata b[20];
b[10].item1=0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.