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

Step 1: #include <iostream> #include <string> using namespace std; struct studen

ID: 3558932 • Letter: S

Question

Step 1:

#include <iostream>
#include <string>
using namespace std;

struct student_record
{
   string name;
   double age;
   char sex;
};
int main()
{
   student_record Student_DB[3] = {"Lofton",53,'M',"Thomas",55,'M',
                       "Tami",25,'F'};

   cout << endl;
   for (int i=0; i<3; i++)
   {
       cout << Student_DB[i].name << " "
       << Student_DB[i].age <<" "
       << Student_DB[i].sex << endl << endl;
   }

   Student_DB[0].name = "William";
   Student_DB[2].age = 100;
   Student_DB[1].sex = 'F';

   cout << "+++++++++++++++++++++++++++++++ ";

   cout << endl;

   for (int i=0; i<3; i++)
   {
       cout << Student_DB[i].name << " "
       << Student_DB[i].age << " "
       << Student_DB[i].sex << endl << endl;
   }
   return 0;
   }

Question 1:   Please explain how the array

Explanation / Answer

A. Here in Both program samples you have created your own structure datatype. and the structure data type you have 3 data members name age and sex. so the size of each sturcture datatype is sum of size of its members.

assume of string is of maximum length 10 so total size of your one structure data type is 10(name) +2 (age) + 1(sex)

now just like array of primitive you can aasume array of structure but in primitive you can directly access the element by index but here in structure you have data mebmers so which data member you want to access you need to specify using dot operator like structureArray[0].name or more generally strucctureArray[i].name

B. Here first loop is to display the structure data and then you modified the structure so to see the changes you are using the loop again.

C.In the first program you are performing the initilaisation at the time of declaration but in second you are fisrt declaringg and then initialising the strusture array.

D.Static array the size is decided at the time of array declaration but in dynamic array the size of array is decided at run time.

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