I need help to complet this struct problem here is the declaration for the struc
ID: 3623108 • Letter: I
Question
I need help to complet this struct problemhere is the declaration for the struct
struct studentType
{
string name;
int credits;
float gpa;
string major;
char gender;
};
const int SIZE= 400;
studentType allStudents[SIZE];
1. I need to assign "Computer Science" as the major of all the students represented in array "allSudents"
2. write function definition of a value returning CountSophomore that counts the number of sophomore students in all the students. student considered sophomore if he has completed between 30-59 credits. the array allStudents and the number of students in the array are parameters of this function.
3. write complet definition of void function SwapStudents that exchanges the position of two students. the array "allSudents" and the index of the two students to be swapped are the parameters of this function
Explanation / Answer
Plz rate....
Note: This Program Runs Correctly on Borland Compiler and to Check the output of the program you should change the size of the array to 4 or 5 instead of 400 so that entry in the structure is easy, also Feel free to PM me if you have any problem in understanding.
#include <iostream.h>
#include <conio.h>
#include <cstring>
////////////////////////////////////////////////////////////////////////
struct studentType
{
string name;
int credits;
float gpa;
string major;
char gender;
};
void get_info(studentType allStd[],int size);
void display(studentType allStd[],int size);
int CountSophomore(studentType allStd[],int no_of_std);
void swap(studentType allStd[],int ind1,int ind2);
//////////////////////////////////////////////////////////////////////
void main()
{
const int size = 400;
studentType allStudents[size];
int index1,index2;
get_info(allStudents,size);
display(allStudents,size);
cout<<" Number of Sophmore Students :"<<CountSophomore(allStudents,size);
cout<<" Enter the First index to be swaped Between 0-"<<(size-1)<<" :";
cin>>index1;
cout<<" Enter the Second index to be swaped Between 0-"<<size<<"But not "<<index1<<" :";
cin>>index2;
swap(allStudents,index1,index2);
display(allStudents,size);
cout<<" Good Bye";
getche();
}
//////////////////////////////////////////////////////////////////////
void get_info(studentType allStd[],int size)
{
int i;
for(i=0;i<size;i++)
{
clrscr();
cout<<" Enter the Student Name : ";
getline(cin,allStd[i].name);
cin.ignore();
cout<<" Enter the Student Credits : ";
cin>>allStd[i].credits;
cout<<" Enter the Student GPA : ";
cin>>allStd[i].gpa;
allStd[i].major="Computer Science"; //initialize all student's major to "Computer science"
cout<<" Enter the Student Gender : ";
cin>>allStd[i].gender;
cin.ignore();
cout<<" -------------------------------------";
}
}
////////////////////////////////////////////////////////////////////
void display(studentType allStd[],int size)
{
clrscr();
for(int i=0;i<size;i++)
{
cout<<" Name : "<<allStd[i].name;
cout<<" Credits : "<<allStd[i].credits;
cout<<" GPA : "<<allStd[i].gpa;
cout<<" Major : "<<allStd[i].major;
cout<<" Gender : "<<allStd[i].gender;
cout<<" --------------------------------------";
}
cout<<" Note: All Students has in Major "Computer Science" ";
getche();
clrscr();
}
///////////////////////////////////////////////////////////////////////////
int CountSophomore(studentType allStd[],int no_of_std)
{
int count=0;
for(int i=0;i<no_of_std;i++)
if(allStd[i].credits>=30&&allStd[i].credits<=59)
count++;
return count;
}
//////////////////////////////////////////////////////////////////////////
void swap(studentType allStd[],int ind1,int ind2)
{
studentType temp=allStd[ind1];
allStd[ind1]=allStd[ind2];
allStd[ind2]=temp;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.