'temp'未声明,请先使用此函数
'temp' is undeclared, first use this function
#include<iostream>
#include<conio.h>
#include<string>
#include<cstring>
#include<stdlib.h>
using namespace std;
bool rgstr_stdnt(struct student *stud,struct list *ls);
double calculate_aggregate(struct student *);
void srch_student(struct student * next);
void addToList(struct student *stud, struct list *l);
void display(struct student *stud, struct list *l);
struct student
{
char name[20];
int matric_marks, inter_marks, aptitude_marks;
int temp;
student *next;
};
struct list
{
char name[20];
double aggr;
list *next;
};
这就是问题出现的地方,它说临时未声明,首先使用此功能,我无法纠正它
void srch_stdnt(struct student *stud)
{
char name[60];
cout << "Enter Student to search :";
cin>>name;
cout << name;
//down here, the error comes and whatever i knew, i have tried to solve it but could not
while (temp!=NULL){
if(strcmp(temp->name, name)==0){
}
temp = temp->next;
}
cout << "No match found";
}
int main()
{
student * temp=new student();
student *s;
s = (struct student *) malloc(sizeof(struct student));
struct list *ls;
ls = (struct list *) malloc(sizeof(struct list));
strcpy(ls->name,"");
ls->aggr = 0;
ls->next= NULL;
do
{
cout<<" STUDENT ENROLLMENT AND RECORDS MANAGEMENT"<<endl;
cout<<"1- To Enroll A New Sudent."<<endl;
cout<<"2- To View The Enrolled Students."<<endl;
cout<<"3- To Search Through The Already Enrolled Students."<<endl;
cout<<"4- Exit."<<endl;
int input;
cin>>input;
if (input == 1)
{
rgstr_stdnt(s, ls);
}
else if (input == 2)
{
display(s, ls);
}
else if(input == 3)
{
void srch_student(struct student * stud);
}
else if (input == 4)
exit(0);
cout<<endl;
} while(1);
getch();
}
bool rgstr_stdnt(struct student *stud,struct list *ls)
{
student *s = stud;
cout<<"Enter Name Of The Student: "<<endl;
cin>>s->name;
cout<<"Enter Percentage in 10th Grade: "<<endl;
cin>>s->matric_marks;
cout<<"Enter Intermediate Percentage:"<<endl;
cin>>s->inter_marks;
cout<<"Enter Percentage In Aptitude Test: "<<endl;
cin>>s->aptitude_marks;
double aggregate;
aggregate = calculate_aggregate(s);
cout<<"Aggregate Percentage Is: "<< aggregate<<"%"<<endl;
if (aggregate >= 70)
{
cout<<"-> Student Enrolled In BSCS. <-"<<endl;
addToList(s,ls);
return true;
}
else if (aggregate >= 60)
{
cout<<"-> Student Enrolled In BE. <-"<<endl;
addToList(s,ls);
return true;
}
else if (aggregate >=50)
{
cout<<"-> Student Enrolled In MS. <-"<<endl;
addToList(s,ls);
return true;
}
else
{
cout<<"Sorry, Low Percentage. Student Can't Be Enrolled!"<<endl;
return false;
}
}
double calculate_aggregate(struct student *stud)
{
student *s = stud;
double aggr;
aggr = s->matric_marks * 10/100 + s->inter_marks * 50/100 +
s->aptitude_marks * 40/100;
return aggr;
}
void addToList(struct student *stud, struct list *l)
{
list *pointer = l;
while (pointer->next != NULL)
{
pointer = pointer->next;
}
pointer->next = (struct list *) malloc(sizeof(struct list));
pointer = pointer->next;
strcpy(pointer->name , stud->name);
pointer->aggr = calculate_aggregate(stud);
pointer->next = NULL;
}
void display(struct student *stud, struct list *l)
{
list *pointer = l;
if (pointer->next == NULL)
cout<<"No Students Enrolled Yet."<<endl;
else
{
cout<<" !- - - - - - - - -. STUDENTS RECORDS .- - - - - - - - - -! "
<<endl;
while (pointer->next != NULL)
{
pointer = pointer->next;
cout<<"Name Of Student: "<<pointer->name<<endl;
cout<<"Aggregate Is: "<<pointer->aggr<<endl;
if (pointer->aggr >= 70)
cout<<"-> Student Enrolled In BSCS. <-"<<endl;
else if(pointer->aggr >=60)
cout<<"-> Student Enrolled In BE. <-"<<endl;
else
cout<<"-> Student Enrolled In MS. <-"<<endl;
cout<<endl;
}
}
}
任何能帮助我解决这个问题的人,我真的很感激。
如错误消息所述,您正在使用尚未声明的名为temp
的变量。 您需要声明它并为其提供一个初始值:
struct student *temp = stud;
while (temp!=NULL){
...
//down here, the error comes and whatever i knew, i have tried to solve it but could not while (temp!=NULL){
您尚未在函数中声明temp
。这解释了编译器错误。
也许你打算使用:
struct student* temp = stud;
while ( temp != NULL )
由于您在C++土地上,请丢弃struct
并使用:
student* temp = stud;
while ( temp != NULL )
也可以在代码的其余部分进行更改更改。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 'temp'未声明,请先使用此函数
- 将 rvalue/temp 对象传递给需要非成本引用的函数的任何方法
- 运算符<<使用temp变量工作,但不直接使用函数调用