#include <iostream> using namespace std ; typedef struct Student { char strname[50]; //姓名 int math; //数学分数 int chinese; //语文 int total; //总分 }STUDENT; void InitData(STUDENT* some) { ////////////////////////////////////// //初始化数据 some->strname[0] = ''''''''; some->math = 0; some->chinese = 0; some->total = 0; } void InputData(STUDENT* some) { /////////////////////////////////////// //获取输入 cout<<"enter name"<<endl; cin>>some->strname; cout<<"enter math"<<endl; cin>>some->math; cout<<"enter chinese"<<endl; cin>>some->chinese; ////////////////////////////////////// //计算总分 some->total = some->math + some->chinese; } void PrintData(STUDENT some) { cout<<some.strname<<"''''s total mark is:"<<some.total<<endl; } //上面的部分可以单独放在一个头和CPP中 main() { STUDENT someone; InitData(&someone); InputData(&someone); PrintData(someone); } |