请帮我看看要怎么改
请帮我看看要怎么改must write the subprogram to share individual elements of the array -- NOT the whole array. In your loops in main, call the subprogram once for each element of the array.
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
const int size = 3;
struct student
{
string name;
string address;
string city;
string state;
int zip;
char gender;
int idno;
float gpa;
}; //student
void getInfo(int i, student* s)
{
// function to get students' information
cout << "student " << i+1 << "'s Name? ";
getline(cin, s[i].name);
cout << "student " << i+1 << "'s address? ";
getline(cin, s[i].address);
cout << "student " << i+1 << "'s city? ";
getline(cin, s[i].city);
cout << "student " << i+1 << "'s state? ";
getline(cin, s[i].state);
cout << "student " << i+1 << "'s zip code? ";
cin >> s[i].zip;
cin.ignore(1000, 10);
cout << "student " << i+1 << "'s gender? [M/F]";
cin >> s[i].gender;
cin.ignore(1000, 10);
cout << "student " << i+1 << "'s ID number? ";
cin >> s[i].idno;
cin.ignore(1000, 10);
cout << "student " << i+1 << "'s gpa? ";
cin >> s[i].gpa;
cin.ignore(1000, 10);
cout << endl;
}
// function to print students' information
void printInfo(int i, student* s)
{
cout << "=======student (" << i+1 << ")=======" << endl;
cout << "Name: " << s[i].name << endl;
cout << "Address: " << s[i].address << endl;
cout << "City: " << s[i].city << endl;
cout << "State: " << s[i].state << endl;
cout << "Zip code: " << s[i].zip << endl;
cout << "Gender: " << s[i].gender << endl;
cout << "ID number: " << s[i].idno << endl;
cout << "GPA: " << s[i].gpa << endl;
cout << endl;
}
int main()
{
PrintStatements();
student s[2];
int i;
for (i = 0; i < size; i++)
{
getInfo(i, s);
} //getInfo
cout << endl;
for (i = 0; i < size; i++)
{
printInfo(i, s);
} //printInfo
// End!
cout << endl;
cout << endl;
cout << "Press ENTER to continue..." << endl;
cin.get();
return 0;
}