Saturday, May 22, 2010

How can i make an array of 30 student using structure in C++?

all data of 30 student for example name,age,marks,marital status etc.Give complete programme.

How can i make an array of 30 student using structure in C++?
Don't ask for the full program for a homework assignment.
Reply:#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;stdio.h%26gt;


class student


{


char name[20],martial_status[8];


int age,marks;


public:


void getdata();


void display();


};


void student::getdata()


{


cout%26lt;%26lt;"Enter Your Name ";


gets(name);


cout%26lt;%26lt;"Enter Your Age ";


cin%26gt;%26gt;age;


cout%26lt;%26lt;"Enter Yout Martial Status ";


gets(martial_status);


cout%26lt;%26lt;"Enter Your Marks ";


cin%26gt;%26gt;marks;


}


void student::display()


{


cout%26lt;%26lt;"\n Student Name = "%26lt;%26lt;name;


cout%26lt;%26lt;"\n Student Age ="%26lt;%26lt;age;


cout%26lt;%26lt;"\nMartial Status ="%26lt;%26lt;martial_status;


cout%26lt;%26lt;"\nMarks ="%26lt;%26lt;marks;


}





void main()


{


clrscr();


student s[3];


int i;


for(i=0;i%26lt;3;i++)


{


s[i].getdata();


}


for(i=0;i%26lt;3;i++)


{


s[i].display();


}


getch();


}
Reply:Same way you'd make an array of other data types.





struct student {


string name;


int age;


float marks;


int maritalstatus


};





student StudentArray[30];
Reply:Here:


struct Students


{


int Age;


char Name[255];//Adjust to fit...


int Marks;//I think? Not sure what this would be


int MStatus;//Married? Not Married? Single? Use integers


};


Students sArray[29];


//0-29 = 30 as in 0 to 29. if this doesn't work use Students sArray[30];


//Hmm use a for loop? or whatever


sArray[0].Age=30; // And so forth...


No comments:

Post a Comment