我的程序的一个功能必须是在一个包含1000个成员的数组中添加一个结构元素,在我的结构中保留'matrnr'作为整数,'name',指针作为char,'abslv'作为数组,包含30个元素,因为我必须使用char编写字符串,并且必须声明符号的大小,以及指针,因为所有字符串的总和必须小于或等于30.
我不允许使用任何库函数,只能使用来自iostream和stdio.h的printf,getchar,scanf,cin和cout
关于struct的问题:名称也必须用char实现,我是否必须编写数组?
const int maxstudenten = 1000;
const int MAX = 30;
struct student_t {
int matrnr;
char* name[MAX];
char** abslv[MAX];
};
我在此功能的以下空格中也有问题(在评论中):
int land (student_t *feld[maxstudenten], int i) { //I is my counter for
//the current size
student_t *pstudentanlegen= new student_t; //Write a new student
printf("Matrikelnummer:...."); //Enrolment number
std::cin>>pstudentanlegen->matrnr; //Stack->enrolment number
if (pstudentanlegen->matrnr>1 && pstudentanlegen->matrnr<999999) {
//the enrolment number must be >1 and <999999
if (binaeresuche(&feld[maxstudenten],i,(pstudentanlegen->matrnr))!=0) { //It examins if a student with this name already exists
std::cout<<"Student mit diesem Matrikelnummer ist schon vorhanden"<<std::endl; //Student with this enr.nr exists
return i;
}else {
printf("\nName:.....");
pstudentanlegen->name=getchar(); //Pointer->name
//Here I cant write anything although I have written getchar
std::cout<<std::endl;
int zaehler=0;
std::cout<<"Möchten Sie Lehrveranstantungen hinfügen? j=ja,n=nein"<<std::endl;
//Do you want to add lectures?
char a;
std::cin>>a;
if(a=='j' && zaehler<MAX) { //zaehler=my second counter
//for the lectures
std::cout<<"Lehrveranstaltung:"; //Lecture:
pstudentanlegen->abslv[MAX]=getchar();
//insupportable types of allocation of int to char* [30]
zaehler++;
}
i++;
} //Anhängen (sortiert nach Matrikelnummer)
//add(sorted towards number)
int position=0;
while(position<maxstudenten && pstudentanlegen->matrnr>feld[position]->matrnr) { //Invalid conversion of int in char**
position++;
}
}return i;
}