Create an array of structures of student records. The records have the following
ID: 3621467 • Letter: C
Question
Create an array of structures of student records. The records have the following fields: Student name and student ID.
Fill the array of structures with the following data:
name Student ID
Titus Purdin 3289
Barack Obama 0705
Jerry Brown 8910
Mickey Mouse 6638
Jessica Rabbit 9991
Jubal Sackett 4321
then sort in ascending order using student ID as the key.
Output should consist of the columns formatted as follows:
student ID followed by three tabs, and then the student name.
for example
Sally Smith 1234
June Ward 4567
Lewis Carroll 5678
etc.
My coding so far:
(Note that some of this is probaby really way off so feel free to add whatever coding necessary)
//begin program
//create structure "studentRecords" with fields char type "studentName" and int type "studentID."
struct studentRecords
{
char studentName;
int studentID;
};
int main()
{
//use a multi-dimensional array with the structure fields as its elements.
char arrayOfStructures[];
//fill studentName with "Titus Purdin", "Barack Obama", "Jerry Brown", "Jessica Rabbit" and "Jubal Sackett".
string studentName[]={"Titus Purdin", "Barack Obama", "Jerry Brown", "Jessica Rabbit", "Jubal Sackett"}
//fill studentID with "3289", "0705", "8910", "6638", "9991", and "4321".
int studentID[]={3289, 0705, 8910, 6638, 9991, 4321};
//use if-statement to check values of the studentID array. Use min variable to sort the array from smallest to largest.
//print sorted multi-dimensional array to screen with names and IDs separated by three tabs.
for (size = 0; size < 6; size++)
cout << arrayOfStructures[StudentName] << " " << arrayOfStructures[StudentID]
system("pause");
return EXIT_SUCCESS;
}
//end program
Explanation / Answer
please rate - thanks
you say output ID then name, and show name then ID. I did what you said
//begin program
//create structure "studentRecords" with fields char type "studentName" and int type "studentID."
#include <iostream>
using namespace std;
struct studentRecords
{
char studentName[15];
int studentID;
};
int main()
{int size=6,i,j;
studentRecords student[]={ {"Titus Purdin", 3289},
{"Barack Obama", 0705},
{"Jerry Brown", 8910},
{"Mickey Mouse", 6638},
{"Jessica Rabbit", 9991},
{"Jubal Sackett", 4321}};
studentRecords temp;
//use a multi-dimensional array with the structure fields as its elements.
//char arrayOfStructures[];
//fill studentName with "Titus Purdin", "Barack Obama", "Jerry Brown", "Jessica Rabbit" and "Jubal Sackett".
//string studentName[]={"Titus Purdin", "Barack Obama", "Jerry Brown", "Jessica Rabbit", "Jubal Sackett"}
//fill studentID with "3289", "0705", "8910", "6638", "9991", and "4321".
//int studentID[]={3289, 0705, 8910, 6638, 9991, 4321};
//use if-statement to check values of the studentID array. Use min variable to sort the array from smallest to largest.
//print sorted multi-dimensional array to screen with names and IDs separated by three tabs.
for (i=0;i<size-1;i++)
for(j=i;j<size;j++)
if(student[i].studentID>student[j].studentID)
{temp=student[i];
student[i]=student[j];
student[j]=temp;
}
cout<<"ID Name ";
for(i=0;i<size;i++)
cout << student[i].studentID<< " " << student[i].studentName<<endl;
system("pause");
return EXIT_SUCCESS;
}
//end program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.