Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Write a program that uses following structured memory: struct info { char lastName[80]; char firstName[80]; char ID[20]; int score; }; to store the information of five students. You program should allow a user to enter the information of those students. Write a function in this program that has no return value, and receives a student ID number as its input. The function will search for the student that has the ID number that matches the input. If such student is found, then display all the information about this student, otherwise, display the message: The student is not foun

OpenStudy (espex):

So what is the question?

OpenStudy (anonymous):

the program recievies a student ID number as its input. then search for and if its found then it will display all the information, if not it displays student not found

OpenStudy (espex):

What was the question you had about the project?

OpenStudy (anonymous):

i was wondering how i would write the program, since i am new to programing

OpenStudy (espex):

The most simplistic way to do this that I can think of off the top of my head is to hard code the 5 structures. Use a for loop to prompt the user for data and then use a swtich/case to print the record they ask for.

OpenStudy (anonymous):

ok thank you

OpenStudy (espex):

You're welcome. :)

OpenStudy (anonymous):

i was wondering if this would work #include<iostream> using namespace std; struct info { char lastName; char firstName; char iD[20]; int score; }; void searchEngine(info a[], int length, char[]); void displayInfo(info a[], int length) { cout<<"last name:\n"<<endl; cout<<"first name:\n"<<endl; cout<<"iD:\n"<<endl; cout<<"score:\n"<<endl; for(int i=0; i<length; i++){ cout<<a[i].lastName; cout<<a[i].firstName; cout<<a[i].iD; cout<<a[i].score; cout<<endl; } } int main() { info a[5]; char search[20]; for(int i=0; i<5; i++){ cout<<"enter the last name:\n"<<endl; cin.getline(a[i].lastName,80); cout<<"enter the firs name:\n"<<endl; cin.getline(a[i].firstName, 80); cout<<"enter the id:\n"<<endl; cin.getline(a[i].iD, 20); cout<<"enter the score:\n"<<endl; cin>>a[i].score; } } void searchEngine(info a[], int length, char[]) { for(int i=0; i<5; i++) if(strcmp(a[i].iD, iD)==0) { cout<<"last name"<<a[i].lastName<<endl; cout<<"first name"<<a[i].firstName<<endl; cout<<"iD"<<a[i].iD<<endl; cout<<"score"<<a[i].score<<endl; return; } cout<<"the student is not found"<<endl; }

OpenStudy (rsmith6559):

You're definitely on your way. The most serious thing that I see is that in your definition of info, I believe that you should have char[] for the names. Since this is C++, why don't you use string? The layout in displayInfo is probably going to need some tweaking. I don't see any code calling displayInfo() or using searchEngine().

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!