Hi
For the code below I'm getting these errors:
In function 'int main()':|
29|error: no match for 'operator=' in 'stud[3] = read()'|
14|note: candidates are: Student& Student:: operator=(const Student&)|
What's the reason for these errors? Please help me. Thank you.
Code:// read students' record and search for data of a particular student.cpp // use structure and display all data about the searched student #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int C = 3; int i; //////////////////////////////////////////////////////////////////////// struct Student {int rollno; char firstname[20]; char lastname[20]; string sex; float gpa;}; //////////////////////////////////////////////////////////////////////// Student stud[C]; void read(); void prnt(Student dummy[]); void find(char dummy[]); int main() { char choice; char searchname[30]; stud[C] = read(); cout << "do you want to print the data: "; cin >> choice; if (choice == 'y') { prnt(stud); } cout << "enter the name of the student to be searched for: "; cin.get(searchname, 30); find(searchname); system("pause"); return 0; } //---------------------------------------------------------------- // read() definition void read() { for (i=0; i<C; i++) { cout << "\n\nEnter student #" << (i+1) << "\'s details below\n\n"; cout << "enter roll no.: "; cin >> stud[i].rollno; cout << "enter first name: "; cin.get(stud[i].firstname, 20); cout << "enter last name: "; cin.get(stud[i].lastname, 20); cout << "enter sex: "; cin >> stud[i].sex; cout << "enter GPA: "; cin >> stud[i].gpa; } } //---------------------------------------------------------------- //prnt() definition void prnt(Student dummy[]) { for (i=0; i<C; i++) { cout << "\n\nstudent #" << (i+1) << "\'s details below\n\n"; cout << "\nroll no.: " << dummy[i].rollno; cout << "\nfirst name: " << dummy[i].firstname; cout << "\nlast name: " << dummy[i].lastname; cout << "\nsex: " << dummy[i].sex; cout << "\nGPA: " << dummy[i].gpa; } } //------------------------------------------------------------------ //find() definition void find(char dummy[]) { for (i=0; i<C; i++) { char temp_str[30] = {0}; strcat(temp_str, stud[i].firstname); strcat(temp_str, " "); strcat(temp_str, stud[i].lastname); if ( strcmp(temp_str, dummy ) == 0 ) { cout << "Data for the searched student is shown below\n"; cout << "roll no.: " << stud[i].rollno << endl; cout << "first name: " << stud[i].firstname << endl; cout << "last name: " << stud[i].lastname << endl; cout << "sex: " << stud[i].sex << endl; cout << "GPA: " << stud[i].gpa << endl; break; } else if ( i == (C-1) ) { cout << "Sorry, no student exists with such name" << endl; break; } } } //----------------------------------------------------------------------



2Likes
LinkBack URL
About LinkBacks




