?
#include <iostream>
#include <strstream>
#include <string>
using namespace std;
const int N = 3;
typedef struct Student{
char name[20];
int num;
double score;
}Student;
void initialStu(Student **stu, int n){
*stu = new Student[n+1];
}
void freeStu(Student **stu){
delete[] (*stu);
}
void inputStu(Student *stu, int n){
cout<<"Enter "<<n<<" Student Info:"<<endl;
for(int i = 0; i < n; i++){
cout<<"Enter No."<<i + 1<<" Student Number(100 ~ 999): ";
cin>>stu[i].num;
while(stu[i].num < 100 || stu[i].num > 999){
cout<<"Number Error! Retry!\nEnter No."<<i + 1<<" Student Number(100 ~ 999): ";
cin>>stu[i].num;
}
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Enter No."<<i + 1<<" Student Name: ";
gets(stu[i].name);
cout<<"Enter No."<<i + 1<<" Student Score(0 ~100): ";
cin>>stu[i].score;
while(stu[i].score < 0 || stu[i].score > 100){
cout<<"Score Error! Retry!\nEnter No."<<i + 1<<" Student Score(0 ~ 100): ";
cin>>stu[i].score;
}
cout<<endl;
}
}
void inputStr(char *str, Student *stu, int n){
ostrstream strout(str, 200);
for(int i = 0; i < n; i++){
strout<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].score<<endl;
}
strout<<ends;
}
void outputStr(char *str, Student *stu, int n){
cout<<"Student Info:"<<endl;
cout<<str<<endl;
}
int main(){
Student *stu = NULL;
char str[200];
initialStu(&stu, N);
inputStu(stu, N);
inputStr(str, stu, N);
outputStr(str, stu, N);
freeStu(&stu);
system("pause");
return 0;
}