C++学习中遇到的问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 17:31:54
我想在下面这段程序里添加一个函数,能够实现程序在调试运行过程中可以从键盘自由的输入学生信息.比如我可能会输入aaa 1 123也可能输入bbb 1 321等等.希望有高手能够帮助我。

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

class STUDENT
{
private:
struct STUD_INF
{
char name[20];
char id[6];
float score;
}stud;

public:
STUDENT(char *n="",char *i="0000",float sc=0)
{
strcpy(stud.name,n);
strcpy(stud.id,i);
stud.score=sc;
}

(是什么类型?) InputInfomation(char *n,char *i,float sc(参数对不对?))
{
cout<<"Input student information"<<endl;
cout<<"--姓名-学号-成绩--"<<endl;
cin>>n>>i>>sc;
return (是什么样的返回值?);
}

void PrintInformation()
{
cout<<"姓名:"<<stud.name<<endl;
cout<<"学号:"<<stud.id<&l

InputInfomation()
{
char n[20],i[20];
float sc;
cout<<"Input student information"<<endl;
cout<<"--姓名-学号-成绩--"<<endl;
cin>>n>>i>>sc;
strcpy(this->name,n);
strcpy(this->id,i);
this->score=sc;

return;
}
主程序里面调用instance.InputInfomation(); 就可以了。(函数里不要有参数)

strcpy();
strcpy();
是操纵c风格的标准库函数……
nstance.InputInfomation(n,i,sc); 这里面的n,i是指针吧,晕,这命名风格真是……
函数实现可参考上面的